Be more lenient with the power levels as they can still be missing at the time the various screens are created e.g. after accepting an invite.

The correct solution is to subscribe to update and update the UI accordingly when receiving them.
This commit is contained in:
Stefan Ceriu
2025-06-26 16:34:34 +03:00
committed by Stefan Ceriu
parent 37cbf733d4
commit 9c28a69ccf
10 changed files with 108 additions and 103 deletions
@@ -19,10 +19,13 @@ private enum SuggestionTriggerRegex {
final class CompletionSuggestionService: CompletionSuggestionServiceProtocol {
private let roomProxy: JoinedRoomProxyProtocol
private var canMentionAllUsers = false
private(set) var suggestionsPublisher: AnyPublisher<[SuggestionItem], Never> = Empty().eraseToAnyPublisher()
private let suggestionTriggerSubject = CurrentValueSubject<SuggestionTrigger?, Never>(nil)
private var cancellables = Set<AnyCancellable>()
init(roomProxy: JoinedRoomProxyProtocol,
roomListPublisher: AnyPublisher<[RoomSummary], Never>) {
self.roomProxy = roomProxy
@@ -47,8 +50,14 @@ final class CompletionSuggestionService: CompletionSuggestionServiceProtocol {
self?.suggestionTriggerSubject.value != nil ? .milliseconds(500) : .milliseconds(0)
}
guard let powerLevels = roomProxy.infoPublisher.value.powerLevels else { fatalError("Missing room power levels") }
canMentionAllUsers = powerLevels.canOwnUserTriggerRoomNotification()
roomProxy.infoPublisher
.receive(on: DispatchQueue.main)
.sink { [weak self] roomInfo in
self?.updateRoomInfo(roomInfo)
}
.store(in: &cancellables)
updateRoomInfo(roomProxy.infoPublisher.value)
}
func processTextMessage(_ textMessage: String, selectedRange: NSRange) {
@@ -61,6 +70,12 @@ final class CompletionSuggestionService: CompletionSuggestionServiceProtocol {
// MARK: - Private
private func updateRoomInfo(_ roomInfo: RoomInfoProxyProtocol) {
if let powerLevels = roomProxy.infoPublisher.value.powerLevels {
canMentionAllUsers = powerLevels.canOwnUserTriggerRoomNotification()
}
}
private func membersSuggestions(suggestionTrigger: SuggestionTrigger,
members: [RoomMemberProxyProtocol],
ownUserID: String) -> [SuggestionItem] {