The triage pair: snooze, and "remind me if no reply"
Two halves of the same problem — a conversation you are not ready for, and one you are waiting on — and both are local to this device on purpose. "I am ignoring this person until Tuesday" and "remind me if they have not answered" are statements about a relationship, and the relay has no business holding either. The honest cost is that neither follows you to a new phone; the alternative is handing a server the list of people you are avoiding. 🔴 **A reply arriving cancels the reminder, and it happens in `Session.record`** — the one place every inbound message passes through. Hanging it off a screen or a poll handler means the one path that forgot to call it produces a reminder that fires after they answered, and that is the single thing that would teach people to ignore reminders. The service fires due reminders from its existing loop, deliberately AFTER `receive()`: a reply that has just landed cancels its own reminder before it can go off. Checking first would nudge about a conversation answered a moment ago. Cleared as it fires, too — a reminder is one-shot, and leaving the row would re-notify every half second for ever. ⚠️ Snoozes are recomputed, never cached as a flag. A snooze expires by the clock passing and nothing runs at that moment, so a stored boolean leaves a conversation muted past its own deadline. ⚠️ Same privacy rule as message notifications: a count, never a name. Who you are waiting on is as sensitive as what they said. engine 163, client 96, app 35. Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
This commit is contained in:
co-authored by
Claude Opus 4.8
parent
020eba2228
commit
3f0dfd669c
@@ -1377,6 +1377,8 @@ fun ColumnScope.ChatScreen(
|
||||
// for is one they will not rely on.
|
||||
if (chat.peerId != null) DisappearingPanel(model, chat)
|
||||
|
||||
if (chat.peerId != null) AttentionPanel(model, chat)
|
||||
|
||||
LazyColumn(
|
||||
state = listState,
|
||||
modifier = Modifier.fillMaxWidth().weight(1f).testTag("messages"),
|
||||
@@ -2731,3 +2733,92 @@ private fun ColumnScope.MediaQualitySection() {
|
||||
color = Palette.SecondaryText,
|
||||
)
|
||||
}
|
||||
|
||||
/**
|
||||
* Snooze, and "remind me if no reply", for one conversation.
|
||||
*
|
||||
* 🔴 **Both are local to this device and always will be.** "I am ignoring this
|
||||
* person until Tuesday" and "remind me if they have not answered" are
|
||||
* statements about a relationship, and the relay has no business holding
|
||||
* either. The honest cost is that neither follows you to a new phone — the
|
||||
* alternative is handing a server the list of people you are avoiding.
|
||||
*/
|
||||
@Composable
|
||||
private fun ColumnScope.AttentionPanel(
|
||||
model: MessengerViewModel,
|
||||
chat: MessengerViewModel.Phase.Chat,
|
||||
) {
|
||||
val peerId = chat.peerId ?: return
|
||||
val snoozed = chat.threadId in (model.phase.value as? MessengerViewModel.Phase.SignedIn)
|
||||
?.snoozedThreads.orEmpty()
|
||||
|
||||
Column(modifier = Modifier.fillMaxWidth().padding(vertical = Space.sm)) {
|
||||
Text("Snooze this chat", style = MaterialTheme.typography.titleSmall)
|
||||
Row(
|
||||
modifier = Modifier.fillMaxWidth().padding(top = Space.xs),
|
||||
horizontalArrangement = Arrangement.spacedBy(Space.xs),
|
||||
) {
|
||||
SNOOZE_CHOICES.forEach { (label, seconds) ->
|
||||
KitChip(
|
||||
text = label,
|
||||
selected = seconds == 0 && !snoozed,
|
||||
onClick = { model.snooze(peerId, seconds) },
|
||||
tag = "snooze-$seconds",
|
||||
)
|
||||
}
|
||||
}
|
||||
Text(
|
||||
if (snoozed) {
|
||||
"Snoozed. Messages still arrive — this chat just stops asking " +
|
||||
"for your attention until it wakes."
|
||||
} else {
|
||||
"Snoozing stops this chat notifying you for a while. Nothing is " +
|
||||
"blocked and nothing is lost."
|
||||
},
|
||||
style = MaterialTheme.typography.bodySmall,
|
||||
modifier = Modifier.padding(top = Space.xs),
|
||||
)
|
||||
|
||||
Spacer(Modifier.height(Space.sm))
|
||||
Text("Remind me if no reply", style = MaterialTheme.typography.titleSmall)
|
||||
Row(
|
||||
modifier = Modifier.fillMaxWidth().padding(top = Space.xs),
|
||||
horizontalArrangement = Arrangement.spacedBy(Space.xs),
|
||||
) {
|
||||
REMINDER_CHOICES.forEach { (label, seconds) ->
|
||||
KitChip(
|
||||
text = label,
|
||||
selected = (seconds == 0) == (chat.replyReminderAt == 0L),
|
||||
onClick = { model.setReplyReminder(peerId, seconds) },
|
||||
tag = "remind-$seconds",
|
||||
)
|
||||
}
|
||||
}
|
||||
Text(
|
||||
if (chat.replyReminderAt == 0L) {
|
||||
"Nothing set. A reminder nudges you if this chat goes unanswered."
|
||||
} else {
|
||||
// ⚠️ Says the cancellation rule out loud. A reminder that fired
|
||||
// after they answered would teach people to ignore reminders,
|
||||
// so the fact that it will not is worth stating.
|
||||
"Set. It is cancelled automatically the moment they reply."
|
||||
},
|
||||
style = MaterialTheme.typography.bodySmall,
|
||||
modifier = Modifier.padding(top = Space.xs),
|
||||
)
|
||||
}
|
||||
}
|
||||
|
||||
private val SNOOZE_CHOICES = listOf(
|
||||
"Off" to 0,
|
||||
"1 hour" to 3_600,
|
||||
"8 hours" to 28_800,
|
||||
"1 day" to 86_400,
|
||||
)
|
||||
|
||||
private val REMINDER_CHOICES = listOf(
|
||||
"Off" to 0,
|
||||
"1 hour" to 3_600,
|
||||
"3 hours" to 10_800,
|
||||
"Tomorrow" to 86_400,
|
||||
)
|
||||
|
||||
@@ -183,6 +183,13 @@ class MessengerService : Service() {
|
||||
while (true) {
|
||||
val touched = runCatching { s.receive() }.getOrDefault(emptySet())
|
||||
if (touched.isNotEmpty()) notifyMessages(touched.size)
|
||||
// 🔴 Reply reminders fire from THIS loop, after `receive()`, and
|
||||
// the order matters: an inbound message clears the reminder inside
|
||||
// `Session.record`, so a reply that has just landed cancels its own
|
||||
// reminder before it can go off. Checking first would fire a
|
||||
// reminder for a conversation that was answered a moment ago —
|
||||
// which is the one thing that would teach people to ignore them.
|
||||
fireDueReplyReminders(s)
|
||||
// ⚠️ A short gap, not a poll interval: `receive()` is held open by
|
||||
// the relay for WAIT_SECONDS, so this only paces a relay that
|
||||
// answers immediately.
|
||||
@@ -222,6 +229,26 @@ class MessengerService : Service() {
|
||||
number = threads)
|
||||
}
|
||||
|
||||
/**
|
||||
* Notify about conversations nobody answered, and forget them.
|
||||
*
|
||||
* ⚠️ Cleared as it fires. A reminder is a one-shot: leaving the row would
|
||||
* re-notify on the next cycle, half a second later, for ever.
|
||||
*/
|
||||
private fun fireDueReplyReminders(s: Session) {
|
||||
val due = runCatching { s.dueReplyReminders() }.getOrDefault(emptyMap())
|
||||
if (due.isEmpty()) return
|
||||
due.keys.forEach { threadId -> runCatching { s.vault.saveReplyReminder(threadId, 0L) } }
|
||||
val open = PendingIntent.getActivity(
|
||||
this, 4, Intent(this, MainActivity::class.java),
|
||||
PendingIntent.FLAG_IMMUTABLE or PendingIntent.FLAG_UPDATE_CURRENT)
|
||||
// Same privacy rule as a message notification: a count, never a name.
|
||||
// Who you are waiting on is as sensitive as what they said.
|
||||
val text = if (due.size == 1) "Still no reply"
|
||||
else "Still no reply in ${due.size} chats"
|
||||
notify(CHANNEL_MESSAGES, 5, text, NotificationCompat.PRIORITY_DEFAULT, open)
|
||||
}
|
||||
|
||||
private fun notifyCall(from: String) {
|
||||
val open = PendingIntent.getActivity(
|
||||
this, 2, Intent(this, MainActivity::class.java),
|
||||
|
||||
@@ -82,6 +82,15 @@ class MessengerViewModel(app: Application) : AndroidViewModel(app) {
|
||||
* groups invisible on iOS for far longer.
|
||||
*/
|
||||
val buddiesLoaded: Boolean = false,
|
||||
/**
|
||||
* Thread ids currently snoozed.
|
||||
*
|
||||
* ⚠️ Recomputed rather than stored as a flag: a snooze expires by
|
||||
* the clock passing, and nothing runs at that moment. A cached
|
||||
* boolean would leave a conversation muted until something happened
|
||||
* to refresh it.
|
||||
*/
|
||||
val snoozedThreads: Set<String> = emptySet(),
|
||||
|
||||
/** Same question for the group list. See [buddiesLoaded]. */
|
||||
val groupsLoaded: Boolean = false,
|
||||
@@ -214,6 +223,8 @@ class MessengerViewModel(app: Application) : AndroidViewModel(app) {
|
||||
* not a preference.
|
||||
*/
|
||||
val disappearSeconds: Int = 0,
|
||||
/** When a reply reminder is set for this thread, epoch millis; 0 = none. */
|
||||
val replyReminderAt: Long = 0,
|
||||
)
|
||||
|
||||
/**
|
||||
@@ -497,6 +508,10 @@ class MessengerViewModel(app: Application) : AndroidViewModel(app) {
|
||||
|
||||
fun refreshBuddies() = viewModelScope.launch {
|
||||
val current = session ?: return@launch
|
||||
// Snoozes expire by the clock passing and nothing runs at that moment,
|
||||
// so the set is recomputed whenever the list is drawn rather than
|
||||
// cached — a stale flag leaves a conversation muted past its deadline.
|
||||
refreshSnoozed()
|
||||
val fetched = withContext(Dispatchers.IO) {
|
||||
runCatching { current.roster() }
|
||||
// Pin each contact's global address the first time we see them.
|
||||
@@ -563,6 +578,7 @@ class MessengerViewModel(app: Application) : AndroidViewModel(app) {
|
||||
trust = current.conversations.trust.state(peerId),
|
||||
safetyNumber = current.conversations.trust.safetyNumber(peerId),
|
||||
disappearSeconds = current.conversations.disappearSeconds(peerId),
|
||||
replyReminderAt = current.replyReminder(peerId),
|
||||
),
|
||||
// Opening the thread is what marks it read. Nothing is sent to
|
||||
// the relay for this — read state is local, because a read
|
||||
@@ -802,6 +818,43 @@ class MessengerViewModel(app: Application) : AndroidViewModel(app) {
|
||||
}
|
||||
}
|
||||
|
||||
// -- Attention management: snooze and reply reminders ---------------------
|
||||
|
||||
/**
|
||||
* Snooze a conversation for [seconds]; 0 wakes it now.
|
||||
*
|
||||
* ⚠️ Local to this device, deliberately. "I am ignoring this person until
|
||||
* Tuesday" is a statement about a relationship, and the relay has no
|
||||
* business holding it — the cost is that a snooze does not follow you to a
|
||||
* new device, which is the better half of that trade.
|
||||
*/
|
||||
fun snooze(peerId: Long, seconds: Int) = viewModelScope.launch {
|
||||
val current = session ?: return@launch
|
||||
val until = if (seconds <= 0) 0L else System.currentTimeMillis() + seconds * 1000L
|
||||
withContext(Dispatchers.IO) { current.snooze(peerId, until) }
|
||||
refreshSnoozed()
|
||||
}
|
||||
|
||||
/** Recompute which threads are snoozed right now. */
|
||||
fun refreshSnoozed() {
|
||||
val current = session ?: return
|
||||
update { it.copy(snoozedThreads = current.snoozedThreads()) }
|
||||
}
|
||||
|
||||
/**
|
||||
* Ask to be reminded if this conversation goes unanswered for [seconds].
|
||||
*
|
||||
* 🔴 The reminder is cancelled by a reply ARRIVING, in `Session.record`,
|
||||
* not merely by firing. One that still goes off after they answered teaches
|
||||
* people to ignore reminders.
|
||||
*/
|
||||
fun setReplyReminder(peerId: Long, seconds: Int) = viewModelScope.launch {
|
||||
val current = session ?: return@launch
|
||||
val at = if (seconds <= 0) 0L else System.currentTimeMillis() + seconds * 1000L
|
||||
withContext(Dispatchers.IO) { current.setReplyReminder(peerId, at) }
|
||||
update { it.copy(openChat = it.openChat?.copy(replyReminderAt = at)) }
|
||||
}
|
||||
|
||||
// -- Disappearing messages (§6.11) ---------------------------------------
|
||||
|
||||
/**
|
||||
|
||||
@@ -126,11 +126,51 @@ class Session(
|
||||
}
|
||||
}
|
||||
.also { if (attachment != null) it.put("kind", attachment.kind).put("att", attachment.toJson()) })
|
||||
|
||||
// 🔴 A reply arriving cancels the reminder, and it is done HERE because
|
||||
// this is the one place every inbound message passes through. Hanging it
|
||||
// off a screen or a poll handler means the one path that forgot to call
|
||||
// it produces a reminder that fires after they answered — which teaches
|
||||
// people to ignore reminders, and is worse than not having them.
|
||||
if (!mine) clearReplyReminderOnInbound(threadId)
|
||||
}
|
||||
|
||||
/** Clear a thread. Keeps the session, so the conversation still works. */
|
||||
fun clearHistory(threadId: String) = vault.forgetHistory(threadId)
|
||||
|
||||
// -- Attention management -------------------------------------------------
|
||||
|
||||
/** Snooze a conversation until [until] (epoch millis); 0 clears it. */
|
||||
fun snooze(peerId: Long, until: Long) =
|
||||
vault.saveSnoozedUntil(Vault.threadForUser(peerId), until)
|
||||
|
||||
fun snoozedUntil(peerId: Long): Long = vault.snoozedUntil(Vault.threadForUser(peerId))
|
||||
|
||||
/** Thread ids still snoozed at [now]. */
|
||||
fun snoozedThreads(now: Long = System.currentTimeMillis()): Set<String> =
|
||||
vault.snoozedThreads(now)
|
||||
|
||||
/**
|
||||
* Ask to be reminded about this conversation if nobody replies by [at].
|
||||
*
|
||||
* 🔴 **Cancelled by a reply arriving**, not only by firing — see
|
||||
* [clearReplyReminderOnInbound]. A reminder that still goes off after they
|
||||
* answered is worse than none: it teaches people to ignore it.
|
||||
*/
|
||||
fun setReplyReminder(peerId: Long, at: Long) =
|
||||
vault.saveReplyReminder(Vault.threadForUser(peerId), at)
|
||||
|
||||
fun replyReminder(peerId: Long): Long = vault.replyReminder(Vault.threadForUser(peerId))
|
||||
|
||||
/** Drop any pending reminder for a thread that has just heard back. */
|
||||
fun clearReplyReminderOnInbound(threadId: String) {
|
||||
if (vault.replyReminder(threadId) != 0L) vault.saveReplyReminder(threadId, 0L)
|
||||
}
|
||||
|
||||
/** Reminders that have come due at [now]. */
|
||||
fun dueReplyReminders(now: Long = System.currentTimeMillis()): Map<String, Long> =
|
||||
vault.dueReplyReminders(now)
|
||||
|
||||
/** Delete one message from this device (delete for me). */
|
||||
fun deleteMessage(threadId: String, at: Long, mine: Boolean, text: String) =
|
||||
vault.deleteLine(threadId, at, mine, text)
|
||||
|
||||
Reference in New Issue
Block a user