From fae56cb2a838fddd81557169e3301bbe803f0d5d Mon Sep 17 00:00:00 2001 From: kutesir Date: Mon, 15 Jun 2026 12:59:48 +0300 Subject: [PATCH] Matrix: backfill legacy task priorities so birthdays place correctly (KC-21) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit The Priority defaults only fired at creation, so tasks saved before Priority existed (e.g. birthdays) all had `.none` and fell to the Matrix bottom row instead of Q2. Added a one-time, flag-guarded migration on load that applies the KisaniCal category defaults (birthday/domain/annual/exam/subscription → High, workout → Medium) to existing `.none`-priority tasks. Co-Authored-By: Claude Opus 4.8 --- KisaniCal/Models/TaskItem.swift | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) diff --git a/KisaniCal/Models/TaskItem.swift b/KisaniCal/Models/TaskItem.swift index 3a13603..4fa208b 100644 --- a/KisaniCal/Models/TaskItem.swift +++ b/KisaniCal/Models/TaskItem.swift @@ -152,6 +152,22 @@ class TaskViewModel: ObservableObject { } else { tasks = [] } + migrateCategoryPrioritiesIfNeeded() + } + + /// One-time backfill: tasks created before Priority existed all have `.none`. + /// Apply the KisaniCal category defaults (birthdays → High, etc.) so the Matrix + /// places legacy birthdays/renewals in the top row like newly-created ones. + private func migrateCategoryPrioritiesIfNeeded() { + let flag = "kisani.migration.categoryPriority.v1" + guard !UserDefaults.kisani.bool(forKey: flag) else { return } + var changed = false + for idx in tasks.indices where tasks[idx].priority == .none { + let def = defaultPriority(category: tasks[idx].category, title: tasks[idx].title) + if def != .none { tasks[idx].priority = def; changed = true } + } + UserDefaults.kisani.set(true, forKey: flag) + if changed { save() } } func reload() {