Avoid race condition of group updates overwriting unread counts

This commit is contained in:
trevor-signal 2024-10-02 16:59:33 -04:00 committed by GitHub
parent 6fc62f29cb
commit da947ddf44
No known key found for this signature in database
GPG key ID: B5690EEEBB952194

View file

@ -7,6 +7,7 @@ import {
flatten,
fromPairs,
isNumber,
omit,
values,
} from 'lodash';
import Long from 'long';
@ -3111,6 +3112,19 @@ export async function maybeUpdateGroup(
}
}
/**
* UpdateGroup runs on the conversation's queue, and it overwrites all of conversation
* attributes. This would be fine, except we have some time-sensitive conversation-related
* tasks that happen off-queue, notably: updateUnread(). This is a non-exhaustive list of
* attributes that should never be stomped by updateGroup. Attributes should be added here
* if:
* 1) [most importantly!] they will never be updated by updateGroup, and
* 2) they are updated off-queue and therefore at risk of being stomped on.
*
* TODO (DESKTOP-7729): consider better separating conversation data to avoid this
*/
const FIELDS_UNRELATED_TO_GROUP_STATE = ['unreadCount', 'unreadMentionsOfMe'];
async function updateGroup(
{
conversation,
@ -3262,7 +3276,7 @@ async function updateGroup(
}
conversation.set({
...newAttributes,
...omit(newAttributes, FIELDS_UNRELATED_TO_GROUP_STATE),
active_at: activeAt,
});