Skip to content

Commit 090120d

Browse files
committedMar 13, 2025·
Address PR comments
1 parent 1078c6e commit 090120d

File tree

5 files changed

+21
-8
lines changed

5 files changed

+21
-8
lines changed
 

‎ElementX/Sources/Screens/RoomDetailsScreen/RoomDetailsScreenModels.swift

+2-2
Original file line numberDiff line numberDiff line change
@@ -38,8 +38,8 @@ struct DMRecipientInfo {
3838
struct RoomDetailsScreenViewState: BindableState {
3939
var details: RoomDetails
4040

41-
let isEncrypted: Bool
42-
let isDirect: Bool
41+
var isEncrypted: Bool
42+
var isDirect: Bool
4343
var permalink: URL?
4444

4545
var topic: AttributedString?

‎ElementX/Sources/Screens/RoomDetailsScreen/RoomDetailsScreenViewModel.swift

+7-2
Original file line numberDiff line numberDiff line change
@@ -208,13 +208,18 @@ class RoomDetailsScreenViewModel: RoomDetailsScreenViewModelType, RoomDetailsScr
208208
}
209209

210210
private func updateRoomInfo(_ roomInfo: RoomInfoProxy) {
211+
state.isEncrypted = roomInfo.isEncrypted
212+
state.isDirect = roomInfo.isDirect
213+
state.bindings.isFavourite = roomInfo.isFavourite
214+
215+
state.joinedMembersCount = roomInfo.joinedMembersCount
216+
211217
state.details = roomProxy.details
212218

213219
let topic = attributedStringBuilder.fromPlain(roomInfo.topic)
214220
state.topic = topic
215221
state.topicSummary = topic?.unattributedStringByReplacingNewlinesWithSpaces()
216-
state.joinedMembersCount = roomInfo.joinedMembersCount
217-
state.bindings.isFavourite = roomInfo.isFavourite
222+
218223
switch roomInfo.joinRule {
219224
case .knock, .knockRestricted:
220225
state.isKnockableRoom = true

‎ElementX/Sources/Screens/RoomScreen/ComposerToolbar/ComposerToolbarModels.swift

+1-1
Original file line numberDiff line numberDiff line change
@@ -73,7 +73,7 @@ struct ComposerToolbarViewState: BindableState {
7373
var audioPlayerState: AudioPlayerState
7474
var audioRecorderState: AudioRecorderState
7575

76-
let isRoomEncrypted: Bool
76+
var isRoomEncrypted: Bool
7777

7878
var bindings: ComposerToolbarViewStateBindings
7979

‎ElementX/Sources/Screens/RoomScreen/ComposerToolbar/ComposerToolbarViewModel.swift

+7-3
Original file line numberDiff line numberDiff line change
@@ -62,13 +62,17 @@ final class ComposerToolbarViewModel: ComposerToolbarViewModelType, ComposerTool
6262
mentionBuilder = MentionBuilder()
6363
attributedStringBuilder = AttributedStringBuilder(cacheKey: "Composer", mentionBuilder: mentionBuilder)
6464

65-
super.init(initialViewState: ComposerToolbarViewState(audioPlayerState: .init(id: .recorderPreview,
66-
title: L10n.commonVoiceMessage,
67-
duration: 0),
65+
super.init(initialViewState: ComposerToolbarViewState(audioPlayerState: .init(id: .recorderPreview, title: L10n.commonVoiceMessage, duration: 0),
6866
audioRecorderState: .init(),
6967
isRoomEncrypted: roomProxy.infoPublisher.value.isEncrypted,
7068
bindings: .init()),
7169
mediaProvider: mediaProvider)
70+
71+
roomProxy.infoPublisher
72+
.map(\.isEncrypted)
73+
.receive(on: DispatchQueue.main)
74+
.weakAssign(to: \.state.isRoomEncrypted, on: self)
75+
.store(in: &cancellables)
7276

7377
context.$viewState
7478
.map(\.composerMode)

‎ElementX/Sources/Services/Room/RoomInfoProxy.swift

+4
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,11 @@ struct RoomInfoProxy: BaseRoomInfoProxyProtocol {
4242
return .room(id: id, name: displayName, avatarURL: avatarURL)
4343
}
4444

45+
// Here we're assuming unknown rooms are unencrypted.
46+
// Fortunately https://github.com/matrix-org/matrix-rust-sdk/pull/4778 makes that very much of an edge case and we
47+
// also automatically start a `latestEncryptionState` fetch if needed.
4548
var isEncrypted: Bool { roomInfo.encryptionState == .encrypted }
49+
4650
var isDirect: Bool { roomInfo.isDirect }
4751
var isPublic: Bool { roomInfo.isPublic }
4852
var isSpace: Bool { roomInfo.isSpace }

0 commit comments

Comments
 (0)