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';
|
} from '../util/deleteForMe';
|
||||||
import { explodePromise } from '../util/explodePromise';
|
import { explodePromise } from '../util/explodePromise';
|
||||||
import { getCallHistorySelector } from '../state/selectors/callHistory';
|
import { getCallHistorySelector } from '../state/selectors/callHistory';
|
||||||
|
import { migrateLegacyReadStatus } from '../messages/migrateLegacyReadStatus';
|
||||||
|
import { migrateLegacySendAttributes } from '../messages/migrateLegacySendAttributes';
|
||||||
|
|
||||||
/* eslint-disable more/no-then */
|
/* eslint-disable more/no-then */
|
||||||
window.Whisper = window.Whisper || {};
|
window.Whisper = window.Whisper || {};
|
||||||
|
@ -1935,22 +1937,69 @@ export class ConversationModel extends window.Backbone
|
||||||
}
|
}
|
||||||
|
|
||||||
let upgraded = 0;
|
let upgraded = 0;
|
||||||
|
const ourConversationId =
|
||||||
|
window.ConversationController.getOurConversationId();
|
||||||
|
|
||||||
const hydrated = await Promise.all(
|
const hydrated = await Promise.all(
|
||||||
present.map(async message => {
|
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(
|
const upgradedMessage = await window.MessageCache.upgradeSchema(
|
||||||
message,
|
migratedMessage,
|
||||||
Message.VERSION_NEEDED_FOR_DISPLAY
|
Message.VERSION_NEEDED_FOR_DISPLAY
|
||||||
);
|
);
|
||||||
if (upgradedMessage !== message) {
|
|
||||||
upgraded += 1;
|
|
||||||
}
|
|
||||||
|
|
||||||
const patch = await hydrateStoryContext(message.id, undefined, {
|
const patch = await hydrateStoryContext(message.id, undefined, {
|
||||||
shouldSave: true,
|
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) {
|
if (patch) {
|
||||||
return { ...upgradedMessage, ...patch };
|
return { ...upgradedMessage, ...patch };
|
||||||
}
|
}
|
||||||
|
|
||||||
return upgradedMessage;
|
return upgradedMessage;
|
||||||
})
|
})
|
||||||
);
|
);
|
||||||
|
@ -4285,11 +4334,13 @@ export class ConversationModel extends window.Backbone
|
||||||
if (preview) {
|
if (preview) {
|
||||||
const inMemory = window.MessageCache.accessAttributes(preview.id);
|
const inMemory = window.MessageCache.accessAttributes(preview.id);
|
||||||
preview = inMemory || preview;
|
preview = inMemory || preview;
|
||||||
|
preview = (await this.cleanAttributes([preview]))?.[0] || preview;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (activity) {
|
if (activity) {
|
||||||
const inMemory = window.MessageCache.accessAttributes(activity.id);
|
const inMemory = window.MessageCache.accessAttributes(activity.id);
|
||||||
activity = inMemory || activity;
|
activity = inMemory || activity;
|
||||||
|
activity = (await this.cleanAttributes([activity]))?.[0] || activity;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (
|
if (
|
||||||
|
|
|
@ -54,8 +54,6 @@ import {
|
||||||
sendStateReducer,
|
sendStateReducer,
|
||||||
someRecipientSendStatus,
|
someRecipientSendStatus,
|
||||||
} from '../messages/MessageSendState';
|
} from '../messages/MessageSendState';
|
||||||
import { migrateLegacyReadStatus } from '../messages/migrateLegacyReadStatus';
|
|
||||||
import { migrateLegacySendAttributes } from '../messages/migrateLegacySendAttributes';
|
|
||||||
import { getOwn } from '../util/getOwn';
|
import { getOwn } from '../util/getOwn';
|
||||||
import { markRead, markViewed } from '../services/MessageUpdater';
|
import { markRead, markViewed } from '../services/MessageUpdater';
|
||||||
import {
|
import {
|
||||||
|
@ -126,7 +124,6 @@ import { queueAttachmentDownloads } from '../util/queueAttachmentDownloads';
|
||||||
import { findStoryMessages } from '../util/findStoryMessage';
|
import { findStoryMessages } from '../util/findStoryMessage';
|
||||||
import type { ConversationQueueJobData } from '../jobs/conversationJobQueue';
|
import type { ConversationQueueJobData } from '../jobs/conversationJobQueue';
|
||||||
import { shouldDownloadStory } from '../util/shouldDownloadStory';
|
import { shouldDownloadStory } from '../util/shouldDownloadStory';
|
||||||
import { SeenStatus } from '../MessageSeenStatus';
|
|
||||||
import { isNewReactionReplacingPrevious } from '../reactions/util';
|
import { isNewReactionReplacingPrevious } from '../reactions/util';
|
||||||
import { parseBoostBadgeListFromServer } from '../badges/parseBadgesFromServer';
|
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.CURRENT_PROTOCOL_VERSION = Proto.DataMessage.ProtocolVersion.CURRENT;
|
||||||
this.INITIAL_PROTOCOL_VERSION = Proto.DataMessage.ProtocolVersion.INITIAL;
|
this.INITIAL_PROTOCOL_VERSION = Proto.DataMessage.ProtocolVersion.INITIAL;
|
||||||
|
|
||||||
|
|
|
@ -124,8 +124,10 @@ describe('backup/bubble messages', () => {
|
||||||
conversationId: contactA.id,
|
conversationId: contactA.id,
|
||||||
id: generateGuid(),
|
id: generateGuid(),
|
||||||
type: 'outgoing',
|
type: 'outgoing',
|
||||||
|
readStatus: ReadStatus.Read,
|
||||||
received_at: 3,
|
received_at: 3,
|
||||||
received_at_ms: 3,
|
received_at_ms: 3,
|
||||||
|
seenStatus: SeenStatus.Seen,
|
||||||
sent_at: 3,
|
sent_at: 3,
|
||||||
sourceServiceId: OUR_ACI,
|
sourceServiceId: OUR_ACI,
|
||||||
sendStateByConversationId: {
|
sendStateByConversationId: {
|
||||||
|
@ -330,8 +332,10 @@ describe('backup/bubble messages', () => {
|
||||||
conversationId: contactA.id,
|
conversationId: contactA.id,
|
||||||
id: generateGuid(),
|
id: generateGuid(),
|
||||||
type: 'outgoing',
|
type: 'outgoing',
|
||||||
|
readStatus: ReadStatus.Read,
|
||||||
received_at: 4,
|
received_at: 4,
|
||||||
received_at_ms: 4,
|
received_at_ms: 4,
|
||||||
|
seenStatus: SeenStatus.Seen,
|
||||||
sent_at: 4,
|
sent_at: 4,
|
||||||
sourceServiceId: OUR_ACI,
|
sourceServiceId: OUR_ACI,
|
||||||
sendStateByConversationId: {
|
sendStateByConversationId: {
|
||||||
|
@ -378,8 +382,10 @@ describe('backup/bubble messages', () => {
|
||||||
conversationId: contactA.id,
|
conversationId: contactA.id,
|
||||||
id: generateGuid(),
|
id: generateGuid(),
|
||||||
type: 'outgoing',
|
type: 'outgoing',
|
||||||
|
readStatus: ReadStatus.Read,
|
||||||
received_at: 4,
|
received_at: 4,
|
||||||
received_at_ms: 4,
|
received_at_ms: 4,
|
||||||
|
seenStatus: SeenStatus.Seen,
|
||||||
sent_at: 4,
|
sent_at: 4,
|
||||||
sourceServiceId: OUR_ACI,
|
sourceServiceId: OUR_ACI,
|
||||||
sendStateByConversationId: {
|
sendStateByConversationId: {
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue