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
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import Collections
import UIKit
import NotificationsCore
import ProtobufMessages
import AsyncAlgorithms
@preconcurrency import Combine

@MainActor
Expand Down Expand Up @@ -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
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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?
Expand Down