feat: renamed isLegacyMessage to isLegacyDataMessage

all works except modern to modern stage 2
pull/2660/head
William Grant 2 years ago
parent 89c70760a5
commit 8dc7d48c52

@ -1098,7 +1098,7 @@ export class MessageModel extends Backbone.Model<MessageAttributes> {
} }
// TODO legacy messages support will be removed in a future release // TODO legacy messages support will be removed in a future release
const isLegacyMessage = Boolean( const isLegacyDataMessage = Boolean(
(dataMessage.expireTimer && dataMessage.expireTimer > -1) || (dataMessage.expireTimer && dataMessage.expireTimer > -1) ||
(!content.expirationTimer && (!content.expirationTimer &&
dataMessage.flags === SignalService.DataMessage.Flags.EXPIRATION_TIMER_UPDATE) dataMessage.flags === SignalService.DataMessage.Flags.EXPIRATION_TIMER_UPDATE)
@ -1106,10 +1106,10 @@ export class MessageModel extends Backbone.Model<MessageAttributes> {
const expirationType = content.expirationType const expirationType = content.expirationType
? DisappearingMessageConversationSetting[content.expirationType] ? DisappearingMessageConversationSetting[content.expirationType]
: isLegacyMessage : isLegacyDataMessage
? DisappearingMessageConversationSetting[3] ? DisappearingMessageConversationSetting[3]
: 'off'; : 'off';
const expirationTimer = isLegacyMessage const expirationTimer = isLegacyDataMessage
? Number(dataMessage.expireTimer) ? Number(dataMessage.expireTimer)
: content.expirationTimer; : content.expirationTimer;
const lastDisappearingMessageChangeTimestamp = content.lastDisappearingMessageChangeTimestamp const lastDisappearingMessageChangeTimestamp = content.lastDisappearingMessageChangeTimestamp

@ -351,8 +351,13 @@ export async function handleMessageJob(
} }
if (messageModel.isExpirationTimerUpdate()) { if (messageModel.isExpirationTimerUpdate()) {
// TODO legacy messages support will be removed in a future release
// NOTE if we turn off disappearing messages from a legacy client expirationTimerUpdate can be undefined but the flags value is correctly set
const expirationTimerUpdate = messageModel.get('expirationTimerUpdate'); const expirationTimerUpdate = messageModel.get('expirationTimerUpdate');
if (!expirationTimerUpdate || isEmpty(expirationTimerUpdate)) { if (
messageModel.get('flags') !== SignalService.DataMessage.Flags.EXPIRATION_TIMER_UPDATE &&
(!expirationTimerUpdate || isEmpty(expirationTimerUpdate))
) {
window.log.info( window.log.info(
`WIP: There is a problem with the expiration timer update`, `WIP: There is a problem with the expiration timer update`,
messageModel, messageModel,
@ -361,10 +366,10 @@ export async function handleMessageJob(
return; return;
} }
const expirationType = expirationTimerUpdate.expirationType || 'off'; const expirationType = expirationTimerUpdate?.expirationType || 'off';
const expireTimer = expirationTimerUpdate.expireTimer; const expireTimer = expirationTimerUpdate?.expireTimer || 0;
const lastDisappearingMessageChangeTimestamp = const lastDisappearingMessageChangeTimestamp =
expirationTimerUpdate.lastDisappearingMessageChangeTimestamp || getNowWithNetworkOffset(); expirationTimerUpdate?.lastDisappearingMessageChangeTimestamp || getNowWithNetworkOffset();
// Compare mode and timestamp // Compare mode and timestamp
const oldTypeValue = conversation.get('expirationType'); const oldTypeValue = conversation.get('expirationType');

@ -33,7 +33,7 @@ export type DisappearingMessageUpdate = {
lastDisappearingMessageChangeTimestamp?: number; lastDisappearingMessageChangeTimestamp?: number;
// TODO legacy messages support will be removed in a future release // TODO legacy messages support will be removed in a future release
isLegacyConversationSettingMessage?: boolean; isLegacyConversationSettingMessage?: boolean;
isLegacyMessage?: boolean; isLegacyDataMessage?: boolean;
isDisappearingMessagesV2Released?: boolean; isDisappearingMessagesV2Released?: boolean;
isMismatchedMessage?: boolean; isMismatchedMessage?: boolean;
}; };
@ -283,27 +283,32 @@ export async function checkForExpireUpdate(
convoToUpdate: ConversationModel, convoToUpdate: ConversationModel,
content: SignalService.Content content: SignalService.Content
): Promise<DisappearingMessageUpdate | undefined> { ): Promise<DisappearingMessageUpdate | undefined> {
// debugger;
const dataMessage = content.dataMessage as SignalService.DataMessage; const dataMessage = content.dataMessage as SignalService.DataMessage;
// We will only support legacy disappearing messages for a short period before disappearing messages v2 is unlocked // We will only support legacy disappearing messages for a short period before disappearing messages v2 is unlocked
const isDisappearingMessagesV2Released = await checkIsFeatureReleased('Disappearing Messages V2'); const isDisappearingMessagesV2Released = await checkIsFeatureReleased('Disappearing Messages V2');
const isLegacyContentMessage = checkIsLegacyContentMessage(content); const isLegacyContentMessage = checkIsLegacyContentMessage(content);
const isLegacyMessage = Boolean( const isLegacyDataMessage = Boolean(
isLegacyContentMessage && checkIsLegacyDataMessage(dataMessage as SignalService.DataMessage) isLegacyContentMessage && checkIsLegacyDataMessage(dataMessage as SignalService.DataMessage)
); );
const isLegacyConversationSettingMessage =
isLegacyContentMessage &&
isLegacyDataMessage &&
dataMessage.flags === SignalService.DataMessage.Flags.EXPIRATION_TIMER_UPDATE;
let expirationTimer = isLegacyMessage ? Number(dataMessage.expireTimer) : content.expirationTimer; let expirationTimer = isLegacyDataMessage
? Number(dataMessage.expireTimer)
: content.expirationTimer;
let expirationType = let expirationType =
expirationTimer > 0 expirationTimer > 0
? DisappearingMessageConversationSetting[isLegacyContentMessage ? 3 : content.expirationType] ? DisappearingMessageConversationSetting[
!isDisappearingMessagesV2Released || isLegacyContentMessage ? 3 : content.expirationType
]
: DisappearingMessageConversationSetting[0]; : DisappearingMessageConversationSetting[0];
const lastDisappearingMessageChangeTimestamp = content.lastDisappearingMessageChangeTimestamp const lastDisappearingMessageChangeTimestamp = content.lastDisappearingMessageChangeTimestamp
? Number(content.lastDisappearingMessageChangeTimestamp) ? Number(content.lastDisappearingMessageChangeTimestamp)
: undefined; : undefined;
const isLegacyConversationSettingMessage =
isLegacyContentMessage &&
isLegacyMessage &&
dataMessage.flags === SignalService.DataMessage.Flags.EXPIRATION_TIMER_UPDATE;
const isMismatchedMessage = const isMismatchedMessage =
(!isLegacyConversationSettingMessage && (!isLegacyConversationSettingMessage &&
@ -315,9 +320,9 @@ export async function checkForExpireUpdate(
// If it is a legacy message and disappearing messages v2 is released then we ignore it and use the local client's conversation settings // If it is a legacy message and disappearing messages v2 is released then we ignore it and use the local client's conversation settings
if ( if (
isDisappearingMessagesV2Released && isDisappearingMessagesV2Released &&
(isLegacyMessage || (isLegacyDataMessage ||
isLegacyConversationSettingMessage || isLegacyConversationSettingMessage ||
(!isLegacyConversationSettingMessage && isMismatchedMessage)) (isLegacyDataMessage && isMismatchedMessage))
) { ) {
window.log.info(`WIP: received a legacy disappearing message after v2 was released.`); window.log.info(`WIP: received a legacy disappearing message after v2 was released.`);
expirationType = convoToUpdate.get('expirationType'); expirationType = convoToUpdate.get('expirationType');
@ -329,11 +334,13 @@ export async function checkForExpireUpdate(
expirationTimer, expirationTimer,
lastDisappearingMessageChangeTimestamp, lastDisappearingMessageChangeTimestamp,
isLegacyConversationSettingMessage, isLegacyConversationSettingMessage,
isLegacyMessage, isLegacyDataMessage,
isDisappearingMessagesV2Released, isDisappearingMessagesV2Released,
isMismatchedMessage, isMismatchedMessage,
}; };
window.log.info(`WIP: checkForExpireUpdate`, expireUpdate);
return expireUpdate; return expireUpdate;
} }
@ -389,7 +396,7 @@ export function checkHasOutdatedClient(
if (convoToUpdate.get('hasOutdatedClient')) { if (convoToUpdate.get('hasOutdatedClient')) {
// trigger notice banner // trigger notice banner
if ( if (
expireUpdate.isLegacyMessage || expireUpdate.isLegacyDataMessage ||
expireUpdate.isLegacyConversationSettingMessage || expireUpdate.isLegacyConversationSettingMessage ||
(expireUpdate.isDisappearingMessagesV2Released && expireUpdate.isMismatchedMessage) (expireUpdate.isDisappearingMessagesV2Released && expireUpdate.isMismatchedMessage)
) { ) {
@ -406,7 +413,7 @@ export function checkHasOutdatedClient(
convoToUpdate.commit(); convoToUpdate.commit();
} else { } else {
if ( if (
expireUpdate.isLegacyMessage || expireUpdate.isLegacyDataMessage ||
expireUpdate.isLegacyConversationSettingMessage || expireUpdate.isLegacyConversationSettingMessage ||
(expireUpdate.isDisappearingMessagesV2Released && expireUpdate.isMismatchedMessage) (expireUpdate.isDisappearingMessagesV2Released && expireUpdate.isMismatchedMessage)
) { ) {

Loading…
Cancel
Save