Skip to content

Commit fe3a09b

Browse files
Robclaude
andcommitted
fix(telegram): migrate legacy chat template to include {status_emoji}
Existing Telegram (and VK) destinations had the old default template ("{value} {unit} {trend_arrow} {time}") stored in SharedPreferences. resolvedTemplate() returns the stored value when non-empty, so the new {status_emoji} token was never applied to existing destinations. Auto-migrate on load: if the stored template exactly matches the legacy default, replace it with the current default which prepends {status_emoji}. Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
1 parent b6c5193 commit fe3a09b

1 file changed

Lines changed: 9 additions & 1 deletion

File tree

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

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -65,6 +65,8 @@ object OutboundApiSettings {
6565
"{value} {unit} {trend_arrow} RAW:{raw} ({rate_mgdl} mg/dL/min) IOB:{iob} COB:{cob} {time}"
6666
const val DEFAULT_CHAT_TEMPLATE =
6767
"{status_emoji} {value} {unit} {trend_arrow} {time}"
68+
// Old default before status tokens were added — used to migrate stored templates on load.
69+
private const val LEGACY_CHAT_TEMPLATE = "{value} {unit} {trend_arrow} {time}"
6870
const val DEFAULT_GLUCO_WATCH_TEMPLATE =
6971
"GV:{mmol}|RAW:{raw}|TR:{trend_arrow}|AL:{alarm}|RT:{rate_mmol}|IOB:{iob}|COB:{cob}|TS:{timestamp}"
7072

@@ -575,7 +577,13 @@ object OutboundApiSettings {
575577
apiVersion = item.optString("apiVersion", DEFAULT_VK_API_VERSION)
576578
.ifBlank { DEFAULT_VK_API_VERSION },
577579
headers = item.optString("headers", ""),
578-
messageTemplate = item.optString("messageTemplate", defaultTemplate(preset)),
580+
messageTemplate = run {
581+
val stored = item.optString("messageTemplate", defaultTemplate(preset))
582+
// Migrate the old default (pre-status-emoji) to the current default.
583+
if (stored == LEGACY_CHAT_TEMPLATE &&
584+
(preset == PRESET_TELEGRAM_BOT || preset == PRESET_VK_MESSAGES)
585+
) DEFAULT_CHAT_TEMPLATE else stored
586+
},
579587
minIntervalMinutes = item.optInt(
580588
"minIntervalMinutes",
581589
DEFAULT_MIN_INTERVAL_MINUTES

0 commit comments

Comments
 (0)