From e8d16349ae2ecc513f991cc76509a97474de16ce Mon Sep 17 00:00:00 2001 From: spaced4ndy <8711996+spaced4ndy@users.noreply.github.com> Date: Mon, 20 Apr 2026 13:28:01 +0000 Subject: [PATCH] core: fix changing profile of prepared chats losing chat items (#6843) --- src/Simplex/Chat/Store/Direct.hs | 8 ++++++++ src/Simplex/Chat/Store/Groups.hs | 8 ++++++++ .../Store/SQLite/Migrations/chat_query_plans.txt | 16 ++++++++++++++++ 3 files changed, 32 insertions(+) diff --git a/src/Simplex/Chat/Store/Direct.hs b/src/Simplex/Chat/Store/Direct.hs index 9128404244..60f898e52e 100644 --- a/src/Simplex/Chat/Store/Direct.hs +++ b/src/Simplex/Chat/Store/Direct.hs @@ -429,6 +429,14 @@ updatePreparedContactUser WHERE contact_profile_id = ? |] (newUserId, currentTs, profileId) + DB.execute + db + [sql| + UPDATE chat_items + SET user_id = ?, updated_at = ? + WHERE contact_id = ? + |] + (newUserId, currentTs, contactId) safeDeleteLDN db user oldLDN getContact db vr newUser contactId diff --git a/src/Simplex/Chat/Store/Groups.hs b/src/Simplex/Chat/Store/Groups.hs index 93fdf1868a..c4e7210637 100644 --- a/src/Simplex/Chat/Store/Groups.hs +++ b/src/Simplex/Chat/Store/Groups.hs @@ -687,6 +687,14 @@ updatePreparedGroupUser db vr user gInfo@GroupInfo {groupId, membership} hostMem WHERE group_profile_id IN (SELECT group_profile_id FROM groups WHERE group_id = ?) |] (newUserId, currentTs, groupId) + DB.execute + db + [sql| + UPDATE chat_items + SET user_id = ?, updated_at = ? + WHERE group_id = ? + |] + (newUserId, currentTs, groupId) safeDeleteLDN db user oldGroupLDN updateMembership GroupMember {groupMemberId = membershipId} currentTs = DB.execute diff --git a/src/Simplex/Chat/Store/SQLite/Migrations/chat_query_plans.txt b/src/Simplex/Chat/Store/SQLite/Migrations/chat_query_plans.txt index 82ca68a663..366074acc2 100644 --- a/src/Simplex/Chat/Store/SQLite/Migrations/chat_query_plans.txt +++ b/src/Simplex/Chat/Store/SQLite/Migrations/chat_query_plans.txt @@ -446,6 +446,14 @@ Query: Plan: SEARCH chat_items USING INTEGER PRIMARY KEY (rowid=?) +Query: + UPDATE chat_items + SET user_id = ?, updated_at = ? + WHERE group_id = ? + +Plan: +SEARCH chat_items USING COVERING INDEX idx_chat_items_group_id (group_id=?) + Query: UPDATE contact_profiles SET display_name = ?, @@ -1063,6 +1071,14 @@ SEARCH m USING INTEGER PRIMARY KEY (rowid=?) LEFT-JOIN SEARCH g USING INTEGER PRIMARY KEY (rowid=?) LEFT-JOIN SEARCH h USING INDEX idx_sent_probe_hashes_sent_probe_id (sent_probe_id=?) +Query: + UPDATE chat_items + SET user_id = ?, updated_at = ? + WHERE contact_id = ? + +Plan: +SEARCH chat_items USING COVERING INDEX idx_chat_items_contact_id (contact_id=?) + Query: UPDATE chat_items SET item_status = ?, item_viewed = 1, updated_at = ? WHERE user_id = ? AND group_id = ? AND item_status = ? AND chat_item_id = ?