Update conversation.unreadCount in just one place, from database

This commit is contained in:
Scott Nonnenberg 2022-05-03 13:24:31 -07:00 committed by GitHub
parent a9c788b689
commit d4e0f6a38d
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
3 changed files with 12 additions and 6 deletions

View file

@ -4644,10 +4644,16 @@ export class ConversationModel extends window.Backbone
} }
): Promise<void> { ): Promise<void> {
await markConversationRead(this.attributes, newestUnreadAt, options); await markConversationRead(this.attributes, newestUnreadAt, options);
await this.updateUnread();
}
async updateUnread(): Promise<void> {
const unreadCount = await window.Signal.Data.getTotalUnreadForConversation( const unreadCount = await window.Signal.Data.getTotalUnreadForConversation(
this.id, this.id,
{ storyId: undefined, isGroup: isGroup(this.attributes) } {
storyId: undefined,
isGroup: isGroup(this.attributes),
}
); );
const prevUnreadCount = this.get('unreadCount'); const prevUnreadCount = this.get('unreadCount');

View file

@ -2647,6 +2647,8 @@ export class MessageModel extends window.Backbone.Model<MessageAttributesType> {
window.Whisper.events.trigger('incrementProgress'); window.Whisper.events.trigger('incrementProgress');
confirm(); confirm();
conversation.queueJob('updateUnread', () => conversation.updateUnread());
} }
// This function is called twice - once from handleDataMessage, and then again from // This function is called twice - once from handleDataMessage, and then again from
@ -2776,7 +2778,6 @@ export class MessageModel extends window.Backbone.Model<MessageAttributesType> {
); );
} else if (isFirstRun && !isGroupStoryReply) { } else if (isFirstRun && !isGroupStoryReply) {
conversation.set({ conversation.set({
unreadCount: (conversation.get('unreadCount') || 0) + 1,
isArchived: false, isArchived: false,
}); });
} }

View file

@ -22,7 +22,7 @@ import {
import { Address } from '../types/Address'; import { Address } from '../types/Address';
import { QualifiedAddress } from '../types/QualifiedAddress'; import { QualifiedAddress } from '../types/QualifiedAddress';
import { UUID } from '../types/UUID'; import { UUID } from '../types/UUID';
import { isEnabled } from '../RemoteConfig'; import { getValue, isEnabled } from '../RemoteConfig';
import { isRecord } from './isRecord'; import { isRecord } from './isRecord';
import { isOlderThan } from './timestamp'; import { isOlderThan } from './timestamp';
@ -55,7 +55,6 @@ import {
multiRecipient410ResponseSchema, multiRecipient410ResponseSchema,
} from '../textsecure/WebAPI'; } from '../textsecure/WebAPI';
import { SignalService as Proto } from '../protobuf'; import { SignalService as Proto } from '../protobuf';
import * as RemoteConfig from '../RemoteConfig';
import { strictAssert } from './assert'; import { strictAssert } from './assert';
import * as log from '../logging/log'; import * as log from '../logging/log';
@ -169,8 +168,8 @@ export async function sendContentMessageToGroup({
if ( if (
isEnabled('desktop.sendSenderKey3') && isEnabled('desktop.sendSenderKey3') &&
isEnabled('desktop.senderKey.send') &&
ourConversation?.get('capabilities')?.senderKey && ourConversation?.get('capabilities')?.senderKey &&
RemoteConfig.isEnabled('desktop.senderKey.send') &&
sendTarget.isValid() sendTarget.isValid()
) { ) {
try { try {
@ -681,7 +680,7 @@ const MAX_SENDER_KEY_EXPIRE_DURATION = 90 * DAY;
function getSenderKeyExpireDuration(): number { function getSenderKeyExpireDuration(): number {
try { try {
const parsed = parseIntOrThrow( const parsed = parseIntOrThrow(
window.Signal.RemoteConfig.getValue('desktop.senderKeyMaxAge'), getValue('desktop.senderKeyMaxAge'),
'getSenderKeyExpireDuration' 'getSenderKeyExpireDuration'
); );