fix: deleteAfterSend now works in private convos again

pull/2971/head
William Grant 2 years ago
parent ad21d198cf
commit c24487b938

@ -877,13 +877,16 @@ export class ConversationModel extends Backbone.Model<ConversationAttributes> {
lastDisappearingMessageChangeTimestamp,
});
window?.log?.debug('WIP: Updating conversation disappearing messages setting', {
id: this.idForLogging(),
expirationType,
expireTimer,
lastDisappearingMessageChangeTimestamp,
source,
});
window?.log?.debug(
'WIP: updateExpireTimer() Updating conversation disappearing messages setting',
{
id: this.idForLogging(),
expirationType,
expireTimer,
lastDisappearingMessageChangeTimestamp,
source,
}
);
let message: MessageModel | undefined = existingMessage || undefined;
const messageExpirationType = changeToDisappearingMessageType(

@ -486,7 +486,7 @@ export async function innerHandleSwarmContentMessage(
);
// TODO legacy messages support will be removed in a future release
if (expireUpdate.isDisappearingMessagesV2Released) {
if (expireUpdate?.isDisappearingMessagesV2Released) {
await checkHasOutdatedDisappearingMessageClient(
conversationModelForUIUpdate,
senderConversationModel,
@ -494,8 +494,9 @@ export async function innerHandleSwarmContentMessage(
);
if (expireUpdate.isLegacyConversationSettingMessage) {
window.log.debug(
'WIP: The legacy message is an expiration timer update. Ignoring it.',
content
`WIP: The legacy message is an expiration timer update. Ignoring it. ${JSON.stringify(
content
)}}`
);
return;
}

@ -159,7 +159,7 @@ export async function handleSwarmDataMessage(
rawDataMessage: SignalService.DataMessage,
messageHash: string,
senderConversationModel: ConversationModel,
expireUpdate: DisappearingMessageUpdate
expireUpdate?: DisappearingMessageUpdate
): Promise<void> {
window.log.info('handleSwarmDataMessage');
@ -261,8 +261,10 @@ export async function handleSwarmDataMessage(
sentAt: sentAtTimestamp,
});
msgModel = updateMessageModelToExpire(convoToAddMessageTo, msgModel, expireUpdate);
window.log.debug(`WIP: innerHandleSwarmContentMessage msgModel ${JSON.stringify(msgModel)}`);
if (!isEmpty(expireUpdate)) {
msgModel = updateMessageModelToExpire(convoToAddMessageTo, msgModel, expireUpdate);
window.log.debug(`WIP: innerHandleSwarmContentMessage msgModel ${JSON.stringify(msgModel)}`);
}
await handleSwarmMessage(
msgModel,

@ -23,6 +23,7 @@ import { LinkPreviews } from '../util/linkPreviews';
import { ReleasedFeatures } from '../util/releaseFeature';
import { PropsForMessageWithoutConvoProps, lookupQuote } from '../state/ducks/conversations';
import { PubKey } from '../session/types';
import { UserUtils } from '../session/utils';
function contentTypeSupported(type: string): boolean {
const Chrome = GoogleChrome;
@ -398,8 +399,7 @@ export async function handleMessageJob(
const expirationType = messageModel.get('expirationType');
const expireTimer = messageModel.get('expireTimer');
// NOTE we handle incoming disappear afer send messages and are Note To Self sync messages here
// TODO I think this is incorrect? Let's fix
// NOTE we handle incoming disappear afer send messages and sync messages here
if (
conversation &&
expireTimer > 0 &&
@ -411,16 +411,31 @@ export async function handleMessageJob(
expireTimer
);
if (expirationMode === 'legacy' || expirationMode === 'deleteAfterSend') {
// TODO legacy messages support will be removed in a future release
// NOTE if the expirationMode is deleteAfterRead then legacy sync messages need to explicitly set the expirationStartTimestamp since they are alread marked as read
const legacySyncMessageMustDisappearAfterRead =
expirationMode === 'deleteAfterRead' &&
source === UserUtils.getOurPubKeyStrFromCache() &&
messageModel.get('type') === 'outgoing';
if (
expirationMode === 'legacy' ||
expirationMode === 'deleteAfterSend' ||
legacySyncMessageMustDisappearAfterRead
) {
messageModel.set({
expirationStartTimestamp: setExpirationStartTimestamp(
expirationMode,
messageModel.get('sent_at')
!legacySyncMessageMustDisappearAfterRead ? messageModel.get('sent_at') : undefined
),
});
}
}
window.log.debug(
`WIP: handleMessageJob ${messageModel.idForLogging()} is ${JSON.stringify(messageModel)}`
);
if (messageModel.isExpirationTimerUpdate()) {
// 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');

@ -1,5 +1,5 @@
import { v4 as uuidv4 } from 'uuid';
import _ from 'lodash';
import _, { isEmpty } from 'lodash';
import { UserUtils } from '..';
import { getMessageQueue } from '../..';
import { Data } from '../../../data/data';
@ -370,7 +370,7 @@ export const buildSyncMessage = (
data: DataMessage | SignalService.DataMessage,
syncTarget: string,
sentTimestamp: number,
expireUpdate: DisappearingMessageUpdate
expireUpdate?: DisappearingMessageUpdate
): VisibleMessage | ExpirationTimerUpdateMessage => {
if (
(data as any).constructor.name !== 'DataMessage' &&
@ -387,7 +387,7 @@ export const buildSyncMessage = (
// don't include our profileKey on syncing message. This is to be done by a ConfigurationMessage now
const timestamp = _.toNumber(sentTimestamp);
if (dataMessage.flags === SignalService.DataMessage.Flags.EXPIRATION_TIMER_UPDATE) {
if (expireUpdate.lastDisappearingMessageChangeTimestamp) {
if (!isEmpty(expireUpdate) && expireUpdate.lastDisappearingMessageChangeTimestamp) {
return buildSyncExpireTimerMessage(identifier, expireUpdate, timestamp, syncTarget);
}
window.log.warn('WIP: Building Sync Expire Timer Message failed', dataMessage, expireUpdate);

@ -323,7 +323,8 @@ export function changeToDisappearingMessageType(
if (convo.isMe() || convo.isClosedGroup()) {
return 'deleteAfterSend';
}
return 'deleteAfterRead';
return expirationType === 'deleteAfterSend' ? 'deleteAfterSend' : 'deleteAfterRead';
}
return 'unknown';
@ -353,7 +354,7 @@ export function changeToDisappearingMessageConversationType(
return 'deleteAfterSend';
}
return 'deleteAfterRead';
return expirationType === 'deleteAfterSend' ? 'deleteAfterSend' : 'deleteAfterRead';
}
// TODO legacy messages support will be removed in a future release
@ -403,7 +404,7 @@ export function checkIsLegacyDisappearingDataMessage(
export async function checkForExpireUpdateInContentMessage(
content: SignalService.Content,
convoToUpdate: ConversationModel
): Promise<DisappearingMessageUpdate> {
): Promise<DisappearingMessageUpdate | undefined> {
const dataMessage = content.dataMessage as SignalService.DataMessage;
// We will only support legacy disappearing messages for a short period before disappearing messages v2 is unlocked
const isDisappearingMessagesV2Released = await ReleasedFeatures.checkIsDisappearMessageV2FeatureReleased();
@ -507,6 +508,7 @@ export function updateMessageModelToExpire(
expireUpdate?: DisappearingMessageUpdate
) {
if (!expireUpdate) {
window.log.debug(`WIP: callced updateMessageModelToExpire() without expireUpdate`);
return messageModel;
}

Loading…
Cancel
Save