fix legacy thread name writes

This commit is contained in:
anais
2026-06-23 15:35:34 -07:00
parent 24d662c41f
commit 2eada6a0f2
2 changed files with 16 additions and 2 deletions

View File

@@ -15,3 +15,14 @@ WHERE title <> ''
UPDATE threads
SET title_snapshot = title
WHERE name_state = 'legacy_unknown';
CREATE TRIGGER threads_title_snapshot_after_insert
AFTER INSERT ON threads
WHEN NEW.title_snapshot = ''
AND NEW.title <> ''
AND NEW.title_state = 'legacy_unknown'
BEGIN
UPDATE threads
SET title_snapshot = NEW.title
WHERE id = NEW.id;
END;

View File

@@ -946,13 +946,16 @@ ON CONFLICT(id) DO UPDATE SET
cli_version = excluded.cli_version,
name = CASE
WHEN threads.title <> threads.title_snapshot THEN NULLIF(threads.title, '')
WHEN threads.name_state <> 'legacy_unknown' THEN threads.name
WHEN excluded.name_state = 'explicit' THEN excluded.name
WHEN excluded.name_state = 'cleared' THEN NULL
WHEN threads.name_state IN ('explicit', 'cleared') THEN threads.name
WHEN excluded.name_state = 'legacy_unknown' THEN NULL
ELSE excluded.name
END,
name_state = CASE
WHEN threads.title <> threads.title_snapshot THEN CASE WHEN threads.title = '' THEN 'cleared' ELSE 'explicit' END
WHEN threads.name_state <> 'legacy_unknown' THEN threads.name_state
WHEN excluded.name_state IN ('explicit', 'cleared') THEN excluded.name_state
WHEN threads.name_state IN ('explicit', 'cleared') THEN threads.name_state
WHEN excluded.name_state = 'legacy_unknown' THEN 'unnamed'
ELSE excluded.name_state
END,