Skip to content

iOS-4608 Support link without approve #3308

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 7 commits into
base: develop
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,7 @@ struct InviteLinkView: View {
.newDivider()
}
Spacer.fixedHeight(10)
AnytypeText(model.isStream ? Loc.SpaceShare.Invite.Stream.description : Loc.SpaceShare.Invite.description, style: .relation3Regular)
AnytypeText(model.description, style: .relation3Regular)
.foregroundColor(.Text.secondary)
Spacer.fixedHeight(20)
StandardButton(model.isStream ? Loc.SpaceShare.Share.link : Loc.SpaceShare.Invite.share, style: .primaryLarge) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ final class InviteLinkViewModel: ObservableObject {
@Published var canCopyInviteLink = false
@Published var deleteLinkSpaceId: StringIdentifiable? = nil
@Published var toastBarData: ToastBarData?
@Published var description = ""

@Injected(\.participantSpacesStorage)
private var participantSpacesStorage: any ParticipantSpacesStorageProtocol
Expand Down Expand Up @@ -49,7 +50,14 @@ final class InviteLinkViewModel: ObservableObject {
AnytypeAnalytics.instance().logScreenSettingsSpaceShare(route: data.route)
do {
let invite = isStream ? try await workspaceService.getGuestInvite(spaceId: spaceId) : try await workspaceService.getCurrentInvite(spaceId: spaceId)

if isStream {
description = Loc.SpaceShare.Invite.Stream.description
} else {
description = Loc.SpaceShare.Invite.Description.part1
if let withoutApprove = invite.inviteType?.withoutApprove, !withoutApprove {
description += ". " + Loc.SpaceShare.Invite.Description.part2
}
}
shareLink = universalLinkParser.createUrl(link: .invite(cid: invite.cid, key: invite.fileKey))
} catch {}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ struct SpaceJoinView: View {
ScreenStateView(state: model.state, error: model.errorMessage) {
content
} loading: {
invite(placeholder: true)
invite(placeholder: true, withoutApprove: model.dataState.inviteWithoutApprove)
}
}
.multilineTextAlignment(.center)
Expand All @@ -40,8 +40,8 @@ struct SpaceJoinView: View {
switch model.dataState {
case .requestSent:
requestSent
case .invite:
invite(placeholder: false)
case let .invite(withoutApprove):
invite(placeholder: false, withoutApprove: withoutApprove)
case .alreadyJoined:
alreadyJoined
case .inviteNotFound:
Expand All @@ -62,11 +62,11 @@ struct SpaceJoinView: View {
}
}

private func invite(placeholder: Bool) -> some View {
private func invite(placeholder: Bool, withoutApprove: Bool) -> some View {
VStack(spacing: 0) {
Image(asset: .Dialog.invite)
Spacer.fixedHeight(15)
AnytypeText(Loc.SpaceShare.Join.title, style: .heading)
AnytypeText(model.title, style: .heading)
.foregroundColor(.Text.primary)
Spacer.fixedHeight(8)
AnytypeText(model.message, style: .bodyRegular, enableMarkdown: true)
Expand All @@ -75,15 +75,23 @@ struct SpaceJoinView: View {
$0.redacted(reason: .placeholder)
}
Spacer.fixedHeight(19)
AsyncStandardButton(Loc.SpaceShare.Join.button, style: .primaryLarge) {
AsyncStandardButton(model.button, style: .primaryLarge) {
try await model.onJoin()
}
.if(placeholder) {
$0.redacted(reason: .placeholder)
}
Spacer.fixedHeight(17)
AnytypeText(Loc.SpaceShare.Join.info, style: .caption1Regular)
.foregroundColor(.Text.secondary)
if withoutApprove {
Spacer.fixedHeight(8)
StandardButton(Loc.cancel, style: .secondaryLarge, action: {
model.onCancel()
})
} else {
Spacer.fixedHeight(17)
AnytypeText(Loc.SpaceShare.Join.info, style: .caption1Regular)
.foregroundColor(.Text.secondary)
}

}
.padding(.horizontal, 16)
.padding(.top, 24)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,10 +10,19 @@ struct SpaceJoinModuleData: Identifiable {

enum SpaceJoinDataState {
case requestSent
case invite
case invite(withoutApprove: Bool)
case alreadyJoined
case inviteNotFound
case spaceDeleted

var inviteWithoutApprove: Bool {
switch self {
case let .invite(withoutApprove):
return withoutApprove
default:
return false
}
}
}

@MainActor
Expand All @@ -34,9 +43,11 @@ final class SpaceJoinViewModel: ObservableObject {
private var callManageSpaces = false

@Published var errorMessage: String = ""
@Published var title: String = Loc.SpaceShare.Join.title
@Published var message: String = Loc.SpaceShare.Join.message("", "") // For Placeholder
@Published var button: String = Loc.SpaceShare.Join.button
@Published var state: ScreenState = .loading
@Published var dataState: SpaceJoinDataState = .invite
@Published var dataState: SpaceJoinDataState = .invite(withoutApprove: false)
@Published var toast: ToastBarData?
@Published var showSuccessAlert = false
@Published var dismiss = false
Expand All @@ -57,7 +68,15 @@ final class SpaceJoinViewModel: ObservableObject {
key: data.key,
networkId: accountManager.account.info.networkId
)
showSuccessAlert.toggle()
if inviteView.inviteType.withoutApprove {
dismiss.toggle()
} else {
showSuccessAlert.toggle()
}
}

func onCancel() {
dismiss.toggle()
}

func onDismissSuccessAlert() {
Expand Down Expand Up @@ -104,24 +123,24 @@ final class SpaceJoinViewModel: ObservableObject {
private func updateView() async {
do {
let inviteView = try await workspaceService.inviteView(cid: data.cid, key: data.key)
message = Loc.SpaceShare.Join.message(
inviteView.spaceName.withPlaceholder.trimmingCharacters(in: .whitespaces),
inviteView.creatorName.withPlaceholder.trimmingCharacters(in: .whitespaces)
)

handleInviteType(inviteView: inviteView)

self.inviteView = inviteView
state = .data

let inviteWithoutApprove = inviteView.inviteType.withoutApprove
if let spaceView = workspaceStorage.allWorkspaces.first(where: { $0.targetSpaceId == inviteView.spaceId }) {
switch spaceView.accountStatus {
case .spaceJoining:
dataState = .requestSent
case .spaceActive, .unknown:
dataState = .alreadyJoined
default:
dataState = .invite
dataState = .invite(withoutApprove: inviteWithoutApprove)
}
} else {
dataState = .invite
dataState = .invite(withoutApprove: inviteWithoutApprove)
}
} catch let error as SpaceInviteViewError where error.code == .inviteNotFound {
dataState = .inviteNotFound
Expand All @@ -134,4 +153,23 @@ final class SpaceJoinViewModel: ObservableObject {
state = .error
}
}

private func handleInviteType(inviteView: SpaceInviteView) {
if inviteView.inviteType.withoutApprove {
let spaceName = inviteView.spaceName.withPlaceholder.trimmingCharacters(in: .whitespaces)
title = Loc.SpaceShare.Join.NoApprove.title(spaceName)
message = Loc.SpaceShare.Join.NoApprove.message(
spaceName,
inviteView.creatorName.withPlaceholder.trimmingCharacters(in: .whitespaces)
)
button = Loc.SpaceShare.Join.NoApprove.button
} else {
title = Loc.SpaceShare.Join.title
message = Loc.SpaceShare.Join.message(
inviteView.spaceName.withPlaceholder.trimmingCharacters(in: .whitespaces),
inviteView.creatorName.withPlaceholder.trimmingCharacters(in: .whitespaces)
)
button = Loc.SpaceShare.Join.button
}
}
}
2 changes: 1 addition & 1 deletion Libraryfile
Original file line number Diff line number Diff line change
@@ -1 +1 @@
MIDDLE_VERSION=v0.41.0-rc4
MIDDLE_VERSION=f259480e6
14 changes: 13 additions & 1 deletion Modules/Loc/Sources/Loc/Generated/Strings.swift
Original file line number Diff line number Diff line change
Expand Up @@ -1915,14 +1915,17 @@ public enum Loc {
public static let title = Loc.tr("Localizable", "SpaceShare.HowToShare.Title", fallback: "How to share a space?")
}
public enum Invite {
public static let description = Loc.tr("Localizable", "SpaceShare.Invite.Description", fallback: "Share this invite link so that others can join your Space. Once they click your link and request access, you can set their access rights.")
public static let empty = Loc.tr("Localizable", "SpaceShare.Invite.Empty", fallback: "Create invite link to share space and add new members")
public static let generate = Loc.tr("Localizable", "SpaceShare.Invite.Generate", fallback: "Generate invite link")
public static func maxLimit(_ p1: Int) -> String {
return Loc.tr("Localizable", "SpaceShare.Invite.MaxLimit", p1, fallback: "Plural format key: SpaceShare.Invite.MaxLimit")
}
public static let share = Loc.tr("Localizable", "SpaceShare.Invite.Share", fallback: "Share invite link")
public static let title = Loc.tr("Localizable", "SpaceShare.Invite.Title", fallback: "Invite link")
public enum Description {
public static let part1 = Loc.tr("Localizable", "SpaceShare.Invite.Description.part1", fallback: "Share this invite link so that others can join your space")
public static let part2 = Loc.tr("Localizable", "SpaceShare.Invite.Description.part2", fallback: "Once they click your link and request access, you can set their access rights.")
}
public enum Stream {
public static let description = Loc.tr("Localizable", "SpaceShare.Invite.Stream.Description", fallback: "Share this link so that others can join your Stream.")
}
Expand All @@ -1942,6 +1945,15 @@ public enum Loc {
public enum NoAccess {
public static let title = Loc.tr("Localizable", "SpaceShare.Join.NoAccess.Title", fallback: "No access to this space")
}
public enum NoApprove {
public static let button = Loc.tr("Localizable", "SpaceShare.Join.NoApprove.button", fallback: "Join Space")
public static func message(_ p1: Any, _ p2: Any) -> String {
return Loc.tr("Localizable", "SpaceShare.Join.NoApprove.Message", String(describing: p1), String(describing: p2), fallback: "You've been invited to join %@, created by %@")
}
public static func title(_ p1: Any) -> String {
return Loc.tr("Localizable", "SpaceShare.Join.NoApprove.Title", String(describing: p1), fallback: "Join %@")
}
}
public enum ObjectIsNotAvailable {
public static let message = Loc.tr("Localizable", "SpaceShare.Join.ObjectIsNotAvailable.Message", fallback: "Ask the owner to share it with you.")
}
Expand Down
48 changes: 46 additions & 2 deletions Modules/Loc/Sources/Loc/Resources/Localizable.xcstrings
Original file line number Diff line number Diff line change
Expand Up @@ -149313,7 +149313,7 @@
}
}
},
"SpaceShare.Invite.Description" : {
"SpaceShare.Invite.Description.part1" : {
"extractionState" : "manual",
"localizations" : {
"ar" : {
Expand All @@ -149337,7 +149337,7 @@
"en" : {
"stringUnit" : {
"state" : "translated",
"value" : "Share this invite link so that others can join your Space. Once they click your link and request access, you can set their access rights."
"value" : "Share this invite link so that others can join your space"
}
},
"es" : {
Expand Down Expand Up @@ -149462,6 +149462,17 @@
}
}
},
"SpaceShare.Invite.Description.part2" : {
"extractionState" : "manual",
"localizations" : {
"en" : {
"stringUnit" : {
"state" : "translated",
"value" : "Once they click your link and request access, you can set their access rights."
}
}
}
},
"SpaceShare.Invite.Empty" : {
"extractionState" : "manual",
"localizations" : {
Expand Down Expand Up @@ -151586,6 +151597,39 @@
}
}
},
"SpaceShare.Join.NoApprove.button" : {
"extractionState" : "manual",
"localizations" : {
"en" : {
"stringUnit" : {
"state" : "translated",
"value" : "Join Space"
}
}
}
},
"SpaceShare.Join.NoApprove.Message" : {
"extractionState" : "manual",
"localizations" : {
"en" : {
"stringUnit" : {
"state" : "translated",
"value" : "You've been invited to join %@, created by %@"
}
}
}
},
"SpaceShare.Join.NoApprove.Title" : {
"extractionState" : "manual",
"localizations" : {
"en" : {
"stringUnit" : {
"state" : "translated",
"value" : "Join %@"
}
}
}
},
"SpaceShare.Join.ObjectIsNotAvailable.Message" : {
"extractionState" : "manual",
"localizations" : {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1335,6 +1335,11 @@ extension Anytype_Rpc.Space.Delete.Response.Error: ResponseError {
public var isNull: Bool { code == .null && description_p.isEmpty }
}

extension Anytype_Rpc.Space.InviteChange.Response: ResultWithError {}
extension Anytype_Rpc.Space.InviteChange.Response.Error: ResponseError {
public var isNull: Bool { code == .null && description_p.isEmpty }
}

extension Anytype_Rpc.Space.InviteGenerate.Response: ResultWithError {}
extension Anytype_Rpc.Space.InviteGenerate.Response.Error: ResponseError {
public var isNull: Bool { code == .null && description_p.isEmpty }
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -364,6 +364,16 @@ public struct ClientCommands {
}
}

public static func spaceInviteChange(
_ request: Anytype_Rpc.Space.InviteChange.Request = .init()
) -> Invocation<Anytype_Rpc.Space.InviteChange.Request, Anytype_Rpc.Space.InviteChange.Response> {
return Invocation(messageName: "SpaceInviteChange", request: request) { request in
let requestData = try request.serializedData()
let responseData = Lib.ServiceSpaceInviteChange(requestData) ?? Data()
return try Anytype_Rpc.Space.InviteChange.Response(serializedBytes: responseData)
}
}

public static func spaceInviteGetCurrent(
_ request: Anytype_Rpc.Space.InviteGetCurrent.Request = .init()
) -> Invocation<Anytype_Rpc.Space.InviteGetCurrent.Request, Anytype_Rpc.Space.InviteGetCurrent.Response> {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6548,6 +6548,37 @@ extension Anytype_Rpc.Space.Delete.Response.Error: LocalizedError {
}
}

extension Anytype_Rpc.Space.InviteChange.Response.Error: LocalizedError {
public var errorDescription: String? {
let localizeError = localizeError()
if !localizeError.isEmpty {
return localizeError
}
return "Error: \(description_p) (\(code))"
}

private func localizeError() -> String {
switch code {
case .null:
return ""
case .unknownError:
return ""
case .badInput:
return LocHelper.tr(table: "LocalizableError", key: "Space.InviteChange.badInput")
case .noSuchSpace:
return LocHelper.tr(table: "LocalizableError", key: "Space.InviteChange.noSuchSpace")
case .spaceIsDeleted:
return LocHelper.tr(table: "LocalizableError", key: "Space.InviteChange.spaceIsDeleted")
case .requestFailed:
return LocHelper.tr(table: "LocalizableError", key: "Space.InviteChange.requestFailed")
case .incorrectPermissions:
return LocHelper.tr(table: "LocalizableError", key: "Space.InviteChange.incorrectPermissions")
case .UNRECOGNIZED:
return ""
}
}
}

extension Anytype_Rpc.Space.InviteGenerate.Response.Error: LocalizedError {
public var errorDescription: String? {
let localizeError = localizeError()
Expand Down
Loading
Loading