feat: started consolidating send and receive dm logic.

updated in parts but haven't test what happens
pull/2660/head
William Grant 2 years ago
parent 13f091eff3
commit 22e02633a9

@ -6,22 +6,37 @@ import { NotificationBubble } from './message/message-item/notification-bubble/N
import { ReadableMessage } from './message/message-item/ReadableMessage'; import { ReadableMessage } from './message/message-item/ReadableMessage';
export const TimerNotification = (props: PropsForExpirationTimer) => { export const TimerNotification = (props: PropsForExpirationTimer) => {
const { messageId, receivedAt, isUnread, pubkey, profileName, timespan, type, disabled } = props; const {
messageId,
receivedAt,
isUnread,
pubkey,
profileName,
expirationType,
timespan,
type,
disabled,
} = props;
const contact = profileName || pubkey; const contact = profileName || pubkey;
const mode =
expirationType === 'deleteAfterRead'
? window.i18n('timerModeRead')
: window.i18n('timerModeSent');
let textToRender: string | undefined; let textToRender: string | undefined;
switch (type) { switch (type) {
case 'fromOther': case 'fromOther':
textToRender = disabled textToRender = disabled
? window.i18n('disabledDisappearingMessages', [contact, timespan]) ? window.i18n('disabledDisappearingMessages', [contact, timespan])
: window.i18n('theyChangedTheTimer', [contact, timespan]); : window.i18n('theyChangedTheTimer', [contact, timespan, mode]);
break; break;
case 'fromMe': case 'fromMe':
textToRender = disabled textToRender = disabled
? window.i18n('youDisabledDisappearingMessages') ? window.i18n('youDisabledDisappearingMessages')
: window.i18n('youChangedTheTimer', [timespan]); : window.i18n('youChangedTheTimer', [timespan, mode]);
break; break;
// TODO update synced control message?
case 'fromSync': case 'fromSync':
textToRender = disabled textToRender = disabled
? window.i18n('disappearingMessagesDisabled') ? window.i18n('disappearingMessagesDisabled')

@ -80,7 +80,7 @@ import {
loadPreviewData, loadPreviewData,
loadQuoteData, loadQuoteData,
} from '../types/MessageAttachment'; } from '../types/MessageAttachment';
import { ExpirationTimerOptions } from '../util/expiringMessages'; import { ExpirationTimerOptions, setExpirationStartTimestamp } from '../util/expiringMessages';
import { Notifications } from '../util/notifications'; import { Notifications } from '../util/notifications';
import { Storage } from '../util/storage'; import { Storage } from '../util/storage';
import { LinkPreviews } from '../util/linkPreviews'; import { LinkPreviews } from '../util/linkPreviews';
@ -277,7 +277,7 @@ export class MessageModel extends Backbone.Model<MessageAttributes> {
return null; return null;
} }
const { expireTimer, fromSync, source } = timerUpdate; const { expirationType, expireTimer, fromSync, source } = timerUpdate;
const timespan = ExpirationTimerOptions.getName(expireTimer || 0); const timespan = ExpirationTimerOptions.getName(expireTimer || 0);
const disabled = !expireTimer; const disabled = !expireTimer;
@ -289,6 +289,7 @@ export class MessageModel extends Backbone.Model<MessageAttributes> {
messageId: this.id, messageId: this.id,
receivedAt: this.get('received_at'), receivedAt: this.get('received_at'),
isUnread: this.isUnread(), isUnread: this.isUnread(),
expirationType: expirationType || 'off',
}; };
return basicProps; return basicProps;
@ -457,6 +458,7 @@ export class MessageModel extends Backbone.Model<MessageAttributes> {
// tslint:disable-next-line: cyclomatic-complexity // tslint:disable-next-line: cyclomatic-complexity
public getPropsForMessage(options: any = {}): PropsForMessageWithoutConvoProps { public getPropsForMessage(options: any = {}): PropsForMessageWithoutConvoProps {
const sender = this.getSource(); const sender = this.getSource();
const expirationType = this.get('expirationType');
const expirationLength = this.get('expireTimer') * 1000; const expirationLength = this.get('expireTimer') * 1000;
const expireTimerStart = this.get('expirationStartTimestamp'); const expireTimerStart = this.get('expirationStartTimestamp');
const expirationTimestamp = const expirationTimestamp =
@ -491,6 +493,9 @@ export class MessageModel extends Backbone.Model<MessageAttributes> {
if (this.get('serverId')) { if (this.get('serverId')) {
props.serverId = this.get('serverId'); props.serverId = this.get('serverId');
} }
if (expirationType) {
props.expirationType = expirationType;
}
if (expirationLength) { if (expirationLength) {
props.expirationLength = expirationLength; props.expirationLength = expirationLength;
} }
@ -1162,9 +1167,12 @@ export class MessageModel extends Backbone.Model<MessageAttributes> {
public markReadNoCommit(readAt: number) { public markReadNoCommit(readAt: number) {
this.set({ unread: 0 }); this.set({ unread: 0 });
// TODO This logic needs to depend no the dm mode if (
if (this.get('expireTimer') && !this.get('expirationStartTimestamp')) { this.get('expirationType') === 'deleteAfterRead' &&
const expirationStartTimestamp = Math.min(Date.now(), readAt || Date.now()); this.get('expireTimer') &&
!this.get('expirationStartTimestamp')
) {
const expirationStartTimestamp = setExpirationStartTimestamp(this, 'deleteAfterRead', readAt);
this.set({ expirationStartTimestamp }); this.set({ expirationStartTimestamp });
} }

@ -23,6 +23,7 @@ import { toLogFormat } from '../types/attachments/Errors';
import { ConversationTypeEnum } from '../models/conversationAttributes'; import { ConversationTypeEnum } from '../models/conversationAttributes';
import { Reactions } from '../util/reactions'; import { Reactions } from '../util/reactions';
import { Action, Reaction } from '../types/Reaction'; import { Action, Reaction } from '../types/Reaction';
import { setExpirationStartTimestamp } from '../util/expiringMessages';
function cleanAttachment(attachment: any) { function cleanAttachment(attachment: any) {
return { return {
@ -241,6 +242,15 @@ export async function handleSwarmDataMessage(
sentAt: sentAtTimestamp, sentAt: sentAtTimestamp,
}); });
if (expireUpdate.expirationType === 'deleteAfterSend') {
const expirationStartTimestamp = setExpirationStartTimestamp(
msgModel,
'deleteAfterSend',
msgModel.get('sent_at')
);
msgModel.set('expirationStartTimestamp', expirationStartTimestamp);
}
await handleSwarmMessage( await handleSwarmMessage(
msgModel, msgModel,
messageHash, messageHash,

@ -1,6 +1,7 @@
import _ from 'lodash'; import _ from 'lodash';
import { Data } from '../../data/data'; import { Data } from '../../data/data';
import { SignalService } from '../../protobuf'; import { SignalService } from '../../protobuf';
import { setExpirationStartTimestamp } from '../../util/expiringMessages';
import { PnServer } from '../apis/push_notification_api'; import { PnServer } from '../apis/push_notification_api';
import { OpenGroupVisibleMessage } from '../messages/outgoing/visibleMessage/OpenGroupVisibleMessage'; import { OpenGroupVisibleMessage } from '../messages/outgoing/visibleMessage/OpenGroupVisibleMessage';
import { RawMessage } from '../types'; import { RawMessage } from '../types';
@ -124,10 +125,15 @@ async function handleMessageSentSuccess(
sentTo = _.union(sentTo, [sentMessage.device]); sentTo = _.union(sentTo, [sentMessage.device]);
if (fetchedMessage.get('expirationType') === 'deleteAfterSend') {
const expirationStartTimestamp = setExpirationStartTimestamp(fetchedMessage, 'deleteAfterSend');
fetchedMessage.set('expirationStartTimestamp', expirationStartTimestamp);
}
fetchedMessage.set({ fetchedMessage.set({
sent_to: sentTo, sent_to: sentTo,
sent: true, sent: true,
expirationStartTimestamp: Date.now(), // TODO do we need to use this for the timestamp for the delete after send logic
sent_at: effectiveTimestamp, sent_at: effectiveTimestamp,
}); });
@ -157,6 +163,15 @@ async function handleMessageSentFailure(
fetchedMessage.set({ sentSync: false }); fetchedMessage.set({ sentSync: false });
} }
// TODO Need to handle messages failing to send differently?
if (fetchedMessage.get('expirationType') === 'deleteAfterSend') {
const expirationStartTimestamp = setExpirationStartTimestamp(
fetchedMessage,
'deleteAfterSend'
);
fetchedMessage.set('expirationStartTimestamp', expirationStartTimestamp);
}
fetchedMessage.set({ fetchedMessage.set({
expirationStartTimestamp: Date.now(), expirationStartTimestamp: Date.now(),
}); });

@ -7,6 +7,7 @@ import { initWallClockListener } from './wallClockListener';
import { Data } from '../data/data'; import { Data } from '../data/data';
import { getConversationController } from '../session/conversations'; import { getConversationController } from '../session/conversations';
import { MessageModel } from '../models/message';
// TODO Might need to be improved by using an enum // TODO Might need to be improved by using an enum
export const DisappearingMessageMode = ['deleteAfterRead', 'deleteAfterSend']; export const DisappearingMessageMode = ['deleteAfterRead', 'deleteAfterSend'];
@ -194,3 +195,26 @@ export const ExpirationTimerOptions = {
initExpiringMessageListener, initExpiringMessageListener,
getTimerSecondsWithName, getTimerSecondsWithName,
}; };
export function setExpirationStartTimestamp(
message: MessageModel,
mode: DisappearingMessageType,
timestamp?: number
) {
let expirationStartTimestamp = Date.now();
if (timestamp) {
expirationStartTimestamp = Math.min(expirationStartTimestamp, timestamp);
}
if (mode === 'deleteAfterRead') {
window.log.info(`WIP: we set the start timetamp for a delete after read message`, message);
} else if (mode === 'deleteAfterSend') {
window.log.info(`WIP: we set the start timetamp for a delete after send message`, message);
} else {
console.log(`WIP: Invalid disappearing message mode set, ignoring this message`, message);
return;
}
return expirationStartTimestamp;
}

@ -3,6 +3,7 @@ import { MessageCollection } from '../models/message';
import { Data } from '../data/data'; import { Data } from '../data/data';
import { getConversationController } from '../session/conversations'; import { getConversationController } from '../session/conversations';
import { setExpirationStartTimestamp } from './expiringMessages';
async function getTargetMessage(reader: string, messages: MessageCollection) { async function getTargetMessage(reader: string, messages: MessageCollection) {
if (messages.length === 0) { if (messages.length === 0) {
@ -45,7 +46,14 @@ async function onReadReceipt(receipt: { source: string; timestamp: number; readA
// readBy is only used for private conversations // readBy is only used for private conversations
// we do not care of who read it. If the length is > 0 , it is read and false otherwise // we do not care of who read it. If the length is > 0 , it is read and false otherwise
let readBy = message.get('read_by') || []; let readBy = message.get('read_by') || [];
const expirationStartTimestamp = message.get('expirationStartTimestamp'); let expirationStartTimestamp = undefined;
if (message.get('expirationType') === 'deleteAfterRead') {
expirationStartTimestamp = setExpirationStartTimestamp(
message,
'deleteAfterRead',
message.get('expirationStartTimestamp')
);
}
if (!readBy.length) { if (!readBy.length) {
readBy.push(receipt.source); readBy.push(receipt.source);
@ -53,9 +61,10 @@ async function onReadReceipt(receipt: { source: string; timestamp: number; readA
if (readBy.length > 1) { if (readBy.length > 1) {
readBy = readBy.slice(0, 1); readBy = readBy.slice(0, 1);
} }
message.set({ message.set({
read_by: readBy, read_by: readBy,
expirationStartTimestamp: expirationStartTimestamp || Date.now(), expirationStartTimestamp,
sent: true, sent: true,
}); });

Loading…
Cancel
Save