diff --git a/ts/models/conversations.ts b/ts/models/conversations.ts index 81a5bfaf4..69a461e22 100644 --- a/ts/models/conversations.ts +++ b/ts/models/conversations.ts @@ -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; override defaults(): Partial { @@ -4582,15 +4579,6 @@ export class ConversationModel extends window.Backbone sendReadReceipts: true, } ): Promise { - // 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 diff --git a/ts/views/conversation_view.ts b/ts/views/conversation_view.ts index 7788e49c9..a7bf98024 100644 --- a/ts/views/conversation_view.ts +++ b/ts/views/conversation_view.ts @@ -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 { 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 { } async showForwardMessageModal(messageId: string): Promise { - 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 { async setQuoteMessage(messageId: null | string): Promise { 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 )