fix: Show history visibiliy banner for shared, not invited.

This commit is contained in:
Skye Elliot
2025-12-18 16:05:22 +00:00
parent 65c17eacc6
commit b3c4a2ba92
2 changed files with 16 additions and 6 deletions

View File

@@ -20,7 +20,6 @@ import io.element.android.libraries.matrix.api.core.RoomId
import io.element.android.libraries.matrix.api.room.JoinedRoom
import io.element.android.libraries.matrix.api.room.history.RoomHistoryVisibility
import kotlinx.coroutines.CoroutineScope
import kotlinx.coroutines.coroutineScope
import kotlinx.coroutines.launch
@Inject
@@ -35,11 +34,12 @@ class HistoryVisibleStatePresenter(
val roomInfo by room.roomInfoFlow.collectAsState()
// Implicitly assume the alert is initially acknowledged to avoid flashes in UI.
val acknowledged by repository.hasAcknowledged(room.roomId).collectAsState(initial = true)
val isHistoryVisible = roomInfo.historyVisibility == RoomHistoryVisibility.Shared || roomInfo.historyVisibility == RoomHistoryVisibility.WorldReadable
val coroutineScope = rememberCoroutineScope()
LaunchedEffect(roomInfo.historyVisibility, acknowledged) {
if (roomInfo.historyVisibility == RoomHistoryVisibility.Joined && acknowledged) {
LaunchedEffect(isHistoryVisible, acknowledged) {
if (!isHistoryVisible && acknowledged) {
repository.setAcknowledged(room.roomId, false)
}
}
@@ -51,7 +51,7 @@ class HistoryVisibleStatePresenter(
}
return HistoryVisibleState(
showAlert = isFeatureEnabled && roomInfo.historyVisibility != RoomHistoryVisibility.Joined && roomInfo.isEncrypted == true && !acknowledged,
showAlert = isFeatureEnabled && isHistoryVisible && roomInfo.isEncrypted == true && !acknowledged,
eventSink = ::handleEvent,
)
}

View File

@@ -28,7 +28,7 @@ class HistoryVisibleStatePresenterTest {
@Test
fun `present - not visible if feature disabled`() = runTest {
val room = FakeJoinedRoom()
room.givenRoomInfo(aRoomInfo(historyVisibility = RoomHistoryVisibility.Joined, isEncrypted = true))
room.givenRoomInfo(aRoomInfo(historyVisibility = RoomHistoryVisibility.Shared, isEncrypted = true))
val presenter = createHistoryVisibleStatePresenter(room, enabled = false, acknowledged = false)
presenter.test {
assertThat(awaitLastSequentialItem().showAlert).isFalse()
@@ -48,7 +48,17 @@ class HistoryVisibleStatePresenterTest {
@Test
fun `present - initial with room joined, encrypted`() = runTest {
val room = FakeJoinedRoom()
room.givenRoomInfo(aRoomInfo(historyVisibility = RoomHistoryVisibility.Joined, isEncrypted = false))
room.givenRoomInfo(aRoomInfo(historyVisibility = RoomHistoryVisibility.Joined, isEncrypted = true))
val presenter = createHistoryVisibleStatePresenter(room)
presenter.test {
assertThat(awaitLastSequentialItem().showAlert).isFalse()
}
}
@Test
fun `present - initial with room invited, encrypted`() = runTest {
val room = FakeJoinedRoom()
room.givenRoomInfo(aRoomInfo(historyVisibility = RoomHistoryVisibility.Invited, isEncrypted = true))
val presenter = createHistoryVisibleStatePresenter(room)
presenter.test {
assertThat(awaitLastSequentialItem().showAlert).isFalse()