Merge pull request #5936 from kaylendog/kaylendog/history-sharing/algorithm
Show history visibility banner strictly for `shared` rooms instead of `invited`.
This commit is contained in:
commit
9ad69a0af7
2 changed files with 18 additions and 6 deletions
|
|
@ -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,14 @@ 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) {
|
||||
// Clear the dismissed flag, if it is set to ensure that if a room is changed public -> private -> public,
|
||||
// we show the banner again when it is set back to public.
|
||||
repository.setAcknowledged(room.roomId, false)
|
||||
}
|
||||
}
|
||||
|
|
@ -51,7 +53,7 @@ class HistoryVisibleStatePresenter(
|
|||
}
|
||||
|
||||
return HistoryVisibleState(
|
||||
showAlert = isFeatureEnabled && roomInfo.historyVisibility != RoomHistoryVisibility.Joined && roomInfo.isEncrypted == true && !acknowledged,
|
||||
showAlert = isFeatureEnabled && isHistoryVisible && roomInfo.isEncrypted == true && !acknowledged,
|
||||
eventSink = ::handleEvent,
|
||||
)
|
||||
}
|
||||
|
|
|
|||
|
|
@ -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()
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue