feat: legacy mode now works for 1-1 chats

pull/2660/head
William Grant 2 years ago
parent 03bc6706f6
commit 8117e631d0

@ -635,13 +635,15 @@ export class ConversationModel extends Backbone.Model<ConversationAttributes> {
if (this.isPrivate()) { if (this.isPrivate()) {
if (this.isMe()) { if (this.isMe()) {
if (!this.isDisappearingMode('deleteAfterSend')) { if (this.isDisappearingMode) {
// TODO legacy messages support will be removed in a future release
if (!this.isDisappearingMode('legacy') || !this.isDisappearingMode('deleteAfterSend')) {
return; return;
} }
}
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;
} }
@ -680,6 +682,11 @@ export class ConversationModel extends Backbone.Model<ConversationAttributes> {
expireTimer: chatMessageParams.expireTimer, expireTimer: chatMessageParams.expireTimer,
}); });
window.log.info(
`WIP: sendMessageJob() closedGroupVisibleMessage`,
closedGroupVisibleMessage
);
// we need the return await so that errors are caught in the catch {} // we need the return await so that errors are caught in the catch {}
await getMessageQueue().sendToGroup(closedGroupVisibleMessage); await getMessageQueue().sendToGroup(closedGroupVisibleMessage);
return; return;
@ -2231,11 +2238,11 @@ export class ConversationModel extends Backbone.Model<ConversationAttributes> {
} }
private isDisappearingMode(mode: DisappearingMessageType) { private isDisappearingMode(mode: DisappearingMessageType) {
// TODO support legacy mode // TODO legacy messages support will be removed in a future release
const success = const success =
this.get('expirationType') && this.get('expirationType') && this.get('expirationType') !== 'off' && mode === 'legacy'
this.get('expirationType') !== 'off' && ? this.get('expirationType') === 'legacy'
mode === 'deleteAfterRead' : mode === 'deleteAfterRead'
? this.get('expirationType') === 'deleteAfterRead' ? this.get('expirationType') === 'deleteAfterRead'
: this.get('expirationType') === 'deleteAfterSend'; : this.get('expirationType') === 'deleteAfterSend';

@ -1209,9 +1209,17 @@ export class MessageModel extends Backbone.Model<MessageAttributes> {
public markReadNoCommit(readAt: number) { public markReadNoCommit(readAt: number) {
this.set({ unread: 0 }); this.set({ unread: 0 });
if (this.get('expirationType') === 'deleteAfterRead' && this.get('expireTimer')) { const expirationType = this.get('expirationType');
// TODO legacy messages support will be removed in a future release
const convo = this.getConversation();
const isLegacyMode = convo && convo.isPrivate() && expirationType === 'legacy';
if ((isLegacyMode || expirationType === 'deleteAfterRead') && this.get('expireTimer')) {
this.set({ this.set({
expirationStartTimestamp: setExpirationStartTimestamp('deleteAfterRead', readAt), expirationStartTimestamp: setExpirationStartTimestamp(
'deleteAfterRead',
readAt,
isLegacyMode
),
}); });
} }
@ -1252,7 +1260,9 @@ export class MessageModel extends Backbone.Model<MessageAttributes> {
} }
const expiresAt = start + delta; const expiresAt = start + delta;
this.set({ expires_at: expiresAt }); this.set({
expires_at: expiresAt,
});
const id = this.get('id'); const id = this.get('id');
if (id) { if (id) {
await this.commit(); await this.commit();
@ -1263,7 +1273,12 @@ export class MessageModel extends Backbone.Model<MessageAttributes> {
sentAt: this.get('sent_at'), sentAt: this.get('sent_at'),
}); });
if (this.get('expirationType') === 'deleteAfterRead') { // TODO do we not need to do deleteAfterSend here?
// TODO legacy messages support will be removed in a future release
if (
this.get('expirationType') === 'legacy' ||
this.get('expirationType') === 'deleteAfterRead'
) {
const messageHash = this.get('messageHash'); const messageHash = this.get('messageHash');
if (messageHash) { if (messageHash) {
await expireMessageOnSnode(messageHash, this.get('expireTimer')); await expireMessageOnSnode(messageHash, this.get('expireTimer'));

@ -163,9 +163,17 @@ function updateReadStatus(message: MessageModel) {
if (message.isExpirationTimerUpdate()) { if (message.isExpirationTimerUpdate()) {
message.set({ unread: 0 }); message.set({ unread: 0 });
if (message.get('expirationType') === 'deleteAfterRead' && message.get('expireTimer')) { const expirationType = message.get('expirationType');
// TODO legacy messages support will be removed in a future release
const convo = message.getConversation();
const isLegacyMode = convo && convo.isPrivate() && expirationType === 'legacy';
if ((isLegacyMode || expirationType === 'deleteAfterRead') && message.get('expireTimer')) {
message.set({ message.set({
expirationStartTimestamp: setExpirationStartTimestamp('deleteAfterRead'), expirationStartTimestamp: setExpirationStartTimestamp(
'deleteAfterRead',
undefined,
isLegacyMode
),
}); });
} }
} }

@ -33,6 +33,7 @@ export class ExpirableMessage extends ContentMessage {
return this.expirationType; return this.expirationType;
} }
// TODO need to account for legacy messages here?
public ttl(): number { public ttl(): number {
switch (this.expirationType) { switch (this.expirationType) {
case 'deleteAfterSend': case 'deleteAfterSend':

@ -186,6 +186,11 @@ export class VisibleMessage extends ExpirableMessage {
dataMessage.timestamp = this.timestamp; dataMessage.timestamp = this.timestamp;
// TODO legacy messages support will be removed in a future release
if (this.expirationType === 'legacy' && this.expireTimer) {
dataMessage.expireTimer = this.expireTimer;
}
return dataMessage; return dataMessage;
} }

@ -122,12 +122,18 @@ async function handleMessageSentSuccess(
sentTo = _.union(sentTo, [sentMessage.device]); sentTo = _.union(sentTo, [sentMessage.device]);
const expirationType = fetchedMessage.get('expirationType');
// TODO legacy messages support will be removed in a future release
const convo = fetchedMessage.getConversation();
const isLegacyMode = convo && convo.isPrivate() && expirationType === 'legacy';
const markAsUnread = isLegacyMode || expirationType === 'deleteAfterRead';
fetchedMessage.set({ fetchedMessage.set({
sent_to: sentTo, sent_to: sentTo,
sent: true, sent: true,
sent_at: effectiveTimestamp, sent_at: effectiveTimestamp,
// TODO message status overrides this for some reason in the UI, message still disappears though // TODO message status overrides this for some reason in the UI, message still disappears though
unread: fetchedMessage.get('expirationType') === 'deleteAfterRead' ? 1 : 0, unread: markAsUnread ? 1 : 0,
}); });
if ( if (

@ -182,7 +182,9 @@ export type LocalizerKeys =
| 'timerModeRead' | 'timerModeRead'
| 'timerModeSent' | 'timerModeSent'
| 'youChangedTheTimer' | 'youChangedTheTimer'
| 'youChangedTheTimerLegacy'
| 'theyChangedTheTimer' | 'theyChangedTheTimer'
| 'theyChangedTheTimerLegacy'
| 'timerOption_0_seconds' | 'timerOption_0_seconds'
| 'timerOption_5_seconds' | 'timerOption_5_seconds'
| 'timerOption_10_seconds' | 'timerOption_10_seconds'

@ -208,14 +208,16 @@ export const ExpirationTimerOptions = {
export function setExpirationStartTimestamp( export function setExpirationStartTimestamp(
mode: DisappearingMessageType, mode: DisappearingMessageType,
timestamp?: number timestamp?: number,
isLegacyMode?: boolean
): number | undefined { ): number | undefined {
let expirationStartTimestamp: number | undefined = getNowWithNetworkOffset(); let expirationStartTimestamp: number | undefined = getNowWithNetworkOffset();
// TODO legacy messages support will be removed in a future release
if (timestamp) { if (timestamp) {
window.log.info( window.log.info(
`WIP: We compare 2 timestamps for a delete after ${ `WIP: We compare 2 timestamps for a disappear ${
mode === 'deleteAfterRead' ? 'read' : 'send' isLegacyMode ? 'legacy' : mode === 'deleteAfterRead' ? 'after read' : 'after send'
} message: \expirationStartTimestamp `, } message: \expirationStartTimestamp `,
new Date(expirationStartTimestamp).toLocaleTimeString(), new Date(expirationStartTimestamp).toLocaleTimeString(),
'\ntimestamp ', '\ntimestamp ',
@ -224,17 +226,18 @@ export function setExpirationStartTimestamp(
expirationStartTimestamp = Math.min(expirationStartTimestamp, timestamp); expirationStartTimestamp = Math.min(expirationStartTimestamp, timestamp);
} }
// TODO legacy messages support will be removed in a future release
if (mode === 'deleteAfterRead') { if (mode === 'deleteAfterRead') {
window.log.info( window.log.info(
`WIP: We set the start timestamp for a delete after read message to ${new Date( `WIP: We set the start timestamp for a ${
expirationStartTimestamp isLegacyMode ? 'legacy ' : ''
).toLocaleTimeString()}` }delete after read message to ${new Date(expirationStartTimestamp).toLocaleTimeString()}`
); );
} else if (mode === 'deleteAfterSend') { } else if (mode === 'deleteAfterSend') {
window.log.info( window.log.info(
`WIP: We set the start timestamp for a delete after send message to ${new Date( `WIP: We set the start timestamp for a ${
expirationStartTimestamp isLegacyMode ? 'legacy ' : ''
).toLocaleTimeString()}` }delete after send message to ${new Date(expirationStartTimestamp).toLocaleTimeString()}`
); );
} else if (mode === 'off') { } else if (mode === 'off') {
window.log.info(`WIP: Disappearing message mode "${mode}" set. We can safely ignore this.`); window.log.info(`WIP: Disappearing message mode "${mode}" set. We can safely ignore this.`);

Loading…
Cancel
Save