Skip to content

Commit 962a0aa

Browse files
authored
Merge pull request #46 from robster7674/review/ai-destination-migration-cleanup
refactor(settings): decodeDestinations cleanup — deduplicate staleThreshold, simplify migration predicate, align settingsVersion
2 parents 17f8932 + 20565b9 commit 962a0aa

1 file changed

Lines changed: 6 additions & 11 deletions

File tree

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

Lines changed: 6 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -585,6 +585,8 @@ object OutboundApiSettings {
585585
val item = array.optJSONObject(index) ?: continue
586586
val preset = normalizePreset(item.optString("preset", PRESET_CUSTOM_JSON))
587587
val itemSettingsVersion = item.optInt("settingsVersion", 0)
588+
val staleThreshold = item.optInt("staleThresholdMinutes", DEFAULT_STALE_THRESHOLD_MINUTES)
589+
.coerceIn(1, 120)
588590
destinations += Destination(
589591
id = item.optString("id").ifBlank { UUID.randomUUID().toString() },
590592
enabled = item.optBoolean("enabled", false),
@@ -624,7 +626,7 @@ object OutboundApiSettings {
624626
// since Telegram doesn't notify on edited messages. Force false on first
625627
// migration. Once settingsVersion is saved as 1+, user's explicit choices
626628
// are preserved.
627-
if (itemSettingsVersion < 1 && stored) false else stored
629+
stored && itemSettingsVersion >= 1
628630
},
629631
refreshWindowMinutes = item.optInt(
630632
"refreshWindowMinutes",
@@ -638,23 +640,16 @@ object OutboundApiSettings {
638640
DEFAULT_SUPPRESS_DELTA_BELOW_MGDL
639641
).coerceIn(0, 100),
640642
staleEnabled = item.optBoolean("staleEnabled", DEFAULT_STALE_ENABLED),
641-
staleThresholdMinutes = item.optInt(
642-
"staleThresholdMinutes",
643-
DEFAULT_STALE_THRESHOLD_MINUTES
644-
).coerceIn(1, 120),
643+
staleThresholdMinutes = staleThreshold,
645644
missedThresholdMinutes = item.optInt(
646645
"missedThresholdMinutes",
647646
DEFAULT_MISSED_THRESHOLD_MINUTES
648-
).coerceIn(
649-
item.optInt("staleThresholdMinutes", DEFAULT_STALE_THRESHOLD_MINUTES)
650-
.coerceIn(1, 120) + 1,
651-
240
652-
),
647+
).coerceIn(staleThreshold + 1, 240),
653648
lastMessageIdByRecipient = decodeLongMap(item.optJSONObject("lastMessageIdByRecipient")),
654649
lastSentAtMsByRecipient = decodeLongMap(item.optJSONObject("lastSentAtMsByRecipient")),
655650
lastSentMgdlByRecipient = decodeIntMap(item.optJSONObject("lastSentMgdlByRecipient")),
656651
lastStaleAtMsByRecipient = decodeLongMap(item.optJSONObject("lastStaleAtMsByRecipient")),
657-
settingsVersion = itemSettingsVersion
652+
settingsVersion = maxOf(1, itemSettingsVersion)
658653
)
659654
}
660655
return destinations.distinctBy { it.id.lowercase(Locale.US) }

0 commit comments

Comments
 (0)