feat: the disappearing-messages setting, and the conversation showing it (disappearing-messages, Phase 6)
A screen for the profile's default and a NIP-17 conversation's override: presets from Off to four weeks and a custom length from five minutes to a year, with what the setting does and does not do. The conversation shows its timer in the app bar, a one-time notice, and an hourglass beside each line that will disappear. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
1 parent
c50288a9a1
commit
2e747f907c
12 files changed
+582
No files matched your search
@@ -881,4 +881,37 @@
|
||||
<string name="action_mark_read">Mark as read</string>
|
||||
<string name="action_reply">Reply</string>
|
||||
<string name="action_reply_hint">Message</string>
|
||||
<!-- Disappearing messages (docs/disappearing-messages.md, Phase 6) -->
|
||||
<string name="disappearing_messages">Disappearing messages</string>
|
||||
<string name="disappearing_messages_profile_supporting">How long the messages you send last, in direct messages and in quorum and confederation conversations</string>
|
||||
<string name="disappearing_messages_room_supporting">How long the messages you send here last</string>
|
||||
<string name="disappearing_off">Off</string>
|
||||
<string name="disappearing_custom">Custom…</string>
|
||||
<string name="disappearing_use_default">Use your default (%1$s)</string>
|
||||
<string name="disappearing_default_value">Default (%1$s)</string>
|
||||
<string name="disappearing_explanation">Messages you send are deleted from your devices and from the recipient's Giza after this time, and relays are asked to delete them too. Other apps, screenshots and relays that ignore the request can keep a copy.</string>
|
||||
<string name="disappearing_offline_warning">If someone does not open Giza within this time, they may never receive the message.</string>
|
||||
<string name="disappearing_protocol_note">Signing and key ceremony messages always expire. They are kept for at least a day, or a week for key ceremonies, and are not deleted from this device until the ceremony they belong to has finished.</string>
|
||||
<string name="disappearing_groups_note">A group's own room follows the group's setting, not this one.</string>
|
||||
<string name="disappearing_saved">Disappearing messages set to %1$s</string>
|
||||
<string name="disappearing_custom_title">Custom length</string>
|
||||
<string name="disappearing_custom_amount">Length</string>
|
||||
<string name="disappearing_custom_out_of_range">Choose between 5 minutes and 365 days</string>
|
||||
<string name="disappearing_unit_minutes">Minutes</string>
|
||||
<string name="disappearing_unit_hours">Hours</string>
|
||||
<string name="disappearing_unit_days">Days</string>
|
||||
<string name="disappearing_set">Set</string>
|
||||
<string name="disappears_at">Disappears %1$s</string>
|
||||
<string name="disappearing_timer_description">Messages you send here disappear after %1$s</string>
|
||||
<string name="disappearing_notice">New messages you send here disappear after %1$s.</string>
|
||||
<string name="disappearing_notice_change">Change</string>
|
||||
<string name="disappearing_notice_dismiss">Got it</string>
|
||||
<string name="duration_one_minute">1 minute</string>
|
||||
<string name="duration_minutes">%1$d minutes</string>
|
||||
<string name="duration_one_hour">1 hour</string>
|
||||
<string name="duration_hours">%1$d hours</string>
|
||||
<string name="duration_one_day">1 day</string>
|
||||
<string name="duration_days">%1$d days</string>
|
||||
<string name="duration_one_week">1 week</string>
|
||||
<string name="duration_weeks">%1$d weeks</string>
|
||||
</resources>
|
||||
@@ -46,6 +46,9 @@ abstract class DisappearingDao {
|
||||
@Query("SELECT disappearingNoticeShownAt FROM ChatRoom WHERE id = :chatRoomId")
|
||||
abstract suspend fun noticeShownAt(chatRoomId: String): Instant?
|
||||
|
||||
@Query("SELECT disappearingNoticeShownAt IS NOT NULL FROM ChatRoom WHERE id = :chatRoomId")
|
||||
abstract fun observeNoticeShown(chatRoomId: String): Flow<Boolean?>
|
||||
|
||||
@Query("UPDATE ChatRoom SET disappearingNoticeShownAt = :at WHERE id = :chatRoomId AND disappearingNoticeShownAt IS NULL")
|
||||
abstract suspend fun markNoticeShown(chatRoomId: String, at: Instant): Int
|
||||
|
||||
|
||||
+9
@@ -3,6 +3,7 @@ package mobi.giza.compose.database.repository
|
||||
import com.vitorpamplona.quartz.nip01Core.core.HexKey
|
||||
import com.vitorpamplona.quartz.nip01Core.core.Kind
|
||||
import kotlin.time.Clock
|
||||
import kotlin.time.Instant
|
||||
import kotlinx.coroutines.flow.Flow
|
||||
import kotlinx.coroutines.flow.map
|
||||
import mobi.giza.compose.database.GizaDatabase
|
||||
@@ -36,6 +37,14 @@ class DisappearingSettingsStore(private val database: GizaDatabase) {
|
||||
database.disappearingDao().setRoomOverride(chatRoomId, seconds)
|
||||
}
|
||||
|
||||
/** Whether the one-time notice has been shown in [chatRoomId] (D9); a room not found reads as shown. */
|
||||
fun observeNoticeShown(chatRoomId: String): Flow<Boolean> =
|
||||
database.disappearingDao().observeNoticeShown(chatRoomId).map { it ?: true }
|
||||
|
||||
suspend fun markNoticeShown(chatRoomId: String, at: Instant) {
|
||||
database.disappearingDao().markNoticeShown(chatRoomId, at)
|
||||
}
|
||||
|
||||
/** The policy a message queued now in [chatRoomId] by [userPublicKey] is stamped with. */
|
||||
suspend fun policyFor(chatRoomId: String, userPublicKey: HexKey): Long =
|
||||
DisappearingMessages.policyFor(database.disappearingDao().getRoomOverride(chatRoomId), defaultFor(userPublicKey))
|
||||
|
||||
+26
@@ -1,5 +1,8 @@
|
||||
package mobi.giza.compose.ui.composable
|
||||
|
||||
import mobi.giza.compose.ui.composable.navigation.routes.DisappearingMessagesRoute
|
||||
import mobi.giza.compose.resources.disappearing_messages
|
||||
import androidx.compose.material.icons.filled.HourglassBottom
|
||||
import androidx.compose.foundation.layout.Arrangement
|
||||
import androidx.compose.foundation.layout.Column
|
||||
import androidx.compose.foundation.layout.Row
|
||||
@@ -375,6 +378,29 @@ fun ActiveProfileScreen(
|
||||
}
|
||||
}
|
||||
|
||||
// How long what this profile writes in NIP-17 conversations lasts.
|
||||
// docs/disappearing-messages.md, Phase 6.
|
||||
if (canSign) item {
|
||||
TextButton(
|
||||
onClick = {
|
||||
onNavigateToRoute.invoke(
|
||||
DisappearingMessagesRoute(activeUserPublicKey = activeUserPublicKey)
|
||||
)
|
||||
}
|
||||
) {
|
||||
Icon(
|
||||
Icons.Default.HourglassBottom,
|
||||
contentDescription = Decorative
|
||||
)
|
||||
|
||||
Spacer(
|
||||
modifier = Modifier.width(MaterialTheme.spacing.space125)
|
||||
)
|
||||
|
||||
Text(stringResource(Res.string.disappearing_messages))
|
||||
}
|
||||
}
|
||||
|
||||
item {
|
||||
TextButton(
|
||||
onClick = {
|
||||
|
||||
+24
@@ -1,5 +1,11 @@
|
||||
package mobi.giza.compose.ui.composable
|
||||
|
||||
import mobi.giza.compose.ui.composable.navigation.routes.DisappearingMessagesRoute
|
||||
import mobi.giza.compose.resources.disappearing_messages
|
||||
import mobi.giza.compose.resources.disappearing_messages_room_supporting
|
||||
import androidx.compose.material.icons.filled.HourglassBottom
|
||||
import androidx.compose.foundation.clickable
|
||||
import androidx.compose.material3.minimumInteractiveComponentSize
|
||||
import mobi.giza.compose.ui.composable.widgets.LocalCanSign
|
||||
import mobi.giza.compose.resources.propose_event
|
||||
import mobi.giza.compose.ui.composable.navigation.routes.ProposeGroupEventRoute
|
||||
@@ -598,6 +604,24 @@ fun ChatRoomDetailScreen(
|
||||
}
|
||||
}
|
||||
|
||||
// How long what the user writes here lasts. Local, like muting, and only in
|
||||
// a NIP-17 room: an MLS room follows the group's own retention.
|
||||
// docs/disappearing-messages.md, D4.
|
||||
if (chatRoomDetailUIState.localChatRoom.chatRoom.mlsGroupState == null) item(key = "disappearing") {
|
||||
val room = chatRoomDetailUIState.localChatRoom.chatRoom
|
||||
ListItem(
|
||||
modifier = Modifier.minimumInteractiveComponentSize().clickable {
|
||||
onNavigateToRoute.invoke(DisappearingMessagesRoute(activeUserPublicKey, room.id))
|
||||
},
|
||||
leadingContent = { Icon(Icons.Default.HourglassBottom, contentDescription = Decorative) },
|
||||
headlineContent = { Text(stringResource(Res.string.disappearing_messages)) },
|
||||
// The fixed description, not the current length: this screen reads the
|
||||
// room once, so a length shown here would be stale after a change.
|
||||
supportingContent = { Text(stringResource(Res.string.disappearing_messages_room_supporting)) },
|
||||
trailingContent = { Icon(Icons.Default.ChevronRight, contentDescription = Decorative) },
|
||||
)
|
||||
}
|
||||
|
||||
// Directly under the signing key, because between them
|
||||
// they are what the room *is*: the identity it signs as
|
||||
// and whose child it is. Absent on a group that is
|
||||
|
||||
+19
@@ -1,5 +1,9 @@
|
||||
package mobi.giza.compose.ui.composable
|
||||
|
||||
import androidx.compose.runtime.remember
|
||||
import mobi.giza.compose.GizaRuntime
|
||||
import mobi.giza.compose.database.repository.DisappearingSettingsStore
|
||||
import mobi.giza.compose.ui.composable.navigation.routes.DisappearingMessagesRoute
|
||||
import androidx.compose.foundation.background
|
||||
import androidx.compose.foundation.layout.Arrangement
|
||||
import androidx.compose.foundation.layout.Box
|
||||
@@ -97,6 +101,10 @@ fun ChatRoomMessagingScreen(
|
||||
* phone the same screen is a destination, and the button is what leaves it.
|
||||
*/
|
||||
onNavigateBack: (() -> Unit)?,
|
||||
/** How long what the user writes here lasts (docs/disappearing-messages.md, D12); none in a preview. */
|
||||
disappearingSettings: DisappearingSettingsStore? = remember {
|
||||
GizaRuntime.current()?.let { DisappearingSettingsStore(it.auxDatabaseManager.auxDatabase) }
|
||||
},
|
||||
) {
|
||||
val chatRoomMessagingViewModel: ChatRoomMessagingViewModel = viewModel(
|
||||
factory = ChatRoomMessagingViewModel.factory(
|
||||
@@ -156,6 +164,12 @@ fun ChatRoomMessagingScreen(
|
||||
if (onNavigateBack != null) NavigateBackButton(onNavigateBack)
|
||||
},
|
||||
actions = {
|
||||
// A NIP-17 conversation's timer: an MLS room follows the group's own retention.
|
||||
if (disappearingSettings != null && chatRoomDetailUIState.localChatRoom.chatRoom.mlsGroupState == null) {
|
||||
DisappearingTimerAction(chatRoomId, activeUserPublicKey, disappearingSettings) {
|
||||
onNavigateToRoute.invoke(DisappearingMessagesRoute(activeUserPublicKey, chatRoomId))
|
||||
}
|
||||
}
|
||||
IconButton(
|
||||
onClick = {
|
||||
// Navigate to the invite user screen...
|
||||
@@ -180,6 +194,11 @@ fun ChatRoomMessagingScreen(
|
||||
Column(
|
||||
modifier = Modifier.padding(innerPadding).readableContent().fillMaxSize()
|
||||
) {
|
||||
if (disappearingSettings != null && chatRoomDetailUIState.localChatRoom.chatRoom.mlsGroupState == null) {
|
||||
DisappearingNotice(chatRoomId, activeUserPublicKey, disappearingSettings) {
|
||||
onNavigateToRoute.invoke(DisappearingMessagesRoute(activeUserPublicKey, chatRoomId))
|
||||
}
|
||||
}
|
||||
Column(
|
||||
modifier = Modifier.weight(1f).fillMaxWidth()
|
||||
) {
|
||||
|
||||
+375
@@ -0,0 +1,375 @@
|
||||
package mobi.giza.compose.ui.composable
|
||||
|
||||
import androidx.compose.foundation.layout.Arrangement
|
||||
import androidx.compose.foundation.layout.Column
|
||||
import androidx.compose.foundation.layout.Row
|
||||
import androidx.compose.foundation.layout.fillMaxWidth
|
||||
import androidx.compose.foundation.layout.padding
|
||||
import androidx.compose.foundation.layout.size
|
||||
import androidx.compose.foundation.lazy.LazyColumn
|
||||
import androidx.compose.foundation.selection.selectable
|
||||
import androidx.compose.foundation.selection.selectableGroup
|
||||
import androidx.compose.foundation.text.KeyboardOptions
|
||||
import androidx.compose.material.icons.Icons
|
||||
import androidx.compose.material.icons.filled.HourglassBottom
|
||||
import androidx.compose.material3.AlertDialog
|
||||
import androidx.compose.material3.Card
|
||||
import androidx.compose.material3.ExperimentalMaterial3Api
|
||||
import androidx.compose.material3.Icon
|
||||
import androidx.compose.material3.IconButton
|
||||
import androidx.compose.material3.ListItem
|
||||
import androidx.compose.material3.MaterialTheme
|
||||
import androidx.compose.material3.OutlinedTextField
|
||||
import androidx.compose.material3.RadioButton
|
||||
import androidx.compose.material3.Scaffold
|
||||
import androidx.compose.material3.SegmentedButton
|
||||
import androidx.compose.material3.SegmentedButtonDefaults
|
||||
import androidx.compose.material3.SingleChoiceSegmentedButtonRow
|
||||
import androidx.compose.material3.Text
|
||||
import androidx.compose.material3.TextButton
|
||||
import androidx.compose.material3.TopAppBar
|
||||
import androidx.compose.runtime.Composable
|
||||
import androidx.compose.runtime.collectAsState
|
||||
import androidx.compose.runtime.getValue
|
||||
import androidx.compose.runtime.mutableStateOf
|
||||
import androidx.compose.runtime.remember
|
||||
import androidx.compose.runtime.rememberCoroutineScope
|
||||
import androidx.compose.runtime.setValue
|
||||
import androidx.compose.ui.Modifier
|
||||
import androidx.compose.ui.semantics.Role
|
||||
import androidx.compose.ui.text.input.KeyboardType
|
||||
import androidx.compose.ui.unit.dp
|
||||
import kotlin.time.Clock
|
||||
import kotlin.time.Instant
|
||||
import kotlinx.coroutines.flow.combine
|
||||
import kotlinx.coroutines.flow.map
|
||||
import kotlinx.coroutines.launch
|
||||
import mobi.giza.compose.database.repository.DisappearingSettingsStore
|
||||
import mobi.giza.compose.extensions.toFormattedTimeAndDateString
|
||||
import mobi.giza.compose.nostr.DisappearingMessages
|
||||
import mobi.giza.compose.resources.Res
|
||||
import mobi.giza.compose.resources.cancel
|
||||
import mobi.giza.compose.resources.disappearing_custom
|
||||
import mobi.giza.compose.resources.disappearing_custom_amount
|
||||
import mobi.giza.compose.resources.disappearing_custom_out_of_range
|
||||
import mobi.giza.compose.resources.disappearing_custom_title
|
||||
import mobi.giza.compose.resources.disappearing_default_value
|
||||
import mobi.giza.compose.resources.disappearing_explanation
|
||||
import mobi.giza.compose.resources.disappearing_groups_note
|
||||
import mobi.giza.compose.resources.disappearing_messages
|
||||
import mobi.giza.compose.resources.disappearing_notice
|
||||
import mobi.giza.compose.resources.disappearing_notice_change
|
||||
import mobi.giza.compose.resources.disappearing_notice_dismiss
|
||||
import mobi.giza.compose.resources.disappearing_off
|
||||
import mobi.giza.compose.resources.disappearing_offline_warning
|
||||
import mobi.giza.compose.resources.disappearing_protocol_note
|
||||
import mobi.giza.compose.resources.disappearing_saved
|
||||
import mobi.giza.compose.resources.disappearing_set
|
||||
import mobi.giza.compose.resources.disappearing_timer_description
|
||||
import mobi.giza.compose.resources.disappearing_unit_days
|
||||
import mobi.giza.compose.resources.disappearing_unit_hours
|
||||
import mobi.giza.compose.resources.disappearing_unit_minutes
|
||||
import mobi.giza.compose.resources.disappearing_use_default
|
||||
import mobi.giza.compose.resources.disappears_at
|
||||
import mobi.giza.compose.resources.duration_days
|
||||
import mobi.giza.compose.resources.duration_hours
|
||||
import mobi.giza.compose.resources.duration_minutes
|
||||
import mobi.giza.compose.resources.duration_one_day
|
||||
import mobi.giza.compose.resources.duration_one_hour
|
||||
import mobi.giza.compose.resources.duration_one_minute
|
||||
import mobi.giza.compose.resources.duration_one_week
|
||||
import mobi.giza.compose.resources.duration_weeks
|
||||
import mobi.giza.compose.ui.composable.widgets.Decorative
|
||||
import mobi.giza.compose.ui.composable.widgets.LoadingDataIndicator
|
||||
import mobi.giza.compose.ui.composable.widgets.NavigateBackButton
|
||||
import mobi.giza.compose.ui.composable.widgets.ScreenStateTransition
|
||||
import mobi.giza.compose.ui.composable.widgets.rememberNotifier
|
||||
import mobi.giza.compose.ui.theme.readableContent
|
||||
import mobi.giza.compose.ui.theme.spacing
|
||||
import org.jetbrains.compose.resources.getString
|
||||
import org.jetbrains.compose.resources.stringResource
|
||||
|
||||
/**
|
||||
* A length as a person reads it: the largest unit that divides it exactly, so a preset reads
|
||||
* "1 week" and a custom ninety minutes reads "90 minutes". Off is "Off".
|
||||
*/
|
||||
@Composable
|
||||
fun disappearingLengthText(seconds: Long): String {
|
||||
val (unit, count) = DisappearingLength.split(seconds) ?: return stringResource(Res.string.disappearing_off)
|
||||
return when (unit) {
|
||||
DisappearingLength.Unit.WEEKS -> if (count == 1L) stringResource(Res.string.duration_one_week) else stringResource(Res.string.duration_weeks, count)
|
||||
DisappearingLength.Unit.DAYS -> if (count == 1L) stringResource(Res.string.duration_one_day) else stringResource(Res.string.duration_days, count)
|
||||
DisappearingLength.Unit.HOURS -> if (count == 1L) stringResource(Res.string.duration_one_hour) else stringResource(Res.string.duration_hours, count)
|
||||
DisappearingLength.Unit.MINUTES -> if (count == 1L) stringResource(Res.string.duration_one_minute) else stringResource(Res.string.duration_minutes, count)
|
||||
}
|
||||
}
|
||||
|
||||
/** The arithmetic under [disappearingLengthText] and the custom dialog, kept out of composition so it can be tested. */
|
||||
object DisappearingLength {
|
||||
enum class Unit(val seconds: Long) {
|
||||
MINUTES(DisappearingMessages.MINUTE),
|
||||
HOURS(DisappearingMessages.HOUR),
|
||||
DAYS(DisappearingMessages.DAY),
|
||||
WEEKS(7 * DisappearingMessages.DAY),
|
||||
}
|
||||
|
||||
/** The largest unit [seconds] is a whole number of, and how many; null for Off. */
|
||||
fun split(seconds: Long): Pair<Unit, Long>? {
|
||||
if (seconds <= 0) return null
|
||||
val unit = Unit.entries.reversed().firstOrNull { seconds % it.seconds == 0L } ?: Unit.MINUTES
|
||||
return unit to seconds / unit.seconds
|
||||
}
|
||||
|
||||
/** A custom length from what was typed, or null when it is not a whole number in bounds. */
|
||||
fun parse(amount: String, unit: Unit): Long? {
|
||||
val count = amount.trim().toLongOrNull() ?: return null
|
||||
if (count <= 0 || count > DisappearingMessages.MAX_SECONDS / unit.seconds) return null
|
||||
return (count * unit.seconds).takeIf { DisappearingMessages.isValidPolicy(it) }
|
||||
}
|
||||
}
|
||||
|
||||
private sealed interface DisappearingUIState {
|
||||
data object Loading : DisappearingUIState
|
||||
|
||||
/** [selected] is null when a conversation follows the default; [default] is the identity's. */
|
||||
data class Loaded(val selected: Long?, val default: Long) : DisappearingUIState
|
||||
}
|
||||
|
||||
/**
|
||||
* How long what the user writes lasts: their default, or with [chatRoomId] one conversation's
|
||||
* override, which may also go back to following the default. docs/disappearing-messages.md, D3,
|
||||
* D4, D7 and D11.
|
||||
*
|
||||
* No error or empty state: the value is one row of the local database with a default when absent,
|
||||
* and a read that fails there has failed for every screen in the app.
|
||||
*/
|
||||
@OptIn(ExperimentalMaterial3Api::class)
|
||||
@Composable
|
||||
fun DisappearingMessagesScreen(
|
||||
activeUserPublicKey: String,
|
||||
chatRoomId: String?,
|
||||
store: DisappearingSettingsStore,
|
||||
onNavigateBack: () -> Unit,
|
||||
) {
|
||||
val state by remember(activeUserPublicKey, chatRoomId) {
|
||||
if (chatRoomId == null) {
|
||||
store.observeDefault(activeUserPublicKey).map { default -> DisappearingUIState.Loaded(default, default) }
|
||||
} else {
|
||||
combine(store.observeOverride(chatRoomId), store.observeDefault(activeUserPublicKey)) { override, default ->
|
||||
DisappearingUIState.Loaded(override, default)
|
||||
}
|
||||
}
|
||||
}.collectAsState(initial = DisappearingUIState.Loading)
|
||||
|
||||
val scope = rememberCoroutineScope()
|
||||
val notify = rememberNotifier(scope)
|
||||
var customOpen by remember { mutableStateOf(false) }
|
||||
|
||||
fun save(seconds: Long?, label: String) {
|
||||
scope.launch {
|
||||
if (chatRoomId == null) store.saveDefault(activeUserPublicKey, seconds ?: DisappearingMessages.DEFAULT_SECONDS)
|
||||
else store.saveOverride(chatRoomId, seconds)
|
||||
notify(getString(Res.string.disappearing_saved, label))
|
||||
}
|
||||
}
|
||||
|
||||
Scaffold(
|
||||
topBar = {
|
||||
TopAppBar(
|
||||
title = { Text(stringResource(Res.string.disappearing_messages)) },
|
||||
navigationIcon = { NavigateBackButton(onNavigateBack) },
|
||||
)
|
||||
},
|
||||
) { innerPadding ->
|
||||
Column(modifier = Modifier.padding(innerPadding).readableContent()) {
|
||||
ScreenStateTransition(state) { uiState ->
|
||||
when (uiState) {
|
||||
DisappearingUIState.Loading -> LoadingDataIndicator()
|
||||
is DisappearingUIState.Loaded -> {
|
||||
val defaultLabel = disappearingLengthText(uiState.default)
|
||||
val isCustom = uiState.selected != null && uiState.selected !in DisappearingMessages.PRESETS
|
||||
LazyColumn(modifier = Modifier.selectableGroup()) {
|
||||
if (chatRoomId != null) item {
|
||||
val label = stringResource(Res.string.disappearing_use_default, defaultLabel)
|
||||
ChoiceRow(label, selected = uiState.selected == null) { save(null, defaultLabel) }
|
||||
}
|
||||
DisappearingMessages.PRESETS.forEach { preset ->
|
||||
item(key = preset) {
|
||||
val label = disappearingLengthText(preset)
|
||||
ChoiceRow(label, selected = uiState.selected == preset) { save(preset, label) }
|
||||
}
|
||||
}
|
||||
item {
|
||||
ChoiceRow(
|
||||
label = stringResource(Res.string.disappearing_custom),
|
||||
selected = isCustom,
|
||||
supporting = if (isCustom) disappearingLengthText(uiState.selected!!) else null,
|
||||
) { customOpen = true }
|
||||
}
|
||||
item {
|
||||
Column(
|
||||
modifier = Modifier.padding(MaterialTheme.spacing.screenMargin),
|
||||
verticalArrangement = Arrangement.spacedBy(MaterialTheme.spacing.itemGap),
|
||||
) {
|
||||
Explanation(stringResource(Res.string.disappearing_explanation))
|
||||
Explanation(stringResource(Res.string.disappearing_offline_warning))
|
||||
Explanation(stringResource(Res.string.disappearing_protocol_note))
|
||||
Explanation(stringResource(Res.string.disappearing_groups_note))
|
||||
}
|
||||
}
|
||||
}
|
||||
if (customOpen) {
|
||||
CustomLengthDialog(
|
||||
initial = uiState.selected?.takeIf { isCustom },
|
||||
onDismiss = { customOpen = false },
|
||||
onSet = { seconds, label ->
|
||||
customOpen = false
|
||||
save(seconds, label)
|
||||
},
|
||||
)
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@Composable
|
||||
private fun Explanation(text: String) = Text(
|
||||
text = text,
|
||||
style = MaterialTheme.typography.bodyMedium,
|
||||
color = MaterialTheme.colorScheme.onSurfaceVariant,
|
||||
)
|
||||
|
||||
/** A radio row chosen from anywhere on it: the row is the target, at the list item's height. */
|
||||
@Composable
|
||||
private fun ChoiceRow(label: String, selected: Boolean, supporting: String? = null, onSelect: () -> Unit) {
|
||||
ListItem(
|
||||
modifier = Modifier.selectable(selected = selected, role = Role.RadioButton, onClick = onSelect),
|
||||
leadingContent = { RadioButton(selected = selected, onClick = null) },
|
||||
headlineContent = { Text(label) },
|
||||
supportingContent = supporting?.let { { Text(it) } },
|
||||
)
|
||||
}
|
||||
|
||||
@OptIn(ExperimentalMaterial3Api::class)
|
||||
@Composable
|
||||
private fun CustomLengthDialog(initial: Long?, onDismiss: () -> Unit, onSet: (Long, String) -> Unit) {
|
||||
val start = initial?.let { DisappearingLength.split(it) }
|
||||
?.let { (unit, count) -> if (unit == DisappearingLength.Unit.WEEKS) DisappearingLength.Unit.DAYS to count * 7 else unit to count }
|
||||
var amount by remember { mutableStateOf(start?.second?.toString() ?: "") }
|
||||
var unit by remember { mutableStateOf(start?.first ?: DisappearingLength.Unit.HOURS) }
|
||||
val parsed = DisappearingLength.parse(amount, unit)
|
||||
val showError = amount.isNotBlank() && parsed == null
|
||||
val label = parsed?.let { disappearingLengthText(it) }
|
||||
val units = listOf(
|
||||
DisappearingLength.Unit.MINUTES to stringResource(Res.string.disappearing_unit_minutes),
|
||||
DisappearingLength.Unit.HOURS to stringResource(Res.string.disappearing_unit_hours),
|
||||
DisappearingLength.Unit.DAYS to stringResource(Res.string.disappearing_unit_days),
|
||||
)
|
||||
|
||||
AlertDialog(
|
||||
onDismissRequest = onDismiss,
|
||||
title = { Text(stringResource(Res.string.disappearing_custom_title)) },
|
||||
text = {
|
||||
Column(verticalArrangement = Arrangement.spacedBy(MaterialTheme.spacing.itemGap)) {
|
||||
OutlinedTextField(
|
||||
value = amount,
|
||||
onValueChange = { amount = it.filter(Char::isDigit).take(6) },
|
||||
label = { Text(stringResource(Res.string.disappearing_custom_amount)) },
|
||||
singleLine = true,
|
||||
isError = showError,
|
||||
supportingText = { if (showError) Text(stringResource(Res.string.disappearing_custom_out_of_range)) },
|
||||
keyboardOptions = KeyboardOptions(keyboardType = KeyboardType.Number),
|
||||
modifier = Modifier.fillMaxWidth(),
|
||||
)
|
||||
SingleChoiceSegmentedButtonRow(modifier = Modifier.fillMaxWidth()) {
|
||||
units.forEachIndexed { index, (option, text) ->
|
||||
SegmentedButton(
|
||||
selected = unit == option,
|
||||
onClick = { unit = option },
|
||||
shape = SegmentedButtonDefaults.itemShape(index, units.size),
|
||||
) { Text(text) }
|
||||
}
|
||||
}
|
||||
}
|
||||
},
|
||||
confirmButton = {
|
||||
TextButton(onClick = { if (parsed != null && label != null) onSet(parsed, label) }, enabled = parsed != null) {
|
||||
Text(stringResource(Res.string.disappearing_set))
|
||||
}
|
||||
},
|
||||
dismissButton = {
|
||||
TextButton(onClick = onDismiss) { Text(stringResource(Res.string.cancel)) }
|
||||
},
|
||||
)
|
||||
}
|
||||
|
||||
/**
|
||||
* The hourglass beside an expiring line's time. Its description carries what the icon shows and
|
||||
* the text beside it does not: when the line goes (D12).
|
||||
*/
|
||||
@Composable
|
||||
fun DisappearsIcon(expiresAt: Instant) {
|
||||
Icon(
|
||||
Icons.Default.HourglassBottom,
|
||||
contentDescription = stringResource(Res.string.disappears_at, expiresAt.toFormattedTimeAndDateString()),
|
||||
modifier = Modifier.size(MaterialTheme.typography.labelSmall.lineHeight.value.dp),
|
||||
tint = MaterialTheme.colorScheme.onSurfaceVariant,
|
||||
)
|
||||
}
|
||||
|
||||
/**
|
||||
* The conversation's timer in its app bar (D12), opening its setting; nothing while the policy in
|
||||
* force is Off.
|
||||
*/
|
||||
@Composable
|
||||
fun DisappearingTimerAction(chatRoomId: String, userPublicKey: String, store: DisappearingSettingsStore, onOpen: () -> Unit) {
|
||||
val policy by remember(chatRoomId, userPublicKey) {
|
||||
combine(store.observeOverride(chatRoomId), store.observeDefault(userPublicKey)) { override, default ->
|
||||
DisappearingMessages.policyFor(override, default)
|
||||
}
|
||||
}.collectAsState(initial = DisappearingMessages.OFF)
|
||||
if (policy == DisappearingMessages.OFF) return
|
||||
IconButton(onClick = onOpen) {
|
||||
Icon(
|
||||
Icons.Default.HourglassBottom,
|
||||
contentDescription = stringResource(Res.string.disappearing_timer_description, disappearingLengthText(policy)),
|
||||
)
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* The one-time notice that what the user writes in this conversation now disappears (D9). Shown
|
||||
* until dismissed or acted on, once per conversation, and only while a policy is in force.
|
||||
*/
|
||||
@Composable
|
||||
fun DisappearingNotice(chatRoomId: String, userPublicKey: String, store: DisappearingSettingsStore, onChange: () -> Unit) {
|
||||
val scope = rememberCoroutineScope()
|
||||
val shown by remember(chatRoomId) { store.observeNoticeShown(chatRoomId) }.collectAsState(initial = true)
|
||||
val policy by remember(chatRoomId, userPublicKey) {
|
||||
combine(store.observeOverride(chatRoomId), store.observeDefault(userPublicKey)) { override, default ->
|
||||
DisappearingMessages.policyFor(override, default)
|
||||
}
|
||||
}.collectAsState(initial = DisappearingMessages.OFF)
|
||||
if (shown || policy == DisappearingMessages.OFF) return
|
||||
|
||||
fun dismiss() = scope.launch { store.markNoticeShown(chatRoomId, Clock.System.now()) }
|
||||
|
||||
Card(modifier = Modifier.fillMaxWidth().padding(MaterialTheme.spacing.compactPadding)) {
|
||||
Column(
|
||||
modifier = Modifier.padding(MaterialTheme.spacing.containerPadding),
|
||||
verticalArrangement = Arrangement.spacedBy(MaterialTheme.spacing.relatedGap),
|
||||
) {
|
||||
Row(horizontalArrangement = Arrangement.spacedBy(MaterialTheme.spacing.relatedGap)) {
|
||||
Icon(Icons.Default.HourglassBottom, contentDescription = Decorative)
|
||||
Text(stringResource(Res.string.disappearing_notice, disappearingLengthText(policy)))
|
||||
}
|
||||
Row(modifier = Modifier.fillMaxWidth(), horizontalArrangement = Arrangement.End) {
|
||||
TextButton(onClick = { dismiss(); onChange() }) { Text(stringResource(Res.string.disappearing_notice_change)) }
|
||||
TextButton(onClick = { dismiss() }) { Text(stringResource(Res.string.disappearing_notice_dismiss)) }
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
+12
@@ -1,5 +1,8 @@
|
||||
package mobi.giza.compose.ui.composable.navigation
|
||||
|
||||
import mobi.giza.compose.ui.composable.navigation.routes.DisappearingMessagesRoute
|
||||
import mobi.giza.compose.ui.composable.DisappearingMessagesScreen
|
||||
import mobi.giza.compose.database.repository.DisappearingSettingsStore
|
||||
import mobi.giza.compose.ui.composable.navigation.routes.ProposeGroupEventRoute
|
||||
import mobi.giza.compose.ui.composable.ProposeGroupEventScreen
|
||||
import mobi.giza.compose.ui.composable.navigation.routes.BroadcastGroupSignedEventRoute
|
||||
@@ -928,6 +931,15 @@ fun GizaNavHost(
|
||||
onNavigateBack = { navController.popBackStack() },
|
||||
)
|
||||
}
|
||||
composable<DisappearingMessagesRoute> { backStackEntry ->
|
||||
val route = backStackEntry.toRoute<DisappearingMessagesRoute>()
|
||||
DisappearingMessagesScreen(
|
||||
activeUserPublicKey = route.activeUserPublicKey,
|
||||
chatRoomId = route.chatRoomId,
|
||||
store = remember(runtime) { DisappearingSettingsStore(runtime.auxDatabaseManager.auxDatabase) },
|
||||
onNavigateBack = { navController.popBackStack() },
|
||||
)
|
||||
}
|
||||
composable<KeyRecoveryRoute> { backStackEntry ->
|
||||
val route = backStackEntry.toRoute<KeyRecoveryRoute>()
|
||||
|
||||
|
||||
+13
@@ -0,0 +1,13 @@
|
||||
package mobi.giza.compose.ui.composable.navigation.routes
|
||||
|
||||
import kotlinx.serialization.Serializable
|
||||
|
||||
/**
|
||||
* How long what the user writes lasts: their default when [chatRoomId] is null, else that
|
||||
* conversation's override. docs/disappearing-messages.md, Phase 6.
|
||||
*/
|
||||
@Serializable
|
||||
data class DisappearingMessagesRoute(
|
||||
val activeUserPublicKey: String,
|
||||
val chatRoomId: String? = null,
|
||||
): Route()
|
||||
+2
@@ -1,5 +1,6 @@
|
||||
package mobi.giza.compose.ui.composable.widgets.chat
|
||||
|
||||
import mobi.giza.compose.ui.composable.DisappearsIcon
|
||||
import androidx.compose.material.icons.filled.Warning
|
||||
import androidx.compose.foundation.clickable
|
||||
import androidx.compose.foundation.layout.Arrangement
|
||||
@@ -521,6 +522,7 @@ fun ChatTranscript(
|
||||
text = localChatMessage.chatMessage.createdAt.toFormattedTimeAndDateString(),
|
||||
style = MaterialTheme.typography.labelSmall
|
||||
)
|
||||
localChatMessage.chatMessage.expiresAt?.let { DisappearsIcon(it) }
|
||||
if (localChatMessage.chatMessage.isUserMessage) {
|
||||
if (localChatMessage.chatMessageBroadcastNostrEventReceiptRelation != null) {
|
||||
Icon(
|
||||
|
||||
Reference in new issue
Block a user