lifting hidden/private read receipt option to the view model

This commit is contained in:
Adam Brown 2022-09-13 22:06:37 +01:00
parent 43e53261b6
commit 0e4f6d6ac2
4 changed files with 7 additions and 7 deletions

View File

@ -101,7 +101,7 @@ internal class MessengerViewModel(
private fun CoroutineScope.updateRoomReadStateAsync(latestReadEvent: EventId, state: MessengerState): Deferred<Unit> {
return async {
runCatching {
roomService.markFullyRead(state.roomState.roomOverview.roomId, latestReadEvent)
roomService.markFullyRead(state.roomState.roomOverview.roomId, latestReadEvent, isPrivate = true)
roomStore.markRead(state.roomState.roomOverview.roomId)
}
}

View File

@ -69,7 +69,7 @@ class MessengerViewModelTest {
@Test
fun `given timeline emits state, when starting, then updates state and marks room and events as read`() = runViewModelTest {
fakeRoomStore.expectUnit(times = 2) { it.markRead(A_ROOM_ID) }
fakeRoomService.expectUnit { it.markFullyRead(A_ROOM_ID, AN_EVENT_ID) }
fakeRoomService.expectUnit { it.markFullyRead(A_ROOM_ID, AN_EVENT_ID, isPrivate = true) }
val state = aMessengerStateWithEvent(AN_EVENT_ID, A_SELF_ID)
fakeObserveTimelineUseCase.given(A_ROOM_ID, A_SELF_ID).returns(flowOf(state))

View File

@ -15,7 +15,7 @@ private val SERVICE_KEY = RoomService::class
interface RoomService : MatrixService {
suspend fun joinedMembers(roomId: RoomId): List<JoinedMember>
suspend fun markFullyRead(roomId: RoomId, eventId: EventId)
suspend fun markFullyRead(roomId: RoomId, eventId: EventId, isPrivate: Boolean)
suspend fun findMember(roomId: RoomId, userId: UserId): RoomMember?
suspend fun findMembers(roomId: RoomId, userIds: List<UserId>): List<RoomMember>

View File

@ -30,9 +30,9 @@ class DefaultRoomService(
}
}
override suspend fun markFullyRead(roomId: RoomId, eventId: EventId) {
override suspend fun markFullyRead(roomId: RoomId, eventId: EventId, isPrivate: Boolean) {
logger.matrixLog(ROOM, "marking room fully read ${roomId.value}")
httpClient.execute(markFullyReadRequest(roomId, eventId))
httpClient.execute(markFullyReadRequest(roomId, eventId, isPrivate))
}
override suspend fun findMember(roomId: RoomId, userId: UserId): RoomMember? {
@ -97,10 +97,10 @@ internal fun joinedMembersRequest(roomId: RoomId) = httpRequest<JoinedMembersRes
method = MatrixHttpClient.Method.GET,
)
internal fun markFullyReadRequest(roomId: RoomId, eventId: EventId) = httpRequest<Unit>(
internal fun markFullyReadRequest(roomId: RoomId, eventId: EventId, isPrivate: Boolean) = httpRequest<Unit>(
path = "_matrix/client/r0/rooms/${roomId.value}/read_markers",
method = MatrixHttpClient.Method.POST,
body = jsonBody(MarkFullyReadRequest(eventId, eventId, hidden = true))
body = jsonBody(MarkFullyReadRequest(eventId, eventId, hidden = isPrivate))
)
internal fun createRoomRequest(invites: List<UserId>, isDM: Boolean, visibility: RoomVisibility, name: String? = null) = httpRequest<ApiCreateRoomResponse>(