Skip to content
Merged
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
1 change: 1 addition & 0 deletions Anytype/Sources/Analytics/AnalyticsConstants.swift
Original file line number Diff line number Diff line change
Expand Up @@ -307,6 +307,7 @@ enum ScreenQrRoute: String {
case inviteLink = "InviteLink"
case settingsSpace = "SettingsSpace"
case spaceProfile = "SpaceProfile"
case chat = "Chat"
}

enum ClickShareSpaceCopyLinkRoute: String {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,9 @@ struct ChatCoordinatorView: View {
.sheet(item: $model.spaceShareData) { data in
SpaceShareCoordinatorView(data: data)
}
.anytypeSheet(item: $model.qrCodeInviteLink) {
QrCodeView(title: Loc.joinSpace, data: $0.absoluteString, analyticsType: .inviteSpace, route: .chat)
}
.onChange(of: model.photosItems) {
model.photosPickerFinished()
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ final class ChatCoordinatorViewModel: ObservableObject, ChatModuleOutput {
@Published var newLinkedObject: EditorScreenData?
@Published var inviteLinkData: SpaceShareData?
@Published var spaceShareData: SpaceShareData?
@Published var qrCodeInviteLink: URL?

private var filesPickerData: FilesPickerData?
private var photosPickerData: ChatPhotosPickerData?
Expand Down Expand Up @@ -106,6 +107,10 @@ final class ChatCoordinatorViewModel: ObservableObject, ChatModuleOutput {
inviteLinkData = data
}
}

func onShowQrCodeSelected(url: URL) {
qrCodeInviteLink = url
}

func onPushNotificationsAlertSelected() {
pushNotificationsAlertData = PushNotificationsAlertData(completion: { [weak self] granted in
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ protocol ChatModuleOutput: AnyObject {
func onUrlSelected(url: URL)
func onWidgetsSelected()
func onInviteLinkSelected()
func onShowQrCodeSelected(url: URL)
func onPushNotificationsAlertSelected()
func didSelectCreateObject(type: ObjectType)
}
10 changes: 8 additions & 2 deletions Anytype/Sources/PresentationLayer/Modules/Chat/ChatView.swift
Original file line number Diff line number Diff line change
Expand Up @@ -153,10 +153,16 @@ struct ChatView: View {
ConversationEmptyStateView(
conversationType: model.conversationType,
participantPermissions: model.participantPermissions,
action: {
addMembersAction: {
model.onTapInviteLink()
}
},
qrCodeAction: model.qrCodeInviteUrl != nil ? {
model.onTapShowQrCode()
} : nil
)
.task {
await model.updateInviteState()
}
}

private var actionView: some View {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import AnytypeCore
import Collections
import UIKit
import NotificationsCore
import ProtobufMessages
@preconcurrency import Combine

@MainActor
Expand Down Expand Up @@ -49,6 +50,10 @@ final class ChatViewModel: ObservableObject, MessageModuleOutput, ChatActionProv
private var pushNotificationsAlertHandler: any PushNotificationsAlertHandlerProtocol
@Injected(\.notificationsCenterService)
private var notificationsCenterService: any NotificationsCenterServiceProtocol
@Injected(\.workspaceService)
private var workspaceService: any WorkspaceServiceProtocol
@Injected(\.universalLinkParser)
private var universalLinkParser: any UniversalLinkParserProtocol

private let participantSubscription: any ParticipantsSubscriptionProtocol
private let chatStorage: any ChatMessagesStorageProtocol
Expand All @@ -62,6 +67,7 @@ final class ChatViewModel: ObservableObject, MessageModuleOutput, ChatActionProv

@Published var dataLoaded = false
@Published var canEdit = false
@Published var qrCodeInviteUrl: URL?
var keyboardDismiss: KeyboardDismiss?

// Input Message
Expand Down Expand Up @@ -213,14 +219,19 @@ final class ChatViewModel: ObservableObject, MessageModuleOutput, ChatActionProv
func onTapInviteLink() {
output?.onInviteLinkSelected()
}

func onTapShowQrCode() {
guard let url = qrCodeInviteUrl else { return }
output?.onShowQrCodeSelected(url: url)
}

func startSubscriptions() async {
async let permissionsSub: () = subscribeOnPermissions()
async let participantsSub: () = subscribeOnParticipants()
async let typesSub: () = subscribeOnTypes()
async let messageBackgroundSub: () = subscribeOnMessageBackground()
async let spaceViewSub: () = subscribeOnSpaceView()

(_, _, _, _, _) = await (permissionsSub, participantsSub, typesSub, messageBackgroundSub, spaceViewSub)
}

Expand Down Expand Up @@ -639,6 +650,15 @@ final class ChatViewModel: ObservableObject, MessageModuleOutput, ChatActionProv
await handlePushNotificationsAlert()
}
}

func updateInviteState() async {
do {
let invite = try await workspaceService.getCurrentInvite(spaceId: spaceId)
qrCodeInviteUrl = universalLinkParser.createUrl(link: .invite(cid: invite.cid, key: invite.fileKey))
} catch {
qrCodeInviteUrl = nil
}
}

private func updateMessages() async {
let newMessageBlocks = await chatMessageBuilder.makeMessage(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,11 @@ import SwiftUI
import Services

struct ConversationEmptyStateView: View {

let conversationType: ConversationType
let participantPermissions: ParticipantPermissions?
let action: (() -> Void)?
let addMembersAction: (() -> Void)?
let qrCodeAction: (() -> Void)?

var body: some View {
switch conversationType {
Expand All @@ -22,20 +23,20 @@ struct ConversationEmptyStateView: View {
case .owner:
emptyStateView(
title: Loc.Chat.Empty.title,
description: Loc.Chat.Empty.Owner.description,
action: action
addMembersAction: addMembersAction,
qrCodeAction: qrCodeAction
)
case .writer:
emptyStateView(
title: Loc.Chat.Empty.title,
description: Loc.Chat.Empty.Editor.description,
action: nil
addMembersAction: nil,
qrCodeAction: nil
)
case .reader, .noPermissions, .UNRECOGNIZED, nil:
emptyStateView(
title: Loc.Chat.Empty.title,
description: "",
action: nil
addMembersAction: nil,
qrCodeAction: nil
)
}
}
Expand All @@ -45,38 +46,62 @@ struct ConversationEmptyStateView: View {
case .owner:
emptyStateView(
title: Loc.Stream.Empty.title,
description: Loc.Stream.Empty.description,
action: action
addMembersAction: addMembersAction,
qrCodeAction: qrCodeAction
)
case .writer, .reader, .noPermissions, .UNRECOGNIZED, nil:
emptyStateView(
title: Loc.Stream.Empty.title,
description: "",
action: nil
addMembersAction: nil,
qrCodeAction: nil
)
}
}

private func emptyStateView(title: String, description: String, action: (() -> Void)?) -> some View {
private func emptyStateView(title: String, addMembersAction: (() -> Void)?, qrCodeAction: (() -> Void)?) -> some View {
VStack(alignment: .center, spacing: 0) {
Spacer()
Image(asset: .Dialog.coffee)
Spacer.fixedHeight(10)
Text(title)
.anytypeStyle(.bodyRegular)
.anytypeStyle(.bodySemibold)
.foregroundStyle(Color.Text.primary)
Text(description)
.anytypeStyle(.bodyRegular)
.foregroundStyle(Color.Control.transparentSecondary)
if let action {
Spacer.fixedHeight(10)
StandardButton(
Loc.Chat.Empty.Button.title,
style: .transparentXSmall,
action: action
)
Spacer.fixedHeight(20)
featureRow(icon: "infinity", text: Loc.Chat.Empty.Feature.yoursForever)
Spacer.fixedHeight(12)
featureRow(icon: "wifi.slash", text: Loc.Chat.Empty.Feature.availableOffline)
Spacer.fixedHeight(12)
featureRow(icon: "key.fill", text: Loc.Chat.Empty.Feature.privateEncrypted)
Spacer.fixedHeight(25)
HStack(alignment: .center, spacing: 8) {
Spacer()
if let addMembersAction {
StandardButton(
Loc.Chat.Empty.Button.addMembers,
style: .primaryXSmall,
action: addMembersAction
)
}
if let qrCodeAction {
StandardButton(
Loc.SpaceShare.Qr.button,
style: .primaryXSmall,
action: qrCodeAction
)
}
Spacer()
}
Spacer()
}
}

private func featureRow(icon: String, text: String) -> some View {
HStack(spacing: 12) {
Image(systemName: icon)
.frame(width: 24, height: 24)
.foregroundStyle(Color.Control.transparentSecondary)
Text(text)
.anytypeStyle(.relation3Regular)
Spacer()
}
.padding(.horizontal, 45)
}
}
11 changes: 5 additions & 6 deletions Modules/Loc/Sources/Loc/Generated/Strings.swift
Original file line number Diff line number Diff line change
Expand Up @@ -1423,13 +1423,12 @@ public enum Loc {
public enum Empty {
public static let title = Loc.tr("Workspace", "Chat.Empty.Title", fallback: "You just created a chat")
public enum Button {
public static let title = Loc.tr("Workspace", "Chat.Empty.Button.title", fallback: "Invite members")
public static let addMembers = Loc.tr("Workspace", "Chat.Empty.Button.AddMembers", fallback: "Add members")
}
public enum Editor {
public static let description = Loc.tr("Workspace", "Chat.Empty.Editor.Description", fallback: "Write the first message to spark it up!")
}
public enum Owner {
public static let description = Loc.tr("Workspace", "Chat.Empty.Owner.Description", fallback: "Invite people and start the conversation!")
public enum Feature {
public static let availableOffline = Loc.tr("Workspace", "Chat.Empty.Feature.AvailableOffline", fallback: "Messages, docs & files available offline")
public static let privateEncrypted = Loc.tr("Workspace", "Chat.Empty.Feature.PrivateEncrypted", fallback: "Fully private and encrypted")
public static let yoursForever = Loc.tr("Workspace", "Chat.Empty.Feature.YoursForever", fallback: "Yours forever")
}
}
public enum FileSyncError {
Expand Down
Loading
Loading