refactor: move checkShouldDisappearButIsntMessage

to legacy file
pull/2971/head
William Grant 2 years ago
parent a2908cf24b
commit 3feb8cddf2

@ -13,6 +13,7 @@ import { getConversationController } from '../conversations';
import { isValidUnixTimestamp } from '../utils/Timestamps';
import {
checkIsLegacyDisappearingDataMessage,
checkShouldDisappearButIsntMessage,
couldBeLegacyDisappearingMessageContent,
} from './legacy';
import {
@ -229,7 +230,7 @@ export function changeToDisappearingMessageType(
expirationMode?: DisappearingMessageConversationModeType
): DisappearingMessageType {
if (expirationMode === 'off' || expirationMode === 'legacy') {
// NOTE we would want this to be undefined but because of an issue with the protobuf implement we need to have a value
// NOTE we would want this to be undefined but because of an issue with the protobuf implementation we need to have a value
return 'unknown';
}
@ -271,26 +272,6 @@ export function changeToDisappearingConversationMode(
return expirationType === 'deleteAfterSend' ? 'deleteAfterSend' : 'deleteAfterRead';
}
/**
* Checks if a message is meant to disappear but doesn't have the correct expiration values set
*
* NOTE Examples: legacy disappearing message conversation settings, synced messages from legacy devices
*/
function checkDisappearButIsntMessage(
content: SignalService.Content,
convo: ConversationModel,
expirationMode: DisappearingMessageConversationModeType,
expirationTimer: number
): boolean {
return (
content.dataMessage?.flags !== SignalService.DataMessage.Flags.EXPIRATION_TIMER_UPDATE &&
expirationMode === 'off' &&
expirationTimer === 0 &&
convo.getExpirationMode() !== 'off' &&
convo.getExpireTimer() !== 0
);
}
// TODO legacy messages support will be removed in a future release
export async function checkForExpireUpdateInContentMessage(
content: SignalService.Content,
@ -360,7 +341,7 @@ export async function checkForExpireUpdateInContentMessage(
};
}
const shouldDisappearButIsntMessage = checkDisappearButIsntMessage(
const shouldDisappearButIsntMessage = checkShouldDisappearButIsntMessage(
content,
convoToUpdate,
expirationMode,

@ -1,8 +1,9 @@
// TODO legacy messages support will be removed in a future release
import { ConversationModel } from '../../models/conversation';
import { ProtobufUtils, SignalService } from '../../protobuf';
import { ReleasedFeatures } from '../../util/releaseFeature';
import { DisappearingMessageConversationModeType } from './types';
// TODO legacy messages support will be removed in a future release
export function isLegacyDisappearingModeEnabled(
expirationMode: DisappearingMessageConversationModeType | undefined
): boolean {
@ -24,8 +25,7 @@ export function checkIsLegacyDisappearingDataMessage(
);
}
// 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
/** Use this to check for legacy disappearing messages where the expirationType and expireTimer should be undefined on the ContentMessage */
export function couldBeLegacyDisappearingMessageContent(
contentMessage: SignalService.Content
): boolean {
@ -36,3 +36,25 @@ export function couldBeLegacyDisappearingMessageContent(
!ProtobufUtils.hasDefinedProperty(contentMessage, 'expirationTimer')
);
}
/**
* Checks if a message is meant to disappear but doesn't have the correct expiration values set.
*
* Hopefully we can remove this when we remove legacy support but will need thorough testing
*
* NOTE Examples: legacy disappearing message conversation settings, synced messages from legacy devices
*/
export function checkShouldDisappearButIsntMessage(
content: SignalService.Content,
convo: ConversationModel,
expirationMode: DisappearingMessageConversationModeType,
expirationTimer: number
): boolean {
return (
content.dataMessage?.flags !== SignalService.DataMessage.Flags.EXPIRATION_TIMER_UPDATE &&
expirationMode === 'off' &&
expirationTimer === 0 &&
convo.getExpirationMode() !== 'off' &&
convo.getExpireTimer() !== 0
);
}

Loading…
Cancel
Save