feat: disappearing after send is not working correctly

pull/2660/head
William Grant 3 years ago
parent 22e02633a9
commit ee4aa333fc

@ -541,7 +541,7 @@ export class ConversationModel extends Backbone.Model<ConversationAttributes> {
return getOpenGroupV2FromConversationId(this.id); return getOpenGroupV2FromConversationId(this.id);
} }
public async sendMessageJob(message: MessageModel, expireTimer: number | undefined) { public async sendMessageJob(message: MessageModel) {
try { try {
const { body, attachments, preview, quote, fileIdsToLink } = await message.uploadData(); const { body, attachments, preview, quote, fileIdsToLink } = await message.uploadData();
const { id } = message; const { id } = message;
@ -552,6 +552,9 @@ export class ConversationModel extends Backbone.Model<ConversationAttributes> {
throw new Error('sendMessageJob() sent_at must be set.'); throw new Error('sendMessageJob() sent_at must be set.');
} }
const expirationType = message.get('expirationType');
const expireTimer = message.get('expireTimer');
if (this.isPublic() && !this.isOpenGroupV2()) { if (this.isPublic() && !this.isOpenGroupV2()) {
throw new Error('Only opengroupv2 are supported now'); throw new Error('Only opengroupv2 are supported now');
} }
@ -561,6 +564,7 @@ export class ConversationModel extends Backbone.Model<ConversationAttributes> {
identifier: id, identifier: id,
timestamp: sentAt, timestamp: sentAt,
attachments, attachments,
expirationType,
expireTimer, expireTimer,
preview: preview ? [preview] : [], preview: preview ? [preview] : [],
quote, quote,
@ -613,11 +617,14 @@ export class ConversationModel extends Backbone.Model<ConversationAttributes> {
const destinationPubkey = new PubKey(destination); const destinationPubkey = new PubKey(destination);
// TODO check expiration types per different conversation setting
if (this.isPrivate()) { if (this.isPrivate()) {
if (this.isMe()) { if (this.isMe()) {
chatMessageParams.syncTarget = this.id; chatMessageParams.syncTarget = this.id;
const chatMessageMe = new VisibleMessage(chatMessageParams); const chatMessageMe = new VisibleMessage(chatMessageParams);
// TODO handle sync messages for disappearing messages here
await getMessageQueue().sendSyncMessage(chatMessageMe); await getMessageQueue().sendSyncMessage(chatMessageMe);
return; return;
} }
@ -918,6 +925,7 @@ export class ConversationModel extends Backbone.Model<ConversationAttributes> {
public async sendMessage(msg: SendMessageType) { public async sendMessage(msg: SendMessageType) {
const { attachments, body, groupInvitation, preview, quote } = msg; const { attachments, body, groupInvitation, preview, quote } = msg;
this.clearTypingTimers(); this.clearTypingTimers();
const expirationType = this.get('expirationType');
const expireTimer = this.get('expireTimer'); const expireTimer = this.get('expireTimer');
const networkTimestamp = getNowWithNetworkOffset(); const networkTimestamp = getNowWithNetworkOffset();
@ -934,6 +942,7 @@ export class ConversationModel extends Backbone.Model<ConversationAttributes> {
preview, preview,
attachments, attachments,
sent_at: networkTimestamp, sent_at: networkTimestamp,
expirationType,
expireTimer, expireTimer,
serverTimestamp: this.isPublic() ? networkTimestamp : undefined, serverTimestamp: this.isPublic() ? networkTimestamp : undefined,
groupInvitation, groupInvitation,
@ -958,7 +967,7 @@ export class ConversationModel extends Backbone.Model<ConversationAttributes> {
await this.commit(); await this.commit();
void this.queueJob(async () => { void this.queueJob(async () => {
await this.sendMessageJob(messageModel, expireTimer); await this.sendMessageJob(messageModel);
}); });
} }

@ -1,7 +1,7 @@
import { queueAttachmentDownloads } from './attachments'; import { queueAttachmentDownloads } from './attachments';
import { Quote } from './types'; import { Quote } from './types';
import _, { isEmpty, isEqual } from 'lodash'; import _, { isEqual } from 'lodash';
import { getConversationController } from '../session/conversations'; import { getConversationController } from '../session/conversations';
import { ConversationModel } from '../models/conversation'; import { ConversationModel } from '../models/conversation';
import { MessageModel, sliceQuoteText } from '../models/message'; import { MessageModel, sliceQuoteText } from '../models/message';
@ -366,7 +366,8 @@ export async function handleMessageJob(
try { try {
messageModel.set({ flags: regularDataMessage.flags }); messageModel.set({ flags: regularDataMessage.flags });
// TODO remove 2 weeks after release // TODO remove 2 weeks after release
if (messageModel.isExpirationTimerUpdate() || !isEmpty(expireUpdate)) { if (messageModel.isExpirationTimerUpdate()) {
// TODO account for lastDisappearingMessageChangeTimestamp
const { expireTimer: oldExpireTimer } = regularDataMessage; const { expireTimer: oldExpireTimer } = regularDataMessage;
const expirationType = expireUpdate.expirationType; const expirationType = expireUpdate.expirationType;
const expireTimer = expireUpdate.expireTimer || oldExpireTimer; const expireTimer = expireUpdate.expireTimer || oldExpireTimer;

@ -1,9 +1,10 @@
import ByteBuffer from 'bytebuffer'; import ByteBuffer from 'bytebuffer';
import { isEmpty } from 'lodash'; import { isEmpty } from 'lodash';
import { DataMessage } from '..'; import { ContentMessage } from '..';
import { SignalService } from '../../../../protobuf'; import { SignalService } from '../../../../protobuf';
import { LokiProfile } from '../../../../types/Message'; import { LokiProfile } from '../../../../types/Message';
import { Reaction } from '../../../../types/Reaction'; import { Reaction } from '../../../../types/Reaction';
import { DisappearingMessageType } from '../../../../util/expiringMessages';
import { MessageParams } from '../Message'; import { MessageParams } from '../Message';
interface AttachmentPointerCommon { interface AttachmentPointerCommon {
@ -66,6 +67,7 @@ export interface VisibleMessageParams extends MessageParams {
attachments?: Array<AttachmentPointerWithUrl>; attachments?: Array<AttachmentPointerWithUrl>;
body?: string; body?: string;
quote?: Quote; quote?: Quote;
expirationType?: DisappearingMessageType;
expireTimer?: number; expireTimer?: number;
lokiProfile?: LokiProfile; lokiProfile?: LokiProfile;
preview?: Array<PreviewWithAttachmentUrl>; preview?: Array<PreviewWithAttachmentUrl>;
@ -73,7 +75,8 @@ export interface VisibleMessageParams extends MessageParams {
syncTarget?: string; // undefined means it is not a synced message 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 expireTimer?: number;
public readonly reaction?: Reaction; public readonly reaction?: Reaction;
@ -93,6 +96,7 @@ export class VisibleMessage extends DataMessage {
this.attachments = params.attachments; this.attachments = params.attachments;
this.body = params.body; this.body = params.body;
this.quote = params.quote; this.quote = params.quote;
this.expirationType = params.expirationType;
this.expireTimer = params.expireTimer; this.expireTimer = params.expireTimer;
const profile = buildProfileForOutgoingMessage(params); const profile = buildProfileForOutgoingMessage(params);
@ -105,6 +109,17 @@ export class VisibleMessage extends DataMessage {
this.syncTarget = params.syncTarget; 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 { public dataProto(): SignalService.DataMessage {
const dataMessage = new SignalService.DataMessage(); const dataMessage = new SignalService.DataMessage();

Loading…
Cancel
Save