mirror of
https://github.com/Novaloop-AG/element-x-ios.git
synced 2026-11-03 16:10:20 +00:00
Move room subscriptions to a separate call, fix side effects when requesting other room data (leaving, inviter etc)
This commit is contained in:
committed by
Stefan Ceriu
parent
c64fb44c96
commit
54164b8437
@@ -282,6 +282,8 @@ class RoomFlowCoordinator: FlowCoordinatorProtocol {
|
||||
roomProxy = proxy
|
||||
}
|
||||
|
||||
await roomProxy.subscribeForUpdates()
|
||||
|
||||
actionsSubject.send(.presentedRoom(roomID))
|
||||
|
||||
self.roomProxy = roomProxy
|
||||
@@ -369,6 +371,7 @@ class RoomFlowCoordinator: FlowCoordinatorProtocol {
|
||||
private func asyncPresentRoomDetails(roomID: String, isRoot: Bool, animated: Bool) async {
|
||||
if isRoot {
|
||||
roomProxy = await userSession.clientProxy.roomForIdentifier(roomID)
|
||||
await roomProxy?.subscribeForUpdates()
|
||||
} else {
|
||||
await asyncPresentRoom(roomID, animated: animated)
|
||||
}
|
||||
|
||||
@@ -778,6 +778,18 @@ class RoomProxyMock: RoomProxyProtocol {
|
||||
}
|
||||
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
|
||||
|
||||
var loadAvatarURLForUserIdCallsCount = 0
|
||||
|
||||
@@ -72,6 +72,18 @@ class RoomProxy: RoomProxyProtocol {
|
||||
self.room = room
|
||||
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: ""),
|
||||
RequiredState(key: "m.room.topic", value: ""),
|
||||
RequiredState(key: "m.room.avatar", value: ""),
|
||||
@@ -79,26 +91,21 @@ class RoomProxy: RoomProxyProtocol {
|
||||
RequiredState(key: "m.room.join_rules", value: "")],
|
||||
timelineLimit: UInt32(SlidingSyncConstants.defaultTimelineLimit))
|
||||
roomListItem.subscribe(settings: settings)
|
||||
|
||||
|
||||
let timelineListener = RoomTimelineListener { [weak self] timelineDiffs in
|
||||
self?.updatesSubject.send(timelineDiffs)
|
||||
}
|
||||
|
||||
|
||||
self.timelineListener = timelineListener
|
||||
|
||||
let result = await room.addTimelineListener(listener: timelineListener)
|
||||
roomTimelineObservationToken = result.itemsStream
|
||||
|
||||
|
||||
subscribeToBackpagination()
|
||||
|
||||
innerTimelineProvider = await RoomTimelineProvider(currentItems: result.items,
|
||||
updatePublisher: updatesPublisher,
|
||||
backPaginationStatePublisher: backPaginationStateSubject.eraseToAnyPublisher())
|
||||
|
||||
Task {
|
||||
await fetchMembers()
|
||||
await updateMembers()
|
||||
}
|
||||
}
|
||||
|
||||
lazy var id: String = room.id()
|
||||
|
||||
@@ -77,6 +77,8 @@ protocol RoomProxyProtocol {
|
||||
var updatesPublisher: AnyPublisher<[TimelineDiff], Never> { get }
|
||||
|
||||
var timelineProvider: RoomTimelineProviderProtocol { get }
|
||||
|
||||
func subscribeForUpdates() async
|
||||
|
||||
func loadAvatarURLForUserId(_ userId: String) async -> Result<URL?, RoomProxyError>
|
||||
|
||||
|
||||
Reference in New Issue
Block a user