Skip to content

Commit

Permalink
Make room proxy unsubscriptions explicit. Fixes problems in which cre…
Browse files Browse the repository at this point in the history
…ating and deallocating room proxies would unexpectedly unsubscribe other proxies.
  • Loading branch information
stefanceriu committed Jan 17, 2024
1 parent 886caaf commit 55bcc0a
Show file tree
Hide file tree
Showing 4 changed files with 25 additions and 6 deletions.
7 changes: 6 additions & 1 deletion ElementX/Sources/FlowCoordinators/RoomFlowCoordinator.swift
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,12 @@ class RoomFlowCoordinator: FlowCoordinatorProtocol {
actionsSubject.eraseToAnyPublisher()
}

private var roomProxy: RoomProxyProtocol?
private var roomProxy: RoomProxyProtocol? {
didSet {
oldValue?.unsubscribeFromUpdates()
}
}

private var timelineController: RoomTimelineControllerProtocol?

init(userSession: UserSessionProtocol,
Expand Down
14 changes: 13 additions & 1 deletion ElementX/Sources/Mocks/Generated/GeneratedMocks.swift
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// Generated using Sourcery 2.1.3 — https://github.com/krzysztofzablocki/Sourcery
// Generated using Sourcery 2.1.2 — https://github.com/krzysztofzablocki/Sourcery
// DO NOT EDIT

// swiftlint:disable all
Expand Down Expand Up @@ -1864,6 +1864,18 @@ class RoomProxyMock: RoomProxyProtocol {
subscribeForUpdatesCallsCount += 1
await subscribeForUpdatesClosure?()
}
//MARK: - unsubscribeFromUpdates

var unsubscribeFromUpdatesCallsCount = 0
var unsubscribeFromUpdatesCalled: Bool {
return unsubscribeFromUpdatesCallsCount > 0
}
var unsubscribeFromUpdatesClosure: (() -> Void)?

func unsubscribeFromUpdates() {
unsubscribeFromUpdatesCallsCount += 1
unsubscribeFromUpdatesClosure?()
}
//MARK: - redact

var redactCallsCount = 0
Expand Down
8 changes: 4 additions & 4 deletions ElementX/Sources/Services/Room/RoomProxy.swift
Original file line number Diff line number Diff line change
Expand Up @@ -51,10 +51,6 @@ class RoomProxy: RoomProxyProtocol {
room.ownUserId()
}

deinit {
roomListItem.unsubscribe()
}

init(roomListItem: RoomListItemProtocol,
room: RoomProtocol,
backgroundTaskService: BackgroundTaskServiceProtocol) async {
Expand Down Expand Up @@ -89,6 +85,10 @@ class RoomProxy: RoomProxyProtocol {

subscribeToRoomStateUpdates()
}

func unsubscribeFromUpdates() {
roomListItem.unsubscribe()
}

lazy var id: String = room.id()

Expand Down
2 changes: 2 additions & 0 deletions ElementX/Sources/Services/Room/RoomProxyProtocol.swift
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,8 @@ protocol RoomProxyProtocol {

func subscribeForUpdates() async

func unsubscribeFromUpdates()

func redact(_ eventID: String) async -> Result<Void, RoomProxyError>

func reportContent(_ eventID: String, reason: String?) async -> Result<Void, RoomProxyError>
Expand Down

0 comments on commit 55bcc0a

Please sign in to comment.