From ee4aa333fceb1ee937283c96402674f458fa349b Mon Sep 17 00:00:00 2001 From: William Grant Date: Mon, 3 Apr 2023 14:09:05 +0200 Subject: [PATCH] feat: disappearing after send is not working correctly --- ts/models/conversation.ts | 13 +++++++++++-- ts/receiver/queuedJob.ts | 5 +++-- .../outgoing/visibleMessage/VisibleMessage.ts | 19 +++++++++++++++++-- 3 files changed, 31 insertions(+), 6 deletions(-) diff --git a/ts/models/conversation.ts b/ts/models/conversation.ts index 986c9d418..f917d4f12 100644 --- a/ts/models/conversation.ts +++ b/ts/models/conversation.ts @@ -541,7 +541,7 @@ export class ConversationModel extends Backbone.Model { return getOpenGroupV2FromConversationId(this.id); } - public async sendMessageJob(message: MessageModel, expireTimer: number | undefined) { + public async sendMessageJob(message: MessageModel) { try { const { body, attachments, preview, quote, fileIdsToLink } = await message.uploadData(); const { id } = message; @@ -552,6 +552,9 @@ export class ConversationModel extends Backbone.Model { throw new Error('sendMessageJob() sent_at must be set.'); } + const expirationType = message.get('expirationType'); + const expireTimer = message.get('expireTimer'); + if (this.isPublic() && !this.isOpenGroupV2()) { throw new Error('Only opengroupv2 are supported now'); } @@ -561,6 +564,7 @@ export class ConversationModel extends Backbone.Model { identifier: id, timestamp: sentAt, attachments, + expirationType, expireTimer, preview: preview ? [preview] : [], quote, @@ -613,11 +617,14 @@ export class ConversationModel extends Backbone.Model { const destinationPubkey = new PubKey(destination); + // TODO check expiration types per different conversation setting + if (this.isPrivate()) { if (this.isMe()) { chatMessageParams.syncTarget = this.id; const chatMessageMe = new VisibleMessage(chatMessageParams); + // TODO handle sync messages for disappearing messages here await getMessageQueue().sendSyncMessage(chatMessageMe); return; } @@ -918,6 +925,7 @@ export class ConversationModel extends Backbone.Model { public async sendMessage(msg: SendMessageType) { const { attachments, body, groupInvitation, preview, quote } = msg; this.clearTypingTimers(); + const expirationType = this.get('expirationType'); const expireTimer = this.get('expireTimer'); const networkTimestamp = getNowWithNetworkOffset(); @@ -934,6 +942,7 @@ export class ConversationModel extends Backbone.Model { preview, attachments, sent_at: networkTimestamp, + expirationType, expireTimer, serverTimestamp: this.isPublic() ? networkTimestamp : undefined, groupInvitation, @@ -958,7 +967,7 @@ export class ConversationModel extends Backbone.Model { await this.commit(); void this.queueJob(async () => { - await this.sendMessageJob(messageModel, expireTimer); + await this.sendMessageJob(messageModel); }); } diff --git a/ts/receiver/queuedJob.ts b/ts/receiver/queuedJob.ts index 63fa522c4..b3f34bd15 100644 --- a/ts/receiver/queuedJob.ts +++ b/ts/receiver/queuedJob.ts @@ -1,7 +1,7 @@ import { queueAttachmentDownloads } from './attachments'; import { Quote } from './types'; -import _, { isEmpty, isEqual } from 'lodash'; +import _, { isEqual } from 'lodash'; import { getConversationController } from '../session/conversations'; import { ConversationModel } from '../models/conversation'; import { MessageModel, sliceQuoteText } from '../models/message'; @@ -366,7 +366,8 @@ export async function handleMessageJob( try { messageModel.set({ flags: regularDataMessage.flags }); // TODO remove 2 weeks after release - if (messageModel.isExpirationTimerUpdate() || !isEmpty(expireUpdate)) { + if (messageModel.isExpirationTimerUpdate()) { + // TODO account for lastDisappearingMessageChangeTimestamp const { expireTimer: oldExpireTimer } = regularDataMessage; const expirationType = expireUpdate.expirationType; const expireTimer = expireUpdate.expireTimer || oldExpireTimer; diff --git a/ts/session/messages/outgoing/visibleMessage/VisibleMessage.ts b/ts/session/messages/outgoing/visibleMessage/VisibleMessage.ts index 43e718dc5..1ee4701ac 100644 --- a/ts/session/messages/outgoing/visibleMessage/VisibleMessage.ts +++ b/ts/session/messages/outgoing/visibleMessage/VisibleMessage.ts @@ -1,9 +1,10 @@ import ByteBuffer from 'bytebuffer'; import { isEmpty } from 'lodash'; -import { DataMessage } from '..'; +import { ContentMessage } from '..'; import { SignalService } from '../../../../protobuf'; import { LokiProfile } from '../../../../types/Message'; import { Reaction } from '../../../../types/Reaction'; +import { DisappearingMessageType } from '../../../../util/expiringMessages'; import { MessageParams } from '../Message'; interface AttachmentPointerCommon { @@ -66,6 +67,7 @@ export interface VisibleMessageParams extends MessageParams { attachments?: Array; body?: string; quote?: Quote; + expirationType?: DisappearingMessageType; expireTimer?: number; lokiProfile?: LokiProfile; preview?: Array; @@ -73,7 +75,8 @@ export interface VisibleMessageParams extends MessageParams { syncTarget?: string; // undefined means it is not a synced message } -export class VisibleMessage extends DataMessage { +export class VisibleMessage extends ContentMessage { + public readonly expirationType?: DisappearingMessageType; public readonly expireTimer?: number; public readonly reaction?: Reaction; @@ -93,6 +96,7 @@ export class VisibleMessage extends DataMessage { this.attachments = params.attachments; this.body = params.body; this.quote = params.quote; + this.expirationType = params.expirationType; this.expireTimer = params.expireTimer; const profile = buildProfileForOutgoingMessage(params); @@ -105,6 +109,17 @@ export class VisibleMessage extends DataMessage { this.syncTarget = params.syncTarget; } + public contentProto(): SignalService.Content { + return new SignalService.Content({ + dataMessage: this.dataProto(), + expirationType: + this.expirationType === 'deleteAfterSend' + ? SignalService.Content.ExpirationType.DELETE_AFTER_SEND + : SignalService.Content.ExpirationType.DELETE_AFTER_READ, + expirationTimer: this.expireTimer, + }); + } + public dataProto(): SignalService.DataMessage { const dataMessage = new SignalService.DataMessage();