Fix "mark conversation read" optimization

This commit is contained in:
Evan Hahn 2022-01-31 15:52:09 -06:00 committed by GitHub
parent 397753bbfe
commit c5ad020de7
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 8 additions and 32 deletions

View File

@ -213,9 +213,6 @@ export class ConversationModel extends window.Backbone
private isInReduxBatch = false;
// This number is recorded as an optimization and may be out of date.
private newestReceivedAtMarkedRead?: number;
private _activeProfileFetch?: Promise<void>;
override defaults(): Partial<ConversationAttributesType> {
@ -4582,15 +4579,6 @@ export class ConversationModel extends window.Backbone
sendReadReceipts: true,
}
): Promise<void> {
// This early return is an optimization, not a guarantee.
const { newestReceivedAtMarkedRead } = this;
if (
typeof newestReceivedAtMarkedRead === 'number' &&
newestUnreadAt <= newestReceivedAtMarkedRead
) {
return;
}
await markConversationRead(this.attributes, newestUnreadAt, options);
const unreadCount = await window.Signal.Data.getTotalUnreadForConversation(
@ -4602,8 +4590,6 @@ export class ConversationModel extends window.Backbone
this.set({ unreadCount });
window.Signal.Data.updateConversation(this.attributes);
}
this.newestReceivedAtMarkedRead = newestUnreadAt;
}
// This is an expensive operation we use to populate the message request hero row. It

View File

@ -29,6 +29,7 @@ import type {
MessageAttributesType as MediaItemMessageType,
} from '../types/MediaItem';
import type { MessageModel } from '../models/messages';
import { getMessageById } from '../messages/getMessageById';
import { getContactId } from '../messages/helpers';
import { strictAssert } from '../util/assert';
import { maybeParseUrl } from '../util/url';
@ -137,7 +138,7 @@ const {
upgradeMessageSchema,
} = window.Signal.Migrations;
const { getMessageById, getMessagesBySentAt } = window.Signal.Data;
const { getMessagesBySentAt } = window.Signal.Data;
type MessageActionsType = {
deleteMessage: (messageId: string) => unknown;
@ -475,7 +476,7 @@ export class ConversationView extends window.Backbone.View<ConversationModel> {
throw new Error(`markMessageRead: failed to load message ${messageId}`);
}
await this.model.markRead(message.received_at);
await this.model.markRead(message.get('received_at'));
};
const createMessageRequestResponseHandler =
@ -1250,18 +1251,10 @@ export class ConversationView extends window.Backbone.View<ConversationModel> {
}
async showForwardMessageModal(messageId: string): Promise<void> {
const messageFromCache = window.MessageController.getById(messageId);
if (!messageFromCache) {
log.info('showForwardMessageModal: Fetching message from database');
}
const found =
messageFromCache || (await window.Signal.Data.getMessageById(messageId));
if (!found) {
const message = await getMessageById(messageId);
if (!message) {
throw new Error(`showForwardMessageModal: Message ${messageId} missing!`);
}
const message = window.MessageController.register(found.id, found);
const attachments = getAttachmentsForMessage(message.attributes);
this.forwardMessageModal = new Whisper.ReactWrapperView({
@ -2673,15 +2666,12 @@ export class ConversationView extends window.Backbone.View<ConversationModel> {
async setQuoteMessage(messageId: null | string): Promise<void> {
const { model } = this;
const found = messageId ? await getMessageById(messageId) : undefined;
const message = found
? window.MessageController.register(found.id, found)
: undefined;
const message = messageId ? await getMessageById(messageId) : undefined;
if (
found &&
message &&
!canReply(
found,
message.attributes,
window.ConversationController.getOurConversationIdOrThrow(),
findAndFormatContact
)