-
Notifications
You must be signed in to change notification settings - Fork 338
Add alert to encrypted rooms with visible history (Android). #5709
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
kaylendog
wants to merge
9
commits into
element-hq:develop
Choose a base branch
from
kaylendog:kaylendog/history-sharing/alert-impl
base: develop
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
+452
−0
Open
Changes from all commits
Commits
Show all changes
9 commits
Select commit
Hold shift + click to select a range
6c29249
feat: Add visible history alert to encrypted rooms.
kaylendog 4f4a5d3
chore: Fix linting issues.
kaylendog 888b82b
feat: Move alert showing logic into state presenter.
kaylendog 88f7eb7
chore: Fix linting issues.
kaylendog fba1d91
tests: Fixup tests.
kaylendog 09de0be
feat: Use real link.
kaylendog 46fba48
chore: Update license header.
kaylendog a59651f
chore: Add (c) to license headers.
kaylendog 7fd25c3
chore: Add `.` to license header.
kaylendog File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
42 changes: 42 additions & 0 deletions
42
...d/features/messages/impl/crypto/historyvisible/HistoryVisibleAcknowledgementRepository.kt
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,42 @@ | ||
| /* | ||
| * Copyright (c) 2025 Element Creations Ltd. | ||
| * | ||
| * SPDX-License-Identifier: AGPL-3.0-only OR LicenseRef-Element-Commercial. | ||
| * Please see LICENSE files in the repository root for full details. | ||
| */ | ||
|
|
||
| package io.element.android.features.messages.impl.crypto.historyvisible | ||
|
|
||
| import androidx.datastore.preferences.core.booleanPreferencesKey | ||
| import androidx.datastore.preferences.core.edit | ||
| import dev.zacsweers.metro.ContributesBinding | ||
| import io.element.android.libraries.di.SessionScope | ||
| import io.element.android.libraries.matrix.api.core.RoomId | ||
| import io.element.android.libraries.preferences.api.store.PreferenceDataStoreFactory | ||
| import kotlinx.coroutines.flow.Flow | ||
| import kotlinx.coroutines.flow.map | ||
|
|
||
| interface HistoryVisibleAcknowledgementRepository { | ||
| fun hasAcknowledged(roomId: RoomId): Flow<Boolean> | ||
| suspend fun setAcknowledged(roomId: RoomId, value: Boolean) | ||
| } | ||
|
|
||
| @ContributesBinding(SessionScope::class) | ||
| class DefaultHistoryVisibleAcknowledgementRepository( | ||
| preferenceDataStoreFactory: PreferenceDataStoreFactory, | ||
| ) : HistoryVisibleAcknowledgementRepository { | ||
| val store = preferenceDataStoreFactory.create("elementx_historyvisible") | ||
|
|
||
| override fun hasAcknowledged(roomId: RoomId): Flow<Boolean> { | ||
| return store.data.map { prefs -> | ||
| val acknowledged = prefs[booleanPreferencesKey(roomId.value)] ?: false | ||
| acknowledged | ||
| } | ||
| } | ||
|
|
||
| override suspend fun setAcknowledged(roomId: RoomId, value: Boolean) { | ||
| store.edit { prefs -> | ||
| prefs[booleanPreferencesKey(roomId.value)] = value | ||
| } | ||
| } | ||
| } | ||
12 changes: 12 additions & 0 deletions
12
...in/io/element/android/features/messages/impl/crypto/historyvisible/HistoryVisibleEvent.kt
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,12 @@ | ||
| /* | ||
| * Copyright (c) 2025 Element Creations Ltd. | ||
| * | ||
| * SPDX-License-Identifier: AGPL-3.0-only OR LicenseRef-Element-Commercial. | ||
| * Please see LICENSE files in the repository root for full details. | ||
| */ | ||
|
|
||
| package io.element.android.features.messages.impl.crypto.historyvisible | ||
|
|
||
| sealed interface HistoryVisibleEvent { | ||
| data object Acknowledge : HistoryVisibleEvent | ||
| } |
13 changes: 13 additions & 0 deletions
13
...in/io/element/android/features/messages/impl/crypto/historyvisible/HistoryVisibleState.kt
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,13 @@ | ||
| /* | ||
| * Copyright (c) 2025 Element Creations Ltd. | ||
| * | ||
| * SPDX-License-Identifier: AGPL-3.0-only OR LicenseRef-Element-Commercial. | ||
| * Please see LICENSE files in the repository root for full details. | ||
| */ | ||
|
|
||
| package io.element.android.features.messages.impl.crypto.historyvisible | ||
|
|
||
| data class HistoryVisibleState( | ||
| val showAlert: Boolean, | ||
| val eventSink: (HistoryVisibleEvent) -> Unit, | ||
| ) |
52 changes: 52 additions & 0 deletions
52
...ment/android/features/messages/impl/crypto/historyvisible/HistoryVisibleStatePresenter.kt
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,52 @@ | ||
| /* | ||
| * Copyright (c) 2025 Element Creations Ltd. | ||
| * | ||
| * SPDX-License-Identifier: AGPL-3.0-only OR LicenseRef-Element-Commercial. | ||
| * Please see LICENSE files in the repository root for full details. | ||
| */ | ||
|
|
||
| package io.element.android.features.messages.impl.crypto.historyvisible | ||
|
|
||
| import androidx.compose.runtime.Composable | ||
| import androidx.compose.runtime.LaunchedEffect | ||
| import androidx.compose.runtime.collectAsState | ||
| import androidx.compose.runtime.getValue | ||
| import androidx.compose.runtime.rememberCoroutineScope | ||
| import dev.zacsweers.metro.Inject | ||
| import io.element.android.libraries.architecture.Presenter | ||
| import io.element.android.libraries.matrix.api.room.JoinedRoom | ||
| import io.element.android.libraries.matrix.api.room.history.RoomHistoryVisibility | ||
| import kotlinx.coroutines.launch | ||
|
|
||
| @Inject | ||
| class HistoryVisibleStatePresenter( | ||
| private val repository: HistoryVisibleAcknowledgementRepository, | ||
| private val room: JoinedRoom, | ||
| ) : Presenter<HistoryVisibleState> { | ||
| @Composable | ||
| override fun present(): HistoryVisibleState { | ||
| val roomInfo by room.roomInfoFlow.collectAsState() | ||
| // Implicitly acknowledge the initial event to avoid flashes in UI. | ||
| val acknowledged by repository.hasAcknowledged(room.roomId).collectAsState(initial = true) | ||
|
|
||
| val coroutineScope = rememberCoroutineScope() | ||
|
|
||
| LaunchedEffect(roomInfo.historyVisibility) { | ||
| if (roomInfo.historyVisibility == RoomHistoryVisibility.Joined && acknowledged) { | ||
| repository.setAcknowledged(room.roomId, false) | ||
| } | ||
| } | ||
|
|
||
| return HistoryVisibleState( | ||
| showAlert = roomInfo.historyVisibility != RoomHistoryVisibility.Joined && roomInfo.isEncrypted == true && !acknowledged, | ||
| eventSink = { event -> | ||
| when (event) { | ||
| is HistoryVisibleEvent.Acknowledge -> | ||
| coroutineScope.launch { | ||
| repository.setAcknowledged(room.roomId, true) | ||
| } | ||
| } | ||
| } | ||
| ) | ||
| } | ||
| } |
26 changes: 26 additions & 0 deletions
26
...ement/android/features/messages/impl/crypto/historyvisible/HistoryVisibleStateProvider.kt
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,26 @@ | ||
| /* | ||
| * Copyright (c) 2025 Element Creations Ltd. | ||
| * | ||
| * SPDX-License-Identifier: AGPL-3.0-only OR LicenseRef-Element-Commercial. | ||
| * Please see LICENSE files in the repository root for full details. | ||
| */ | ||
|
|
||
| package io.element.android.features.messages.impl.crypto.historyvisible | ||
|
|
||
| import androidx.compose.ui.tooling.preview.PreviewParameterProvider | ||
|
|
||
| class HistoryVisibleStateProvider : PreviewParameterProvider<HistoryVisibleState> { | ||
| override val values: Sequence<HistoryVisibleState> | ||
| get() = sequenceOf( | ||
| aHistoryVisibleState(showAlert = false), | ||
| aHistoryVisibleState(showAlert = true), | ||
| ) | ||
| } | ||
|
|
||
| internal fun aHistoryVisibleState( | ||
| showAlert: Boolean = false, | ||
| eventSink: (HistoryVisibleEvent) -> Unit = {}, | ||
| ) = HistoryVisibleState( | ||
| showAlert, | ||
| eventSink = eventSink, | ||
| ) |
82 changes: 82 additions & 0 deletions
82
...o/element/android/features/messages/impl/crypto/historyvisible/HistoryVisibleStateView.kt
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,82 @@ | ||
| /* | ||
| * Copyright (c) 2025 Element Creations Ltd. | ||
| * | ||
| * SPDX-License-Identifier: AGPL-3.0-only OR LicenseRef-Element-Commercial. | ||
| * Please see LICENSE files in the repository root for full details. | ||
| */ | ||
|
|
||
| package io.element.android.features.messages.impl.crypto.historyvisible | ||
|
|
||
| import androidx.compose.runtime.Composable | ||
| import androidx.compose.ui.Modifier | ||
| import androidx.compose.ui.res.stringResource | ||
| import androidx.compose.ui.text.LinkAnnotation | ||
| import androidx.compose.ui.text.SpanStyle | ||
| import androidx.compose.ui.text.buildAnnotatedString | ||
| import androidx.compose.ui.text.font.FontWeight | ||
| import androidx.compose.ui.text.style.TextDecoration | ||
| import androidx.compose.ui.tooling.preview.PreviewParameter | ||
| import io.element.android.appconfig.LearnMoreConfig | ||
| import io.element.android.compound.theme.ElementTheme | ||
| import io.element.android.features.messages.impl.R | ||
| import io.element.android.libraries.designsystem.atomic.molecules.ComposerAlertLevel | ||
| import io.element.android.libraries.designsystem.atomic.molecules.ComposerAlertMolecule | ||
| import io.element.android.libraries.designsystem.preview.ElementPreview | ||
| import io.element.android.libraries.designsystem.preview.PreviewsDayNight | ||
| import io.element.android.libraries.ui.strings.CommonStrings | ||
|
|
||
| @Composable | ||
| fun HistoryVisibleStateView( | ||
| state: HistoryVisibleState, | ||
| onLinkClick: (String, Boolean) -> Unit, | ||
| modifier: Modifier = Modifier, | ||
| ) { | ||
| if (!state.showAlert) { | ||
| return | ||
| } | ||
|
|
||
| ComposerAlertMolecule( | ||
| modifier = modifier, | ||
| avatar = null, | ||
| showIcon = true, | ||
| level = ComposerAlertLevel.Info, | ||
| content = buildAnnotatedString { | ||
| val learnMoreStr = stringResource(CommonStrings.action_learn_more) | ||
| val fullText = stringResource(R.string.crypto_history_visible, learnMoreStr) | ||
| append(fullText) | ||
| val learnMoreStartIndex = fullText.lastIndexOf(learnMoreStr) | ||
| addStyle( | ||
| style = SpanStyle( | ||
| textDecoration = TextDecoration.Underline, | ||
| fontWeight = FontWeight.Bold, | ||
| color = ElementTheme.colors.textPrimary | ||
| ), | ||
| start = learnMoreStartIndex, | ||
| end = learnMoreStartIndex + learnMoreStr.length, | ||
| ) | ||
| addLink( | ||
| url = LinkAnnotation.Url( | ||
| url = LearnMoreConfig.HISTORY_VISIBLE_URL, | ||
| linkInteractionListener = { | ||
| onLinkClick(LearnMoreConfig.HISTORY_VISIBLE_URL, true) | ||
| } | ||
| ), | ||
| start = learnMoreStartIndex, | ||
| end = learnMoreStartIndex + learnMoreStr.length, | ||
| ) | ||
| }, | ||
| submitText = stringResource(CommonStrings.action_dismiss), | ||
| onSubmitClick = { state.eventSink(HistoryVisibleEvent.Acknowledge) }, | ||
| ) | ||
| } | ||
|
|
||
| @PreviewsDayNight | ||
| @Composable | ||
| internal fun HistoryVisibleStateViewPreview( | ||
| @PreviewParameter(HistoryVisibleStateProvider::class) state: HistoryVisibleState, | ||
| ) = ElementPreview { | ||
| HistoryVisibleStateView( | ||
| state = state, | ||
| onLinkClick = { _, _ -> }, | ||
| ) | ||
| } |
45 changes: 45 additions & 0 deletions
45
...oid/features/messages/impl/crypto/historyvisible/MessagesViewWithHistoryVisiblePreview.kt
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,45 @@ | ||
| /* | ||
| * Copyright (c) 2025 Element Creations Ltd. | ||
| * | ||
| * SPDX-License-Identifier: AGPL-3.0-only OR LicenseRef-Element-Commercial. | ||
| * Please see LICENSE files in the repository root for full details. | ||
| */ | ||
|
|
||
| package io.element.android.features.messages.impl.crypto.historyvisible | ||
|
|
||
| import androidx.compose.runtime.Composable | ||
| import androidx.compose.ui.tooling.preview.PreviewParameter | ||
| import io.element.android.features.messages.impl.MessagesView | ||
| import io.element.android.features.messages.impl.aMessagesState | ||
| import io.element.android.features.messages.impl.messagecomposer.aMessageComposerState | ||
| import io.element.android.libraries.designsystem.preview.ElementPreview | ||
| import io.element.android.libraries.designsystem.preview.PreviewsDayNight | ||
| import io.element.android.libraries.textcomposer.model.aTextEditorStateMarkdown | ||
|
|
||
| @PreviewsDayNight | ||
| @Composable | ||
| internal fun MessagesViewWithHistoryVisiblePreview( | ||
| @PreviewParameter(HistoryVisibleStateProvider::class) historyVisibleState: HistoryVisibleState | ||
| ) = ElementPreview { | ||
| MessagesView( | ||
| state = aMessagesState( | ||
| composerState = aMessageComposerState( | ||
| textEditorState = aTextEditorStateMarkdown( | ||
| initialText = "", | ||
| initialFocus = false, | ||
| ) | ||
| ), | ||
| historyVisibleState = historyVisibleState, | ||
| ), | ||
| onBackClick = {}, | ||
| onRoomDetailsClick = {}, | ||
| onEventContentClick = { _, _ -> false }, | ||
| onUserDataClick = {}, | ||
| onLinkClick = { _, _ -> }, | ||
| onSendLocationClick = {}, | ||
| onCreatePollClick = {}, | ||
| onJoinCallClick = {}, | ||
| onViewAllPinnedMessagesClick = {}, | ||
| knockRequestsBannerView = {} | ||
| ) | ||
| } |
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm not sure if this is the correct naming scheme to use?