Display an icon in the room header for rooms with shared history (#5016)

* feat: Display an icon in the room header for rooms with shared history

* fix: Apply suggestions from code review

- Simplifies `isRoomHistoryShared` expressions using type inferrence.
- Adds failure messages to unit test.

Co-authored-by: Doug <6060466+pixlwave@users.noreply.github.com>

* fix: Remove extension method in favour of field on configuration.

* fix: Distinguish between `shared` and `worldReadable` icons.

* refactor: Use `RoomHistorySharingState` enum with extension methods

---------

Co-authored-by: Doug <6060466+pixlwave@users.noreply.github.com>
This commit is contained in:
Skye Elliot
2026-01-30 13:11:10 +00:00
committed by GitHub
parent 26cb30c614
commit 955ec0c8a9
15 changed files with 180 additions and 11 deletions
@@ -7,6 +7,7 @@
//
import Foundation
import MatrixRustSDK
import OrderedCollections
enum RoomScreenViewModelAction: Equatable {
@@ -80,6 +81,9 @@ struct RoomScreenViewState: BindableState {
(canAcceptKnocks || canDeclineKnocks || canBan)
}
/// If `enableKeyShareOnInvite` is set, determines the current history sharing state.
var roomHistorySharingState: RoomHistorySharingState?
var footerDetails: RoomScreenFooterViewDetails?
var bindings = RoomScreenViewStateBindings()
@@ -67,10 +67,17 @@ class RoomScreenViewModel: RoomScreenViewModelType, RoomScreenViewModelProtocol
self.initialSelectedPinnedEventID = initialSelectedPinnedEventID
pinnedEventStringBuilder = .pinnedEventStringBuilder(userID: roomProxy.ownUserID)
let roomHistorySharingState: RoomHistorySharingState? = if appSettings.enableKeyShareOnInvite {
roomProxy.infoPublisher.value.historySharingState
} else {
nil
}
let viewState = RoomScreenViewState(roomTitle: roomProxy.infoPublisher.value.displayName ?? roomProxy.id,
roomAvatar: roomProxy.infoPublisher.value.avatar,
hasOngoingCall: roomProxy.infoPublisher.value.hasRoomCall,
hasSuccessor: roomProxy.infoPublisher.value.successor != nil)
hasSuccessor: roomProxy.infoPublisher.value.successor != nil,
roomHistorySharingState: roomHistorySharingState)
super.init(initialViewState: appHooks.roomScreenHook.update(viewState),
mediaProvider: userSession.mediaProvider)
@@ -342,6 +349,14 @@ class RoomScreenViewModel: RoomScreenViewModelType, RoomScreenViewModelProtocol
state.canDeclineKnocks = powerLevels.canOwnUserKick()
state.canBan = powerLevels.canOwnUserBan()
}
// This causes the UI to become inconsistent with the user's mental model if the user
// does not restart the app after disabling the feature flag. We can probably ignore
// such cases, since we explicitly ask for an app restart in the caption of the feature
// flag switch.
if appSettings.enableKeyShareOnInvite {
state.roomHistorySharingState = roomInfo.historySharingState
}
}
private func setupPinnedEventsTimelineItemProviderIfNeeded() {
@@ -157,6 +157,7 @@ struct RoomScreen: View {
RoomHeaderView(roomName: context.viewState.roomTitle,
roomAvatar: context.viewState.roomAvatar,
dmRecipientVerificationState: context.viewState.dmRecipientVerificationState,
roomHistorySharingState: context.viewState.roomHistorySharingState,
mediaProvider: context.mediaProvider) {
context.send(viewAction: .displayRoomDetails)
}