Skip to content

Commit a1f77b0

Browse files
Robclaude
andcommitted
fix(telegram): update stale clock on suppressed readings
When a reading was suppressed (bubble text unchanged), recordBubbleSent and TelegramStaleCheckWork.schedule were both skipped. For flat glucose — where every consecutive reading is within suppressDeltaBelowMgdl — this caused false ⚠️ Stale and ⚪ Missed alerts even while readings arrived normally. Add recordReadingArrived() which bumps only lastSentAtMsByRecipient, leaving the message ID and lastSentMgdl unchanged so the suppression delta is still computed from the last-sent value. Call it from the suppressed path and move the stale reschedule outside the suppression guard so it fires on every successful response. Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
1 parent 439dc87 commit a1f77b0

2 files changed

Lines changed: 35 additions & 9 deletions

File tree

Common/src/main/java/tk/glucodata/OutboundApi.kt

Lines changed: 20 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -657,23 +657,34 @@ class OutboundApiWorker(
657657
val response = send(context, destination, reading)
658658
if (response.ok) {
659659
OutboundApiSettings.recordSuccess(context, destination.id, response.code)
660+
val nowMs = System.currentTimeMillis()
660661
if (!response.suppressed) {
661662
OutboundApiSettings.recordBubbleSent(
662663
context = context.applicationContext,
663664
destinationId = destination.id,
664665
recipient = reading.recipient,
665666
messageId = response.messageId,
666-
sentAtMs = System.currentTimeMillis(),
667+
sentAtMs = nowMs,
667668
mgdl = reading.mgdl
668669
)
669-
if (destination.normalizedPreset() == OutboundApiSettings.PRESET_TELEGRAM_BOT) {
670-
TelegramStaleCheckWork.schedule(
671-
context = context.applicationContext,
672-
destinationId = destination.id,
673-
delayMs = (destination.staleThresholdMinutes.coerceIn(1, 120) * 60_000L) +
674-
OutboundApiSettings.STALE_CHECK_SLACK_MS
675-
)
676-
}
670+
} else {
671+
// Reading arrived but bubble text was unchanged — still update the
672+
// "last received" timestamp so the stale timer doesn't fire during
673+
// a flat-glucose stretch where every reading is suppressed.
674+
OutboundApiSettings.recordReadingArrived(
675+
context = context.applicationContext,
676+
destinationId = destination.id,
677+
recipient = reading.recipient,
678+
arrivedAtMs = nowMs
679+
)
680+
}
681+
if (destination.normalizedPreset() == OutboundApiSettings.PRESET_TELEGRAM_BOT) {
682+
TelegramStaleCheckWork.schedule(
683+
context = context.applicationContext,
684+
destinationId = destination.id,
685+
delayMs = (destination.staleThresholdMinutes.coerceIn(1, 120) * 60_000L) +
686+
OutboundApiSettings.STALE_CHECK_SLACK_MS
687+
)
677688
}
678689
Result.success()
679690
} else {

Common/src/main/java/tk/glucodata/OutboundApiSettings.kt

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -367,6 +367,21 @@ object OutboundApiSettings {
367367
}
368368
}
369369

370+
fun recordReadingArrived(
371+
context: Context,
372+
destinationId: String,
373+
recipient: String,
374+
arrivedAtMs: Long
375+
) {
376+
updateDestination(context, destinationId) { dest ->
377+
// Only update the timestamp; leave messageId and lastSentMgdl unchanged
378+
// so suppression delta is still computed from the last-sent value.
379+
dest.copy(
380+
lastSentAtMsByRecipient = dest.lastSentAtMsByRecipient + (recipient to arrivedAtMs)
381+
)
382+
}
383+
}
384+
370385
fun recordBubbleSent(
371386
context: Context,
372387
destinationId: String,

0 commit comments

Comments
 (0)