diff --git a/ElementX/Sources/Screens/RoomScreen/RoomScreenViewModel.swift b/ElementX/Sources/Screens/RoomScreen/RoomScreenViewModel.swift index 275ba96d08..69bae71f99 100644 --- a/ElementX/Sources/Screens/RoomScreen/RoomScreenViewModel.swift +++ b/ElementX/Sources/Screens/RoomScreen/RoomScreenViewModel.swift @@ -122,6 +122,9 @@ class RoomScreenViewModel: RoomScreenViewModelType, RoomScreenViewModelProtocol } func stop() { + // When navigating away from the room, we need to mark the room as fully read. + // This does not affect the read receipts only the notification count. + Task { await roomProxy.markAsRead(receiptType: .fullyRead) } // Work around QLPreviewController dismissal issues, see the InteractiveQuickLookModifier. state.bindings.mediaPreviewViewModel = nil } diff --git a/UnitTests/Sources/RoomScreenViewModelTests.swift b/UnitTests/Sources/RoomScreenViewModelTests.swift index b9199c98d7..ada85ec499 100644 --- a/UnitTests/Sources/RoomScreenViewModelTests.swift +++ b/UnitTests/Sources/RoomScreenViewModelTests.swift @@ -248,6 +248,28 @@ class RoomScreenViewModelTests: XCTestCase { XCTAssertTrue(viewModel.state.shouldShowCallButton) } + func testRoomFullyRead() async { + let expectation = XCTestExpectation(description: "Wait for fully read") + let roomProxyMock = JoinedRoomProxyMock(.init(id: "MyRoomID")) + roomProxyMock.markAsReadReceiptTypeClosure = { readReceiptType in + XCTAssertEqual(readReceiptType, .fullyRead) + expectation.fulfill() + return .success(()) + } + let viewModel = RoomScreenViewModel(clientProxy: ClientProxyMock(), + roomProxy: roomProxyMock, + initialSelectedPinnedEventID: nil, + mediaProvider: MediaProviderMock(configuration: .init()), + ongoingCallRoomIDPublisher: .init(.init(nil)), + appMediator: AppMediatorMock.default, + appSettings: ServiceLocator.shared.settings, + analyticsService: ServiceLocator.shared.analytics, + userIndicatorController: ServiceLocator.shared.userIndicatorController) + self.viewModel = viewModel + viewModel.stop() + await fulfillment(of: [expectation]) + } + // MARK: - Knock Requests func testKnockRequestBanner() async throws {