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
+15 -8
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: ""),
@@ -79,26 +91,21 @@ class RoomProxy: RoomProxyProtocol {
RequiredState(key: "m.room.join_rules", value: "")], RequiredState(key: "m.room.join_rules", value: "")],
timelineLimit: UInt32(SlidingSyncConstants.defaultTimelineLimit)) timelineLimit: UInt32(SlidingSyncConstants.defaultTimelineLimit))
roomListItem.subscribe(settings: settings) roomListItem.subscribe(settings: settings)
let timelineListener = RoomTimelineListener { [weak self] timelineDiffs in let timelineListener = RoomTimelineListener { [weak self] timelineDiffs in
self?.updatesSubject.send(timelineDiffs) self?.updatesSubject.send(timelineDiffs)
} }
self.timelineListener = timelineListener self.timelineListener = timelineListener
let result = await room.addTimelineListener(listener: timelineListener) let result = await room.addTimelineListener(listener: timelineListener)
roomTimelineObservationToken = result.itemsStream roomTimelineObservationToken = result.itemsStream
subscribeToBackpagination() subscribeToBackpagination()
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()
@@ -77,6 +77,8 @@ protocol RoomProxyProtocol {
var updatesPublisher: AnyPublisher<[TimelineDiff], Never> { get } var updatesPublisher: AnyPublisher<[TimelineDiff], Never> { get }
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>