Move message upgrade from Backbone constructor to cleanAttributes
This commit is contained in:
parent
ba6e11614e
commit
d7cbd2c2ae
3 changed files with 61 additions and 36 deletions
|
@ -185,6 +185,8 @@ import {
|
|||
} from '../util/deleteForMe';
|
||||
import { explodePromise } from '../util/explodePromise';
|
||||
import { getCallHistorySelector } from '../state/selectors/callHistory';
|
||||
import { migrateLegacyReadStatus } from '../messages/migrateLegacyReadStatus';
|
||||
import { migrateLegacySendAttributes } from '../messages/migrateLegacySendAttributes';
|
||||
|
||||
/* eslint-disable more/no-then */
|
||||
window.Whisper = window.Whisper || {};
|
||||
|
@ -1935,22 +1937,69 @@ export class ConversationModel extends window.Backbone
|
|||
}
|
||||
|
||||
let upgraded = 0;
|
||||
const ourConversationId =
|
||||
window.ConversationController.getOurConversationId();
|
||||
|
||||
const hydrated = await Promise.all(
|
||||
present.map(async message => {
|
||||
let migratedMessage = message;
|
||||
|
||||
const readStatus = migrateLegacyReadStatus(migratedMessage);
|
||||
if (readStatus !== undefined) {
|
||||
migratedMessage = {
|
||||
...migratedMessage,
|
||||
readStatus,
|
||||
seenStatus:
|
||||
readStatus === ReadStatus.Unread
|
||||
? SeenStatus.Unseen
|
||||
: SeenStatus.Seen,
|
||||
};
|
||||
}
|
||||
|
||||
if (ourConversationId) {
|
||||
const sendStateByConversationId = migrateLegacySendAttributes(
|
||||
migratedMessage,
|
||||
window.ConversationController.get.bind(
|
||||
window.ConversationController
|
||||
),
|
||||
ourConversationId
|
||||
);
|
||||
if (sendStateByConversationId) {
|
||||
migratedMessage = {
|
||||
...migratedMessage,
|
||||
sendStateByConversationId,
|
||||
};
|
||||
}
|
||||
}
|
||||
|
||||
const upgradedMessage = await window.MessageCache.upgradeSchema(
|
||||
message,
|
||||
migratedMessage,
|
||||
Message.VERSION_NEEDED_FOR_DISPLAY
|
||||
);
|
||||
if (upgradedMessage !== message) {
|
||||
upgraded += 1;
|
||||
}
|
||||
|
||||
const patch = await hydrateStoryContext(message.id, undefined, {
|
||||
shouldSave: true,
|
||||
});
|
||||
|
||||
const didMigrate = migratedMessage !== message;
|
||||
const didUpgrade = upgradedMessage !== migratedMessage;
|
||||
const didPatch = Boolean(patch);
|
||||
|
||||
if (didMigrate || didUpgrade || didPatch) {
|
||||
upgraded += 1;
|
||||
}
|
||||
if (didMigrate && !didUpgrade && !didPatch) {
|
||||
await window.MessageCache.setAttributes({
|
||||
messageId: message.id,
|
||||
messageAttributes: migratedMessage,
|
||||
skipSaveToDatabase: false,
|
||||
});
|
||||
}
|
||||
|
||||
if (patch) {
|
||||
return { ...upgradedMessage, ...patch };
|
||||
}
|
||||
|
||||
return upgradedMessage;
|
||||
})
|
||||
);
|
||||
|
@ -4285,11 +4334,13 @@ export class ConversationModel extends window.Backbone
|
|||
if (preview) {
|
||||
const inMemory = window.MessageCache.accessAttributes(preview.id);
|
||||
preview = inMemory || preview;
|
||||
preview = (await this.cleanAttributes([preview]))?.[0] || preview;
|
||||
}
|
||||
|
||||
if (activity) {
|
||||
const inMemory = window.MessageCache.accessAttributes(activity.id);
|
||||
activity = inMemory || activity;
|
||||
activity = (await this.cleanAttributes([activity]))?.[0] || activity;
|
||||
}
|
||||
|
||||
if (
|
||||
|
|
|
@ -54,8 +54,6 @@ import {
|
|||
sendStateReducer,
|
||||
someRecipientSendStatus,
|
||||
} from '../messages/MessageSendState';
|
||||
import { migrateLegacyReadStatus } from '../messages/migrateLegacyReadStatus';
|
||||
import { migrateLegacySendAttributes } from '../messages/migrateLegacySendAttributes';
|
||||
import { getOwn } from '../util/getOwn';
|
||||
import { markRead, markViewed } from '../services/MessageUpdater';
|
||||
import {
|
||||
|
@ -126,7 +124,6 @@ import { queueAttachmentDownloads } from '../util/queueAttachmentDownloads';
|
|||
import { findStoryMessages } from '../util/findStoryMessage';
|
||||
import type { ConversationQueueJobData } from '../jobs/conversationJobQueue';
|
||||
import { shouldDownloadStory } from '../util/shouldDownloadStory';
|
||||
import { SeenStatus } from '../MessageSeenStatus';
|
||||
import { isNewReactionReplacingPrevious } from '../reactions/util';
|
||||
import { parseBoostBadgeListFromServer } from '../badges/parseBadgesFromServer';
|
||||
|
||||
|
@ -210,35 +207,6 @@ export class MessageModel extends window.Backbone.Model<MessageAttributesType> {
|
|||
);
|
||||
}
|
||||
|
||||
const readStatus = migrateLegacyReadStatus(this.attributes);
|
||||
if (readStatus !== undefined) {
|
||||
this.set(
|
||||
{
|
||||
readStatus,
|
||||
seenStatus:
|
||||
readStatus === ReadStatus.Unread
|
||||
? SeenStatus.Unseen
|
||||
: SeenStatus.Seen,
|
||||
},
|
||||
{ silent: true }
|
||||
);
|
||||
}
|
||||
|
||||
const ourConversationId =
|
||||
window.ConversationController.getOurConversationId();
|
||||
if (ourConversationId) {
|
||||
const sendStateByConversationId = migrateLegacySendAttributes(
|
||||
this.attributes,
|
||||
window.ConversationController.get.bind(window.ConversationController),
|
||||
ourConversationId
|
||||
);
|
||||
if (sendStateByConversationId) {
|
||||
this.set('sendStateByConversationId', sendStateByConversationId, {
|
||||
silent: true,
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
this.CURRENT_PROTOCOL_VERSION = Proto.DataMessage.ProtocolVersion.CURRENT;
|
||||
this.INITIAL_PROTOCOL_VERSION = Proto.DataMessage.ProtocolVersion.INITIAL;
|
||||
|
||||
|
|
|
@ -124,8 +124,10 @@ describe('backup/bubble messages', () => {
|
|||
conversationId: contactA.id,
|
||||
id: generateGuid(),
|
||||
type: 'outgoing',
|
||||
readStatus: ReadStatus.Read,
|
||||
received_at: 3,
|
||||
received_at_ms: 3,
|
||||
seenStatus: SeenStatus.Seen,
|
||||
sent_at: 3,
|
||||
sourceServiceId: OUR_ACI,
|
||||
sendStateByConversationId: {
|
||||
|
@ -330,8 +332,10 @@ describe('backup/bubble messages', () => {
|
|||
conversationId: contactA.id,
|
||||
id: generateGuid(),
|
||||
type: 'outgoing',
|
||||
readStatus: ReadStatus.Read,
|
||||
received_at: 4,
|
||||
received_at_ms: 4,
|
||||
seenStatus: SeenStatus.Seen,
|
||||
sent_at: 4,
|
||||
sourceServiceId: OUR_ACI,
|
||||
sendStateByConversationId: {
|
||||
|
@ -378,8 +382,10 @@ describe('backup/bubble messages', () => {
|
|||
conversationId: contactA.id,
|
||||
id: generateGuid(),
|
||||
type: 'outgoing',
|
||||
readStatus: ReadStatus.Read,
|
||||
received_at: 4,
|
||||
received_at_ms: 4,
|
||||
seenStatus: SeenStatus.Seen,
|
||||
sent_at: 4,
|
||||
sourceServiceId: OUR_ACI,
|
||||
sendStateByConversationId: {
|
||||
|
|
Loading…
Reference in a new issue