feat: disappearing after send is not working correctly

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

@ -541,7 +541,7 @@ export class ConversationModel extends Backbone.Model<ConversationAttributes> {
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<ConversationAttributes> {
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<ConversationAttributes> {
identifier: id,
timestamp: sentAt,
attachments,
expirationType,
expireTimer,
preview: preview ? [preview] : [],
quote,
@ -613,11 +617,14 @@ export class ConversationModel extends Backbone.Model<ConversationAttributes> {
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<ConversationAttributes> {
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<ConversationAttributes> {
preview,
attachments,
sent_at: networkTimestamp,
expirationType,
expireTimer,
serverTimestamp: this.isPublic() ? networkTimestamp : undefined,
groupInvitation,
@ -958,7 +967,7 @@ export class ConversationModel extends Backbone.Model<ConversationAttributes> {
await this.commit();
void this.queueJob(async () => {
await this.sendMessageJob(messageModel, expireTimer);
await this.sendMessageJob(messageModel);
});
}

@ -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;

@ -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<AttachmentPointerWithUrl>;
body?: string;
quote?: Quote;
expirationType?: DisappearingMessageType;
expireTimer?: number;
lokiProfile?: LokiProfile;
preview?: Array<PreviewWithAttachmentUrl>;
@ -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();

Loading…
Cancel
Save