diff --git a/ts/groups.ts b/ts/groups.ts index 0e0c283149..8a14c092e8 100644 --- a/ts/groups.ts +++ b/ts/groups.ts @@ -3510,7 +3510,7 @@ async function appendChangeMessages( // We updated the message, but didn't add new ones - refresh left pane if (!newMessages && mergedMessages.length > 0) { await conversation.updateLastMessage(); - void conversation.updateUnread(); + conversation.throttledUpdateUnread(); } } diff --git a/ts/messages/saveAndNotify.ts b/ts/messages/saveAndNotify.ts index b5892434fd..3facf8cc27 100644 --- a/ts/messages/saveAndNotify.ts +++ b/ts/messages/saveAndNotify.ts @@ -87,9 +87,7 @@ export async function saveAndNotify( confirm(); if (!isStory(message.attributes)) { - drop( - conversation.queueJob('updateUnread', () => conversation.updateUnread()) - ); + conversation.throttledUpdateUnread(); } } finally { resolve(); diff --git a/ts/models/conversations.ts b/ts/models/conversations.ts index d979b2468b..b9bd639101 100644 --- a/ts/models/conversations.ts +++ b/ts/models/conversations.ts @@ -287,6 +287,8 @@ export class ConversationModel extends window.Backbone throttledUpdateVerified?: () => void; + throttledUpdateUnread: () => void; + typingRefreshTimer?: NodeJS.Timeout | null; typingPauseTimer?: NodeJS.Timeout | null; @@ -442,6 +444,7 @@ export class ConversationModel extends window.Backbone this.isFetchingUUID = this.isSMSOnly(); this.throttledBumpTyping = throttle(this.bumpTyping, 300); + this.throttledUpdateUnread = throttle(this.#updateUnread, 300); this.throttledUpdateSharedGroups = throttle( this.updateSharedGroups.bind(this), FIVE_MINUTES @@ -3146,7 +3149,7 @@ export class ConversationModel extends window.Backbone window.MessageCache.register(message); drop(this.onNewMessage(message)); - drop(this.updateUnread()); + this.throttledUpdateUnread(); } async addDeliveryIssue({ @@ -3190,7 +3193,7 @@ export class ConversationModel extends window.Backbone window.MessageCache.register(message); drop(this.onNewMessage(message)); - drop(this.updateUnread()); + this.throttledUpdateUnread(); await this.notify(message.attributes); } @@ -3373,7 +3376,7 @@ export class ConversationModel extends window.Backbone window.MessageCache.register(message); drop(this.onNewMessage(message)); - drop(this.updateUnread()); + this.throttledUpdateUnread(); const serviceId = this.getServiceId(); if (isDirectConversation(this.attributes) && serviceId) { @@ -4801,7 +4804,7 @@ export class ConversationModel extends window.Backbone window.MessageCache.register(message); void this.addSingleMessage(message.attributes); - void this.updateUnread(); + this.throttledUpdateUnread(); log.info( `${logId}: added a notification received_at=${message.get('received_at')}` @@ -4836,11 +4839,11 @@ export class ConversationModel extends window.Backbone } ): Promise { await markConversationRead(this.attributes, newestUnreadAt, options); - await this.updateUnread(); + this.throttledUpdateUnread(); window.reduxActions.callHistory.updateCallHistoryUnreadCount(); } - async updateUnread(): Promise { + async #updateUnread(): Promise { const options = { storyId: undefined, includeStoryReplies: !isGroup(this.attributes), diff --git a/ts/services/releaseNotesFetcher.ts b/ts/services/releaseNotesFetcher.ts index 4de5e37430..66d5cec414 100644 --- a/ts/services/releaseNotesFetcher.ts +++ b/ts/services/releaseNotesFetcher.ts @@ -337,7 +337,7 @@ export class ReleaseNotesFetcher { ); signalConversation.set({ active_at: Date.now(), isArchived: false }); - drop(signalConversation.updateUnread()); + signalConversation.throttledUpdateUnread(); log.info( `ReleaseNotesFetcher: Updating version watermark to ${versionWatermark}` diff --git a/ts/state/ducks/callHistory.ts b/ts/state/ducks/callHistory.ts index 8cb159047a..75c9cbbd0a 100644 --- a/ts/state/ducks/callHistory.ts +++ b/ts/state/ducks/callHistory.ts @@ -21,7 +21,6 @@ import { } from '../../types/CallDisposition'; import * as log from '../../logging/log'; import * as Errors from '../../types/errors'; -import { drop } from '../../util/drop'; import { getCallHistoryLatestCall, getCallHistorySelector, @@ -129,7 +128,9 @@ function markCallHistoryRead( return async dispatch => { try { await DataWriter.markCallHistoryRead(callId); - drop(window.ConversationController.get(conversationId)?.updateUnread()); + window.ConversationController.get( + conversationId + )?.throttledUpdateUnread(); } catch (error) { log.error( 'markCallHistoryRead: Error marking call history read', diff --git a/ts/state/ducks/conversations.ts b/ts/state/ducks/conversations.ts index ba4eb827c6..92d9c46f51 100644 --- a/ts/state/ducks/conversations.ts +++ b/ts/state/ducks/conversations.ts @@ -4767,7 +4767,7 @@ function onConversationOpened( Promise.all([ conversation.loadNewestMessages(undefined, undefined), conversation.updateLastMessage(), - conversation.updateUnread(), + conversation.throttledUpdateUnread(), ]) ); };