From 8216717b73cf7ce840b19a78cb71ece5bc2d8392 Mon Sep 17 00:00:00 2001 From: Kalle <38327916+Sendouc@users.noreply.github.com> Date: Thu, 14 Dec 2023 21:13:34 +0200 Subject: [PATCH] Fix public note getting cleared on group morph Closes #1603 --- .../sendouq/queries/morphGroups.server.ts | 18 +++++++++++------- 1 file changed, 11 insertions(+), 7 deletions(-) diff --git a/app/features/sendouq/queries/morphGroups.server.ts b/app/features/sendouq/queries/morphGroups.server.ts index a66dd444a..03b49eb81 100644 --- a/app/features/sendouq/queries/morphGroups.server.ts +++ b/app/features/sendouq/queries/morphGroups.server.ts @@ -15,9 +15,12 @@ const deleteGroupStm = sql.prepare(/* sql */ ` where "Group"."id" = @groupId `); -const addGroupMemberStm = sql.prepare(/* sql */ ` - insert into "GroupMember" ("groupId", "userId", "role") - values (@groupId, @userId, @role) +const updateGroupMemberStm = sql.prepare(/* sql */ ` + update "GroupMember" + set "role" = @role, + "groupId" = @newGroupId + where "groupId" = @oldGroupId + and "userId" = @userId `); const updateGroupStm = sql.prepare(/* sql */ ` @@ -40,8 +43,6 @@ export const morphGroups = sql.transaction( .all({ groupId: otherGroupId }) .map((row: any) => row.userId) as Array; - deleteGroupStm.run({ groupId: otherGroupId }); - deleteLikesByGroupId(survivingGroupId); // reset chat code so previous messages are not visible @@ -56,11 +57,14 @@ export const morphGroups = sql.transaction( ) ? "MANAGER" : "REGULAR"; - addGroupMemberStm.run({ - groupId: survivingGroupId, + updateGroupMemberStm.run({ + newGroupId: survivingGroupId, + oldGroupId: otherGroupId, userId, role, }); } + + deleteGroupStm.run({ groupId: otherGroupId }); }, );