fix: disappear messages from other platforms correctly

some platforms use the convo settings and dont include info the dataMessage before the v2 release
pull/2971/head
William Grant 2 years ago
parent 58331209c7
commit 6031db308d

@ -346,7 +346,6 @@ export async function handleNewClosedGroup(
isKickedFromGroup: false, isKickedFromGroup: false,
lastJoinedTimestamp: toNumber(envelope.timestamp), lastJoinedTimestamp: toNumber(envelope.timestamp),
// we just got readded. Consider the zombie list to have been cleared // we just got readded. Consider the zombie list to have been cleared
zombies: [], zombies: [],
}); });
} }
@ -372,7 +371,7 @@ export async function handleNewClosedGroup(
// be sure to call this before sending the message. // be sure to call this before sending the message.
// the sending pipeline needs to know from GroupUtils when a message is for a medium group // the sending pipeline needs to know from GroupUtils when a message is for a medium group
await ClosedGroup.updateOrCreateClosedGroup(groupDetails, fromLegacyConfig); await ClosedGroup.updateOrCreateClosedGroup(groupDetails);
// ClosedGroup.updateOrCreateClosedGroup will mark the activeAt to Date.now if it's active // ClosedGroup.updateOrCreateClosedGroup will mark the activeAt to Date.now if it's active
// But we need to override this value with the sent timestamp of the message creating this group for us. // But we need to override this value with the sent timestamp of the message creating this group for us.

@ -88,7 +88,7 @@ export async function initiateClosedGroupUpdate(
zombies: convo.get('zombies')?.filter(z => members.includes(z)), zombies: convo.get('zombies')?.filter(z => members.includes(z)),
activeAt: Date.now(), activeAt: Date.now(),
expirationType, expirationType,
expireTimer: convo.get('expireTimer') || 0, expireTimer: convo.get('expireTimer'),
}; };
const diff = buildGroupDiff(convo, groupDetails); const diff = buildGroupDiff(convo, groupDetails);
@ -170,7 +170,7 @@ export async function addUpdateMessage(
} }
const expirationMode = convo.get('expirationType'); const expirationMode = convo.get('expirationType');
const expireTimer = convo.get('expireTimer') || 0; const expireTimer = convo.get('expireTimer');
let expirationType; let expirationType;
let expirationStartTimestamp; let expirationStartTimestamp;

@ -352,7 +352,7 @@ export function changeToDisappearingMessageConversationType(
// TODO legacy messages support will be removed in a future release // TODO legacy messages support will be removed in a future release
// NOTE We need this to check for legacy disappearing messages where the expirationType and expireTimer should be undefined on the ContentMessage // NOTE We need this to check for legacy disappearing messages where the expirationType and expireTimer should be undefined on the ContentMessage
function checkIsLegacyContentMessage(contentMessage: SignalService.Content): boolean { function checkIsLegacyDisappearingContentMessage(contentMessage: SignalService.Content): boolean {
return ( return (
(contentMessage.expirationType === SignalService.Content.ExpirationType.UNKNOWN || (contentMessage.expirationType === SignalService.Content.ExpirationType.UNKNOWN ||
!ProtobufUtils.hasDefinedProperty(contentMessage, 'expirationType')) && !ProtobufUtils.hasDefinedProperty(contentMessage, 'expirationType')) &&
@ -360,7 +360,7 @@ function checkIsLegacyContentMessage(contentMessage: SignalService.Content): boo
); );
} }
function checkIsLegacyDataMessage(dataMessage: SignalService.DataMessage): boolean { function checkIsLegacyDisappearingDataMessage(dataMessage: SignalService.DataMessage): boolean {
return ( return (
ProtobufUtils.hasDefinedProperty(dataMessage, 'expireTimer') && dataMessage.expireTimer > -1 ProtobufUtils.hasDefinedProperty(dataMessage, 'expireTimer') && dataMessage.expireTimer > -1
); );
@ -375,9 +375,10 @@ export async function checkForExpireUpdateInContentMessage(
// 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 ReleasedFeatures.checkIsDisappearMessageV2FeatureReleased(); const isDisappearingMessagesV2Released = await ReleasedFeatures.checkIsDisappearMessageV2FeatureReleased();
const isLegacyContentMessage = checkIsLegacyContentMessage(content); const isLegacyContentMessage = checkIsLegacyDisappearingContentMessage(content);
const isLegacyDataMessage = Boolean( const isLegacyDataMessage = Boolean(
isLegacyContentMessage && checkIsLegacyDataMessage(dataMessage as SignalService.DataMessage) isLegacyContentMessage &&
checkIsLegacyDisappearingDataMessage(dataMessage as SignalService.DataMessage)
); );
const isLegacyConversationSettingMessage = isDisappearingMessagesV2Released const isLegacyConversationSettingMessage = isDisappearingMessagesV2Released
? isLegacyContentMessage && ? isLegacyContentMessage &&
@ -414,12 +415,38 @@ export async function checkForExpireUpdateInContentMessage(
convoToUpdate.get('expirationType') !== 'off' && convoToUpdate.get('expirationType') !== 'off' &&
convoToUpdate.get('expireTimer') !== 0; convoToUpdate.get('expireTimer') !== 0;
// If it is a legacy message and disappearing messages v2 is released then we ignore it and use the local client's conversation settings // NOTE some platforms do not include the diappearing message values in the Data Message for sent messages so we have to trust the conversation settings until v2 is released
if (
!isDisappearingMessagesV2Released &&
!isLegacyConversationSettingMessage &&
isLegacyContentMessage &&
convoToUpdate.get('expirationType') !== 'off'
) {
if (
expirationType !== convoToUpdate.get('expirationType') ||
expirationTimer !== convoToUpdate.get('expireTimer')
) {
window.log.debug(
'WIP: Received a legacy disappearing message before v2 was released without values set. Using the conversation settings.',
content
);
expirationTimer = convoToUpdate.get('expireTimer');
expirationType = changeToDisappearingMessageType(
convoToUpdate,
convoToUpdate.get('expirationType')
);
}
}
// NOTE 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 &&
(isLegacyDataMessage || isLegacyConversationSettingMessage || shouldDisappearButIsntMessage) (isLegacyDataMessage || isLegacyConversationSettingMessage || shouldDisappearButIsntMessage)
) { ) {
window.log.warn('Received a legacy disappearing message after v2 was released.', content); window.log.warn(
'Received a legacy disappearing message after v2 was released. Overriding it with the conversation settings',
content
);
expirationTimer = convoToUpdate.get('expireTimer'); expirationTimer = convoToUpdate.get('expireTimer');
expirationType = changeToDisappearingMessageType( expirationType = changeToDisappearingMessageType(
convoToUpdate, convoToUpdate,

Loading…
Cancel
Save