mirror of
https://github.com/Novaloop-AG/element-x-ios.git
synced 2026-11-03 16:10:20 +00:00
Implement Knock Logic (#3573)
* WIP RequestToJoin struct * implemented the logic to display the cells * knock request banner accept flow * mark all knocks as seen implemented * details logic * implemented accept, decline and ban in the list * added a loader and modified the stacked view of the banner * pr suggestions * updated naming and loading strings * added the initial loading state improved code and the tests * updated a string that has changed * code improvement * tests for the room screen view model * room details tests and improved the knock requests tests for the room screen * knock requests list tests * added error state alerts with retry * struct has been renamed on the sdk so I renamed it also on the app side * update SDK
This commit is contained in:
@@ -60,6 +60,8 @@ class JoinedRoomProxy: JoinedRoomProxyProtocol {
|
||||
private var typingNotificationObservationToken: TaskHandle?
|
||||
// periphery:ignore - required for instance retention in the rust codebase
|
||||
private var identityStatusChangesObservationToken: TaskHandle?
|
||||
// periphery:ignore - required for instance retention in the rust codebase
|
||||
private var knockRequestsChangesObservationToken: TaskHandle?
|
||||
|
||||
private var subscribedForUpdates = false
|
||||
|
||||
@@ -83,6 +85,11 @@ class JoinedRoomProxy: JoinedRoomProxyProtocol {
|
||||
identityStatusChangesSubject.asCurrentValuePublisher()
|
||||
}
|
||||
|
||||
private let knockRequestsStateSubject = CurrentValueSubject<KnockRequestsState, Never>(.loading)
|
||||
var knockRequestsStatePublisher: CurrentValuePublisher<KnockRequestsState, Never> {
|
||||
knockRequestsStateSubject.asCurrentValuePublisher()
|
||||
}
|
||||
|
||||
// A room identifier is constant and lazy stops it from being fetched
|
||||
// multiple times over FFI
|
||||
lazy var id: String = room.id()
|
||||
@@ -131,6 +138,8 @@ class JoinedRoomProxy: JoinedRoomProxyProtocol {
|
||||
}
|
||||
|
||||
subscribeToTypingNotifications()
|
||||
|
||||
await subscribeToKnockRequests()
|
||||
}
|
||||
|
||||
func subscribeToRoomInfoUpdates() {
|
||||
@@ -645,6 +654,19 @@ class JoinedRoomProxy: JoinedRoomProxyProtocol {
|
||||
identityStatusChangesSubject.send(changes)
|
||||
})
|
||||
}
|
||||
|
||||
private func subscribeToKnockRequests() async {
|
||||
do {
|
||||
knockRequestsChangesObservationToken = try await room.subscribeToKnockRequests(listener: RoomKnockRequestsListener { [weak self] requests in
|
||||
guard let self else { return }
|
||||
|
||||
MXLog.info("Received requests to join update, requests id: \(requests.map(\.eventId))")
|
||||
knockRequestsStateSubject.send(.loaded(requests.map(KnockRequestProxy.init)))
|
||||
})
|
||||
} catch {
|
||||
MXLog.error("Failed observing requests to join with error: \(error)")
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private final class RoomInfoUpdateListener: RoomInfoListener {
|
||||
@@ -682,3 +704,15 @@ private final class RoomIdentityStatusChangeListener: IdentityStatusChangeListen
|
||||
onUpdateClosure(identityStatusChange)
|
||||
}
|
||||
}
|
||||
|
||||
private final class RoomKnockRequestsListener: KnockRequestsListener {
|
||||
private let onUpdateClosure: ([KnockRequest]) -> Void
|
||||
|
||||
init(_ onUpdateClosure: @escaping ([KnockRequest]) -> Void) {
|
||||
self.onUpdateClosure = onUpdateClosure
|
||||
}
|
||||
|
||||
func call(joinRequests: [KnockRequest]) {
|
||||
onUpdateClosure(joinRequests)
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user