mirror of
https://github.com/Novaloop-AG/element-x-ios.git
synced 2026-11-05 11:58:32 +00:00
Display the notification mode for each room in the the room list (#1595)
Co-authored-by: Stefan Ceriu <stefan.ceriu@gmail.com>
This commit is contained in:
@@ -36,6 +36,8 @@ class ClientProxy: ClientProxyProtocol {
|
||||
|
||||
var roomSummaryProvider: RoomSummaryProviderProtocol?
|
||||
var inviteSummaryProvider: RoomSummaryProviderProtocol?
|
||||
|
||||
var notificationSettings: NotificationSettingsProxyProtocol
|
||||
|
||||
private let roomListRecencyOrderingAllowedEventTypes = ["m.room.message", "m.room.encrypted", "m.sticker"]
|
||||
|
||||
@@ -66,6 +68,9 @@ class ClientProxy: ClientProxyProtocol {
|
||||
clientQueue = .init(label: "ClientProxyQueue", attributes: .concurrent)
|
||||
|
||||
mediaLoader = MediaLoader(client: client, clientQueue: clientQueue)
|
||||
|
||||
notificationSettings = NotificationSettingsProxy(notificationSettings: client.getNotificationSettings(),
|
||||
backgroundTaskService: backgroundTaskService)
|
||||
|
||||
client.setDelegate(delegate: ClientDelegateWrapper { [weak self] isSoftLogout in
|
||||
self?.callbacks.send(.receivedAuthError(isSoftLogout: isSoftLogout))
|
||||
@@ -348,13 +353,6 @@ class ClientProxy: ClientProxyProtocol {
|
||||
}
|
||||
}
|
||||
|
||||
func notificationSettings() async -> NotificationSettingsProxyProtocol {
|
||||
await Task.dispatch(on: clientQueue) {
|
||||
NotificationSettingsProxy(notificationSettings: self.client.getNotificationSettings(),
|
||||
backgroundTaskService: self.backgroundTaskService)
|
||||
}
|
||||
}
|
||||
|
||||
// MARK: Private
|
||||
|
||||
private func restartSync(delay: Duration = .zero) {
|
||||
@@ -405,12 +403,14 @@ class ClientProxy: ClientProxyProtocol {
|
||||
eventStringBuilder: eventStringBuilder,
|
||||
name: "AllRooms",
|
||||
appSettings: appSettings,
|
||||
notificationSettings: notificationSettings,
|
||||
backgroundTaskService: backgroundTaskService)
|
||||
try await roomSummaryProvider?.setRoomList(roomListService.allRooms())
|
||||
inviteSummaryProvider = RoomSummaryProvider(roomListService: roomListService,
|
||||
eventStringBuilder: eventStringBuilder,
|
||||
name: "Invites",
|
||||
appSettings: appSettings,
|
||||
notificationSettings: notificationSettings,
|
||||
backgroundTaskService: backgroundTaskService)
|
||||
|
||||
self.syncService = syncService
|
||||
|
||||
@@ -83,6 +83,8 @@ protocol ClientProxyProtocol: AnyObject, MediaLoaderProtocol {
|
||||
|
||||
var inviteSummaryProvider: RoomSummaryProviderProtocol? { get }
|
||||
|
||||
var notificationSettings: NotificationSettingsProxyProtocol { get }
|
||||
|
||||
func startSync()
|
||||
|
||||
func stopSync()
|
||||
@@ -114,6 +116,4 @@ protocol ClientProxyProtocol: AnyObject, MediaLoaderProtocol {
|
||||
func searchUsers(searchTerm: String, limit: UInt) async -> Result<SearchUsersResultsProxy, ClientProxyError>
|
||||
|
||||
func profile(for userID: String) async -> Result<UserProfileProxy, ClientProxyError>
|
||||
|
||||
func notificationSettings() async -> NotificationSettingsProxyProtocol
|
||||
}
|
||||
|
||||
@@ -32,6 +32,8 @@ class MockClientProxy: ClientProxyProtocol {
|
||||
var inviteSummaryProvider: RoomSummaryProviderProtocol? = MockRoomSummaryProvider()
|
||||
|
||||
var avatarURLPublisher: AnyPublisher<URL?, Never> { Empty().eraseToAnyPublisher() }
|
||||
|
||||
var notificationSettings: NotificationSettingsProxyProtocol = NotificationSettingsProxyMock(with: .init())
|
||||
|
||||
init(userID: String, deviceID: String? = nil, accountURL: URL? = nil, roomSummaryProvider: RoomSummaryProviderProtocol? = MockRoomSummaryProvider()) {
|
||||
self.userID = userID
|
||||
@@ -141,13 +143,4 @@ class MockClientProxy: ClientProxyProtocol {
|
||||
getProfileCalled = true
|
||||
return getProfileResult
|
||||
}
|
||||
|
||||
var notificationSettingsResult: NotificationSettingsProxyProtocol?
|
||||
func notificationSettings() -> NotificationSettingsProxyProtocol {
|
||||
if let notificationSettingsResult {
|
||||
return notificationSettingsResult
|
||||
} else {
|
||||
return NotificationSettingsProxyMock(with: .init())
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -37,7 +37,7 @@ private final class WeakNotificationSettingsProxy: NotificationSettingsDelegate
|
||||
final class NotificationSettingsProxy: NotificationSettingsProxyProtocol {
|
||||
private(set) var notificationSettings: MatrixRustSDK.NotificationSettingsProtocol
|
||||
private let backgroundTaskService: BackgroundTaskServiceProtocol?
|
||||
|
||||
|
||||
let callbacks = PassthroughSubject<NotificationSettingsProxyCallback, Never>()
|
||||
|
||||
init(notificationSettings: MatrixRustSDK.NotificationSettingsProtocol, backgroundTaskService: BackgroundTaskServiceProtocol?) {
|
||||
|
||||
@@ -57,6 +57,7 @@ extension Array where Element == RoomSummary {
|
||||
lastMessage: AttributedString("Prosciutto beef ribs pancetta filet mignon kevin hamburger, chuck ham venison picanha. Beef ribs chislic turkey biltong tenderloin."),
|
||||
lastMessageFormattedTimestamp: "Now",
|
||||
unreadNotificationCount: 4,
|
||||
notificationMode: .allMessages,
|
||||
canonicalAlias: nil,
|
||||
inviter: RoomMemberProxyMock.mockCharlie)),
|
||||
.filled(details: RoomSummaryDetails(id: "2",
|
||||
@@ -66,6 +67,7 @@ extension Array where Element == RoomSummary {
|
||||
lastMessage: nil,
|
||||
lastMessageFormattedTimestamp: nil,
|
||||
unreadNotificationCount: 1,
|
||||
notificationMode: .mentionsAndKeywordsOnly,
|
||||
canonicalAlias: nil,
|
||||
inviter: RoomMemberProxyMock.mockCharlie)),
|
||||
.filled(details: RoomSummaryDetails(id: "3",
|
||||
@@ -75,6 +77,7 @@ extension Array where Element == RoomSummary {
|
||||
lastMessage: try? AttributedString(markdown: "**@mock:client.com**: T-bone beef ribs bacon"),
|
||||
lastMessageFormattedTimestamp: "Later",
|
||||
unreadNotificationCount: 0,
|
||||
notificationMode: .mute,
|
||||
canonicalAlias: nil,
|
||||
inviter: RoomMemberProxyMock.mockCharlie)),
|
||||
.empty
|
||||
@@ -87,6 +90,7 @@ extension Array where Element == RoomSummary {
|
||||
lastMessage: nil,
|
||||
lastMessageFormattedTimestamp: nil,
|
||||
unreadNotificationCount: 0,
|
||||
notificationMode: nil,
|
||||
canonicalAlias: "#footest:somewhere.org",
|
||||
inviter: RoomMemberProxyMock.mockCharlie)),
|
||||
.filled(details: RoomSummaryDetails(id: "someAwesomeRoomId2",
|
||||
@@ -96,6 +100,7 @@ extension Array where Element == RoomSummary {
|
||||
lastMessage: nil,
|
||||
lastMessageFormattedTimestamp: nil,
|
||||
unreadNotificationCount: 0,
|
||||
notificationMode: nil,
|
||||
canonicalAlias: nil,
|
||||
inviter: RoomMemberProxyMock.mockCharlie))
|
||||
]
|
||||
|
||||
@@ -25,6 +25,7 @@ struct RoomSummaryDetails {
|
||||
let lastMessage: AttributedString?
|
||||
let lastMessageFormattedTimestamp: String?
|
||||
let unreadNotificationCount: UInt
|
||||
let notificationMode: RoomNotificationModeProxy?
|
||||
let canonicalAlias: String?
|
||||
let inviter: RoomMemberProxyProtocol?
|
||||
}
|
||||
|
||||
@@ -23,6 +23,7 @@ class RoomSummaryProvider: RoomSummaryProviderProtocol {
|
||||
private let eventStringBuilder: RoomEventStringBuilder
|
||||
private let name: String
|
||||
private var appSettings: AppSettings
|
||||
private let notificationSettings: NotificationSettingsProxyProtocol
|
||||
private let backgroundTaskService: BackgroundTaskServiceProtocol
|
||||
|
||||
private let serialDispatchQueue: DispatchQueue
|
||||
@@ -58,18 +59,24 @@ class RoomSummaryProvider: RoomSummaryProviderProtocol {
|
||||
eventStringBuilder: RoomEventStringBuilder,
|
||||
name: String,
|
||||
appSettings: AppSettings,
|
||||
notificationSettings: NotificationSettingsProxyProtocol,
|
||||
backgroundTaskService: BackgroundTaskServiceProtocol) {
|
||||
self.roomListService = roomListService
|
||||
serialDispatchQueue = DispatchQueue(label: "io.element.elementx.roomsummaryprovider", qos: .default)
|
||||
self.eventStringBuilder = eventStringBuilder
|
||||
self.name = name
|
||||
self.appSettings = appSettings
|
||||
self.notificationSettings = notificationSettings
|
||||
self.backgroundTaskService = backgroundTaskService
|
||||
|
||||
diffsPublisher
|
||||
.receive(on: serialDispatchQueue)
|
||||
.sink { [weak self] in self?.updateRoomsWithDiffs($0) }
|
||||
.store(in: &cancellables)
|
||||
|
||||
if appSettings.notificationSettingsEnabled {
|
||||
setupNotificationSettingsSubscription()
|
||||
}
|
||||
}
|
||||
|
||||
func setRoomList(_ roomList: RoomList) {
|
||||
@@ -227,6 +234,8 @@ class RoomSummaryProvider: RoomSummaryProviderProtocol {
|
||||
inviterProxy = RoomMemberProxy(member: inviter, backgroundTaskService: backgroundTaskService)
|
||||
}
|
||||
|
||||
let notificationMode = roomInfo.notificationMode.flatMap { RoomNotificationModeProxy.from(roomNotificationMode: $0) }
|
||||
|
||||
let details = RoomSummaryDetails(id: roomInfo.id,
|
||||
name: roomInfo.name ?? roomInfo.id,
|
||||
isDirect: roomInfo.isDirect,
|
||||
@@ -234,6 +243,7 @@ class RoomSummaryProvider: RoomSummaryProviderProtocol {
|
||||
lastMessage: attributedLastMessage,
|
||||
lastMessageFormattedTimestamp: lastMessageFormattedTimestamp,
|
||||
unreadNotificationCount: UInt(roomInfo.notificationCount),
|
||||
notificationMode: notificationMode,
|
||||
canonicalAlias: roomInfo.canonicalAlias,
|
||||
inviter: inviterProxy)
|
||||
|
||||
@@ -324,6 +334,43 @@ class RoomSummaryProvider: RoomSummaryProviderProtocol {
|
||||
|
||||
return CollectionDifference(changes)
|
||||
}
|
||||
|
||||
private func setupNotificationSettingsSubscription() {
|
||||
notificationSettings.callbacks
|
||||
.receive(on: serialDispatchQueue)
|
||||
.dropFirst() // drop the first one to avoid rebuilding the summaries during the first synchronization
|
||||
.sink { [weak self] callback in
|
||||
guard let self else { return }
|
||||
switch callback {
|
||||
case .settingsDidChange:
|
||||
self.rebuildRoomSummaries()
|
||||
}
|
||||
}
|
||||
.store(in: &cancellables)
|
||||
}
|
||||
|
||||
private func rebuildRoomSummaries() {
|
||||
let span = MXLog.createSpan("\(name).rebuild_room_summaries")
|
||||
span.enter()
|
||||
defer {
|
||||
span.exit()
|
||||
}
|
||||
|
||||
MXLog.info("\(name): Rebuilding room summaries for \(rooms.count) rooms")
|
||||
|
||||
rooms = rooms.map {
|
||||
switch $0 {
|
||||
case .empty:
|
||||
return $0
|
||||
case .filled(let details):
|
||||
return self.buildRoomSummaryForIdentifier(details.id, invalidated: false)
|
||||
case .invalidated(let details):
|
||||
return self.buildRoomSummaryForIdentifier(details.id, invalidated: true)
|
||||
}
|
||||
}
|
||||
|
||||
MXLog.info("\(name): Finished rebuilding room summaries (\(rooms.count) rooms)")
|
||||
}
|
||||
}
|
||||
|
||||
extension RoomSummaryProviderState {
|
||||
|
||||
Reference in New Issue
Block a user