Skip to content

Commit

Permalink
waitThenMaybeUpdateGroup: If group is blocked, don't fetch
Browse files Browse the repository at this point in the history
Co-authored-by: Scott Nonnenberg <scott@signal.org>
  • Loading branch information
automated-signal and scottnonnenberg-signal committed Jul 16, 2021
1 parent d808ffb commit 82f55ab
Showing 1 changed file with 11 additions and 4 deletions.
15 changes: 11 additions & 4 deletions ts/groups.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2680,14 +2680,20 @@ export async function waitThenMaybeUpdateGroup(
options: MaybeUpdatePropsType,
{ viaSync = false } = {}
): Promise<void> {
const { conversation } = options;

if (conversation.isBlocked()) {
window.log.info(
`waitThenMaybeUpdateGroup: Group ${conversation.idForLogging()} is blocked, returning early`
);
return;
}

// First wait to process all incoming messages on the websocket
await window.waitForEmptyEventQueue();

// Then wait to process all outstanding messages for this conversation
const { conversation } = options;

// Then make sure we haven't fetched this group too recently
const { lastSuccessfulGroupFetch = 0 } = conversation;

if (isMoreRecentThan(lastSuccessfulGroupFetch, FIVE_MINUTES)) {
const waitTime = lastSuccessfulGroupFetch + FIVE_MINUTES - Date.now();
window.log.info(
Expand All @@ -2697,6 +2703,7 @@ export async function waitThenMaybeUpdateGroup(
return;
}

// Then wait to process all outstanding messages for this conversation
await conversation.queueJob('waitThenMaybeUpdateGroup', async () => {
try {
// And finally try to update the group
Expand Down

0 comments on commit 82f55ab

Please sign in to comment.