From d4e0f6a38d2d72ad679154491732c25485838553 Mon Sep 17 00:00:00 2001 From: Scott Nonnenberg Date: Tue, 3 May 2022 13:24:31 -0700 Subject: [PATCH] Update conversation.unreadCount in just one place, from database --- ts/models/conversations.ts | 8 +++++++- ts/models/messages.ts | 3 ++- ts/util/sendToGroup.ts | 7 +++---- 3 files changed, 12 insertions(+), 6 deletions(-) diff --git a/ts/models/conversations.ts b/ts/models/conversations.ts index 1b95db1d8b2..6afcc647460 100644 --- a/ts/models/conversations.ts +++ b/ts/models/conversations.ts @@ -4644,10 +4644,16 @@ export class ConversationModel extends window.Backbone } ): Promise { await markConversationRead(this.attributes, newestUnreadAt, options); + await this.updateUnread(); + } + async updateUnread(): Promise { const unreadCount = await window.Signal.Data.getTotalUnreadForConversation( this.id, - { storyId: undefined, isGroup: isGroup(this.attributes) } + { + storyId: undefined, + isGroup: isGroup(this.attributes), + } ); const prevUnreadCount = this.get('unreadCount'); diff --git a/ts/models/messages.ts b/ts/models/messages.ts index 54b26bbba0f..0b79be443c2 100644 --- a/ts/models/messages.ts +++ b/ts/models/messages.ts @@ -2647,6 +2647,8 @@ export class MessageModel extends window.Backbone.Model { window.Whisper.events.trigger('incrementProgress'); confirm(); + + conversation.queueJob('updateUnread', () => conversation.updateUnread()); } // This function is called twice - once from handleDataMessage, and then again from @@ -2776,7 +2778,6 @@ export class MessageModel extends window.Backbone.Model { ); } else if (isFirstRun && !isGroupStoryReply) { conversation.set({ - unreadCount: (conversation.get('unreadCount') || 0) + 1, isArchived: false, }); } diff --git a/ts/util/sendToGroup.ts b/ts/util/sendToGroup.ts index 5ac6b7ba564..c164858da4c 100644 --- a/ts/util/sendToGroup.ts +++ b/ts/util/sendToGroup.ts @@ -22,7 +22,7 @@ import { import { Address } from '../types/Address'; import { QualifiedAddress } from '../types/QualifiedAddress'; import { UUID } from '../types/UUID'; -import { isEnabled } from '../RemoteConfig'; +import { getValue, isEnabled } from '../RemoteConfig'; import { isRecord } from './isRecord'; import { isOlderThan } from './timestamp'; @@ -55,7 +55,6 @@ import { multiRecipient410ResponseSchema, } from '../textsecure/WebAPI'; import { SignalService as Proto } from '../protobuf'; -import * as RemoteConfig from '../RemoteConfig'; import { strictAssert } from './assert'; import * as log from '../logging/log'; @@ -169,8 +168,8 @@ export async function sendContentMessageToGroup({ if ( isEnabled('desktop.sendSenderKey3') && + isEnabled('desktop.senderKey.send') && ourConversation?.get('capabilities')?.senderKey && - RemoteConfig.isEnabled('desktop.senderKey.send') && sendTarget.isValid() ) { try { @@ -681,7 +680,7 @@ const MAX_SENDER_KEY_EXPIRE_DURATION = 90 * DAY; function getSenderKeyExpireDuration(): number { try { const parsed = parseIntOrThrow( - window.Signal.RemoteConfig.getValue('desktop.senderKeyMaxAge'), + getValue('desktop.senderKeyMaxAge'), 'getSenderKeyExpireDuration' );