From 3d0abbe3546eabc8a6fd0709ee5b05c36e6cbc46 Mon Sep 17 00:00:00 2001 From: automated-signal <37887102+automated-signal@users.noreply.github.com> Date: Wed, 23 Feb 2022 12:25:50 -0800 Subject: [PATCH] updateGroup: Update group attributes last, after notifications are added Co-authored-by: Scott Nonnenberg --- ts/groups.ts | 27 +++++++++++++++------------ 1 file changed, 15 insertions(+), 12 deletions(-) diff --git a/ts/groups.ts b/ts/groups.ts index dfc691549..9b736288c 100644 --- a/ts/groups.ts +++ b/ts/groups.ts @@ -2842,18 +2842,6 @@ async function updateGroup( activeAt = newAttributes.active_at; } - conversation.set({ - ...newAttributes, - active_at: activeAt, - temporaryMemberCount: isInGroup - ? undefined - : newAttributes.temporaryMemberCount, - }); - - if (idChanged) { - conversation.trigger('idUpdated', conversation, 'groupId', previousId); - } - // Save all synthetic messages describing group changes let syntheticSentAt = initialSentAt - (groupChangeMessages.length + 1); const changeMessagesToSave = groupChangeMessages.map(changeMessage => { @@ -2915,6 +2903,21 @@ async function updateGroup( }); } + // We update group membership last to ensure that all notifications are in place before + // the group updates happen on the model. + + conversation.set({ + ...newAttributes, + active_at: activeAt, + temporaryMemberCount: isInGroup + ? undefined + : newAttributes.temporaryMemberCount, + }); + + if (idChanged) { + conversation.trigger('idUpdated', conversation, 'groupId', previousId); + } + // No need for convo.updateLastMessage(), 'newmessage' handler does that }