diff --git a/Anytype/Sources/PresentationLayer/Modules/Chat/ChatViewModel.swift b/Anytype/Sources/PresentationLayer/Modules/Chat/ChatViewModel.swift index ee487d857b..dfab94caf7 100644 --- a/Anytype/Sources/PresentationLayer/Modules/Chat/ChatViewModel.swift +++ b/Anytype/Sources/PresentationLayer/Modules/Chat/ChatViewModel.swift @@ -7,6 +7,7 @@ import Collections import UIKit import NotificationsCore import ProtobufMessages +import AsyncAlgorithms @preconcurrency import Combine @MainActor @@ -627,8 +628,14 @@ final class ChatViewModel: MessageModuleOutput, ChatActionProviderHandler { } private func subscribeOnPermissions() async { - for await canEditMessages in accountParticipantsStorage.canEditSequence(spaceId: spaceId) { - canEdit = canEditMessages + let permissionsSequence = accountParticipantsStorage.canEditSequence(spaceId: spaceId) + let deletedOrArchivedSequence = chatObject.detailsPublisher + .map { !$0.isDeleted && !$0.isArchived } + .removeDuplicates() + .values + + for await (canEditMessages, canEditChat) in combineLatest(permissionsSequence, deletedOrArchivedSequence) { + canEdit = canEditMessages && canEditChat } } diff --git a/Anytype/Sources/PresentationLayer/Modules/Chat/Services/ChatMessageBuilder.swift b/Anytype/Sources/PresentationLayer/Modules/Chat/Services/ChatMessageBuilder.swift index 27e6aa3391..4e6c1d8681 100644 --- a/Anytype/Sources/PresentationLayer/Modules/Chat/Services/ChatMessageBuilder.swift +++ b/Anytype/Sources/PresentationLayer/Modules/Chat/Services/ChatMessageBuilder.swift @@ -11,20 +11,21 @@ protocol ChatMessageBuilderProtocol: AnyObject, Sendable { } actor ChatMessageBuilder: ChatMessageBuilderProtocol, Sendable { - + private enum Constants { static let grouppingDateInterval: Int = 60 // seconds } - + private let accountParticipantsStorage: any ParticipantsStorageProtocol = Container.shared.participantsStorage() private let messageTextBuilder: any MessageTextBuilderProtocol = Container.shared.messageTextBuilder() private let workspaceStorage: any SpaceViewsStorageProtocol = Container.shared.spaceViewsStorage() - + private let openDocumentProvider: any OpenedDocumentsProviderProtocol = Container.shared.openedDocumentProvider() + private let spaceId: String private let chatId: String - + private let dateFormatter = HistoryDateFormatter() - + init(spaceId: String, chatId: String) { self.spaceId = spaceId self.chatId = chatId @@ -36,10 +37,12 @@ actor ChatMessageBuilder: ChatMessageBuilderProtocol, Sendable { firstUnreadMessageOrderId: String?, limits: any ChatMessageLimitsProtocol ) async -> [MessageSectionData] { - + let isStream = workspaceStorage.spaceView(spaceId: spaceId)?.uxType.isStream ?? false let participant = accountParticipantsStorage.participants.first { $0.spaceId == spaceId } - let canEdit = participant?.canEdit ?? false + let chatObject = openDocumentProvider.document(objectId: chatId, spaceId: spaceId) + let isChatDeletedOrArchived = (chatObject.details?.isDeleted ?? false) || (chatObject.details?.isArchived ?? false) + let canEdit = (participant?.canEdit ?? false) && !isChatDeletedOrArchived let yourProfileIdentity = participant?.identity var currentSectionData: MessageSectionData?