Move room subscriptions to a separate call, fix side effects when requesting other room data (leaving, inviter etc)

This commit is contained in:
Stefan Ceriu
2023-08-16 15:53:42 +03:00
committed by Stefan Ceriu
parent c64fb44c96
commit 54164b8437
4 changed files with 32 additions and 8 deletions
@@ -282,6 +282,8 @@ class RoomFlowCoordinator: FlowCoordinatorProtocol {
roomProxy = proxy roomProxy = proxy
} }
await roomProxy.subscribeForUpdates()
actionsSubject.send(.presentedRoom(roomID)) actionsSubject.send(.presentedRoom(roomID))
self.roomProxy = roomProxy self.roomProxy = roomProxy
@@ -369,6 +371,7 @@ class RoomFlowCoordinator: FlowCoordinatorProtocol {
private func asyncPresentRoomDetails(roomID: String, isRoot: Bool, animated: Bool) async { private func asyncPresentRoomDetails(roomID: String, isRoot: Bool, animated: Bool) async {
if isRoot { if isRoot {
roomProxy = await userSession.clientProxy.roomForIdentifier(roomID) roomProxy = await userSession.clientProxy.roomForIdentifier(roomID)
await roomProxy?.subscribeForUpdates()
} else { } else {
await asyncPresentRoom(roomID, animated: animated) await asyncPresentRoom(roomID, animated: animated)
} }
@@ -778,6 +778,18 @@ class RoomProxyMock: RoomProxyProtocol {
} }
var underlyingTimelineProvider: RoomTimelineProviderProtocol! var underlyingTimelineProvider: RoomTimelineProviderProtocol!
//MARK: - subscribeForUpdates
var subscribeForUpdatesCallsCount = 0
var subscribeForUpdatesCalled: Bool {
return subscribeForUpdatesCallsCount > 0
}
var subscribeForUpdatesClosure: (() async -> Void)?
func subscribeForUpdates() async {
subscribeForUpdatesCallsCount += 1
await subscribeForUpdatesClosure?()
}
//MARK: - loadAvatarURLForUserId //MARK: - loadAvatarURLForUserId
var loadAvatarURLForUserIdCallsCount = 0 var loadAvatarURLForUserIdCallsCount = 0
+12 -5
View File
@@ -72,6 +72,18 @@ class RoomProxy: RoomProxyProtocol {
self.room = room self.room = room
self.backgroundTaskService = backgroundTaskService self.backgroundTaskService = backgroundTaskService
Task {
await fetchMembers()
await updateMembers()
}
}
func subscribeForUpdates() async {
guard innerTimelineProvider == nil else {
MXLog.warning("Room already subscribed for updates")
return
}
let settings = RoomSubscription(requiredState: [RequiredState(key: "m.room.name", value: ""), let settings = RoomSubscription(requiredState: [RequiredState(key: "m.room.name", value: ""),
RequiredState(key: "m.room.topic", value: ""), RequiredState(key: "m.room.topic", value: ""),
RequiredState(key: "m.room.avatar", value: ""), RequiredState(key: "m.room.avatar", value: ""),
@@ -94,11 +106,6 @@ class RoomProxy: RoomProxyProtocol {
innerTimelineProvider = await RoomTimelineProvider(currentItems: result.items, innerTimelineProvider = await RoomTimelineProvider(currentItems: result.items,
updatePublisher: updatesPublisher, updatePublisher: updatesPublisher,
backPaginationStatePublisher: backPaginationStateSubject.eraseToAnyPublisher()) backPaginationStatePublisher: backPaginationStateSubject.eraseToAnyPublisher())
Task {
await fetchMembers()
await updateMembers()
}
} }
lazy var id: String = room.id() lazy var id: String = room.id()
@@ -78,6 +78,8 @@ protocol RoomProxyProtocol {
var timelineProvider: RoomTimelineProviderProtocol { get } var timelineProvider: RoomTimelineProviderProtocol { get }
func subscribeForUpdates() async
func loadAvatarURLForUserId(_ userId: String) async -> Result<URL?, RoomProxyError> func loadAvatarURLForUserId(_ userId: String) async -> Result<URL?, RoomProxyError>
func loadDisplayNameForUserId(_ userId: String) async -> Result<String?, RoomProxyError> func loadDisplayNameForUserId(_ userId: String) async -> Result<String?, RoomProxyError>