Fixes element-hq/element-meta/issues/2525 - Display a warning when a user's pinned identity changes

This commit is contained in:
Stefan Ceriu
2024-10-01 08:41:15 +03:00
parent 70652ed7be
commit 794d0eead1
30 changed files with 678 additions and 131 deletions
@@ -58,6 +58,8 @@ class JoinedRoomProxy: JoinedRoomProxyProtocol {
private var roomInfoObservationToken: TaskHandle?
// periphery:ignore - required for instance retention in the rust codebase
private var typingNotificationObservationToken: TaskHandle?
// periphery:ignore - required for instance retention in the rust codebase
private var identityStatusChangesObservationToken: TaskHandle?
private var subscribedForUpdates = false
@@ -70,6 +72,11 @@ class JoinedRoomProxy: JoinedRoomProxyProtocol {
var typingMembersPublisher: CurrentValuePublisher<[String], Never> {
typingMembersSubject.asCurrentValuePublisher()
}
private let identityStatusChangesSubject = CurrentValueSubject<[IdentityStatusChange], Never>([])
var identityStatusChangesPublisher: CurrentValuePublisher<[IdentityStatusChange], Never> {
identityStatusChangesSubject.asCurrentValuePublisher()
}
private let actionsSubject = PassthroughSubject<JoinedRoomProxyAction, Never>()
var actionsPublisher: AnyPublisher<JoinedRoomProxyAction, Never> {
@@ -193,6 +200,8 @@ class JoinedRoomProxy: JoinedRoomProxyProtocol {
subscribeToRoomInfoUpdates()
subscribeToIdentityStatusChanges()
subscribeToTypingNotifications()
}
@@ -708,6 +717,16 @@ class JoinedRoomProxy: JoinedRoomProxyProtocol {
typingMembersSubject.send(typingMembers)
})
}
private func subscribeToIdentityStatusChanges() {
identityStatusChangesObservationToken = room.subscribeToIdentityStatusChanges(listener: RoomIdentityStatusChangeListener { [weak self] changes in
guard let self else { return }
MXLog.info("Received identity status changes: \(changes)")
identityStatusChangesSubject.send(changes)
})
}
}
private final class RoomInfoUpdateListener: RoomInfoListener {
@@ -733,3 +752,15 @@ private final class RoomTypingNotificationUpdateListener: TypingNotificationsLis
onUpdateClosure(typingUserIds)
}
}
private final class RoomIdentityStatusChangeListener: IdentityStatusChangeListener {
private let onUpdateClosure: ([IdentityStatusChange]) -> Void
init(_ onUpdateClosure: @escaping ([IdentityStatusChange]) -> Void) {
self.onUpdateClosure = onUpdateClosure
}
func call(identityStatusChange: [IdentityStatusChange]) {
onUpdateClosure(identityStatusChange)
}
}