Fix "mark conversation read" optimization
This commit is contained in:
parent
397753bbfe
commit
c5ad020de7
2 changed files with 8 additions and 32 deletions
|
@ -213,9 +213,6 @@ export class ConversationModel extends window.Backbone
|
||||||
|
|
||||||
private isInReduxBatch = false;
|
private isInReduxBatch = false;
|
||||||
|
|
||||||
// This number is recorded as an optimization and may be out of date.
|
|
||||||
private newestReceivedAtMarkedRead?: number;
|
|
||||||
|
|
||||||
private _activeProfileFetch?: Promise<void>;
|
private _activeProfileFetch?: Promise<void>;
|
||||||
|
|
||||||
override defaults(): Partial<ConversationAttributesType> {
|
override defaults(): Partial<ConversationAttributesType> {
|
||||||
|
@ -4582,15 +4579,6 @@ export class ConversationModel extends window.Backbone
|
||||||
sendReadReceipts: true,
|
sendReadReceipts: true,
|
||||||
}
|
}
|
||||||
): Promise<void> {
|
): 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);
|
await markConversationRead(this.attributes, newestUnreadAt, options);
|
||||||
|
|
||||||
const unreadCount = await window.Signal.Data.getTotalUnreadForConversation(
|
const unreadCount = await window.Signal.Data.getTotalUnreadForConversation(
|
||||||
|
@ -4602,8 +4590,6 @@ export class ConversationModel extends window.Backbone
|
||||||
this.set({ unreadCount });
|
this.set({ unreadCount });
|
||||||
window.Signal.Data.updateConversation(this.attributes);
|
window.Signal.Data.updateConversation(this.attributes);
|
||||||
}
|
}
|
||||||
|
|
||||||
this.newestReceivedAtMarkedRead = newestUnreadAt;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// This is an expensive operation we use to populate the message request hero row. It
|
// This is an expensive operation we use to populate the message request hero row. It
|
||||||
|
|
|
@ -29,6 +29,7 @@ import type {
|
||||||
MessageAttributesType as MediaItemMessageType,
|
MessageAttributesType as MediaItemMessageType,
|
||||||
} from '../types/MediaItem';
|
} from '../types/MediaItem';
|
||||||
import type { MessageModel } from '../models/messages';
|
import type { MessageModel } from '../models/messages';
|
||||||
|
import { getMessageById } from '../messages/getMessageById';
|
||||||
import { getContactId } from '../messages/helpers';
|
import { getContactId } from '../messages/helpers';
|
||||||
import { strictAssert } from '../util/assert';
|
import { strictAssert } from '../util/assert';
|
||||||
import { maybeParseUrl } from '../util/url';
|
import { maybeParseUrl } from '../util/url';
|
||||||
|
@ -137,7 +138,7 @@ const {
|
||||||
upgradeMessageSchema,
|
upgradeMessageSchema,
|
||||||
} = window.Signal.Migrations;
|
} = window.Signal.Migrations;
|
||||||
|
|
||||||
const { getMessageById, getMessagesBySentAt } = window.Signal.Data;
|
const { getMessagesBySentAt } = window.Signal.Data;
|
||||||
|
|
||||||
type MessageActionsType = {
|
type MessageActionsType = {
|
||||||
deleteMessage: (messageId: string) => unknown;
|
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}`);
|
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 =
|
const createMessageRequestResponseHandler =
|
||||||
|
@ -1250,18 +1251,10 @@ export class ConversationView extends window.Backbone.View<ConversationModel> {
|
||||||
}
|
}
|
||||||
|
|
||||||
async showForwardMessageModal(messageId: string): Promise<void> {
|
async showForwardMessageModal(messageId: string): Promise<void> {
|
||||||
const messageFromCache = window.MessageController.getById(messageId);
|
const message = await getMessageById(messageId);
|
||||||
if (!messageFromCache) {
|
if (!message) {
|
||||||
log.info('showForwardMessageModal: Fetching message from database');
|
|
||||||
}
|
|
||||||
const found =
|
|
||||||
messageFromCache || (await window.Signal.Data.getMessageById(messageId));
|
|
||||||
|
|
||||||
if (!found) {
|
|
||||||
throw new Error(`showForwardMessageModal: Message ${messageId} missing!`);
|
throw new Error(`showForwardMessageModal: Message ${messageId} missing!`);
|
||||||
}
|
}
|
||||||
|
|
||||||
const message = window.MessageController.register(found.id, found);
|
|
||||||
const attachments = getAttachmentsForMessage(message.attributes);
|
const attachments = getAttachmentsForMessage(message.attributes);
|
||||||
|
|
||||||
this.forwardMessageModal = new Whisper.ReactWrapperView({
|
this.forwardMessageModal = new Whisper.ReactWrapperView({
|
||||||
|
@ -2673,15 +2666,12 @@ export class ConversationView extends window.Backbone.View<ConversationModel> {
|
||||||
|
|
||||||
async setQuoteMessage(messageId: null | string): Promise<void> {
|
async setQuoteMessage(messageId: null | string): Promise<void> {
|
||||||
const { model } = this;
|
const { model } = this;
|
||||||
const found = messageId ? await getMessageById(messageId) : undefined;
|
const message = messageId ? await getMessageById(messageId) : undefined;
|
||||||
const message = found
|
|
||||||
? window.MessageController.register(found.id, found)
|
|
||||||
: undefined;
|
|
||||||
|
|
||||||
if (
|
if (
|
||||||
found &&
|
message &&
|
||||||
!canReply(
|
!canReply(
|
||||||
found,
|
message.attributes,
|
||||||
window.ConversationController.getOurConversationIdOrThrow(),
|
window.ConversationController.getOurConversationIdOrThrow(),
|
||||||
findAndFormatContact
|
findAndFormatContact
|
||||||
)
|
)
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue