Manually cancel timeline listeners when a RoomScreen is torn down instead of waiting for a delayed deinit

This commit is contained in:
Stefan Ceriu 2023-02-23 15:22:09 +02:00 committed by Stefan Ceriu
parent 698b0aea44
commit 99d6caed4e
4 changed files with 11 additions and 7 deletions

View File

@ -60,6 +60,7 @@ final class RoomScreenCoordinator: CoordinatorProtocol {
}
func stop() {
parameters.roomProxy.removeTimelineListener()
viewModel.context.send(viewAction: .markRoomAsRead)
}

View File

@ -44,12 +44,12 @@ struct MockRoomProxy: RoomProxyProtocol {
.failure(.failedRetrievingMemberAvatarURL)
}
func startLiveEventListener() { }
func addTimelineListener(listener: TimelineListener) -> Result<[TimelineItem], RoomProxyError> {
.failure(.failedAddingTimelineListener)
}
func removeTimelineListener() { }
func paginateBackwards(requestSize: UInt, untilNumberOfItems: UInt) async -> Result<Void, RoomProxyError> {
.failure(.failedPaginatingBackwards)
}

View File

@ -34,11 +34,7 @@ class RoomProxy: RoomProxyProtocol {
private(set) var displayName: String?
private var timelineObservationToken: StoppableSpawn?
deinit {
timelineObservationToken?.cancel()
}
init(slidingSyncRoom: SlidingSyncRoomProtocol,
room: RoomProtocol,
backgroundTaskService: BackgroundTaskServiceProtocol) {
@ -151,6 +147,11 @@ class RoomProxy: RoomProxyProtocol {
}
}
func removeTimelineListener() {
timelineObservationToken?.cancel()
timelineObservationToken = nil
}
func paginateBackwards(requestSize: UInt, untilNumberOfItems: UInt) async -> Result<Void, RoomProxyError> {
do {
try await Task.dispatch(on: .global()) {

View File

@ -60,6 +60,8 @@ protocol RoomProxyProtocol {
func addTimelineListener(listener: TimelineListener) -> Result<[TimelineItem], RoomProxyError>
func removeTimelineListener()
func paginateBackwards(requestSize: UInt, untilNumberOfItems: UInt) async -> Result<Void, RoomProxyError>
func sendReadReceipt(for eventID: String) async -> Result<Void, RoomProxyError>