feat: improved syncing of timers for disappear after send

pull/2660/head
William Grant 3 years ago
parent 4d92500b60
commit 996d204dc8

@ -242,6 +242,10 @@ export async function handleSwarmDataMessage(
sentAt: sentAtTimestamp, sentAt: sentAtTimestamp,
}); });
if (isSyncedMessage) {
// TODO handle sync messages separately
console.log(`WIP: Sync Message dropping`);
} else {
if (expireUpdate.expirationType === 'deleteAfterSend') { if (expireUpdate.expirationType === 'deleteAfterSend') {
const expirationStartTimestamp = setExpirationStartTimestamp( const expirationStartTimestamp = setExpirationStartTimestamp(
msgModel, msgModel,
@ -255,6 +259,7 @@ export async function handleSwarmDataMessage(
msgModel.get('sent_at') msgModel.get('sent_at')
); );
} }
}
await handleSwarmMessage( await handleSwarmMessage(
msgModel, msgModel,

@ -119,8 +119,17 @@ async function handleMessageSentSuccess(
window?.log?.warn('Got an error while trying to sendSyncMessage():', e); window?.log?.warn('Got an error while trying to sendSyncMessage():', e);
} }
} }
if (fetchedMessage.get('expirationType')) {
const expirationStartTimestamp = setExpirationStartTimestamp(
fetchedMessage,
fetchedMessage.get('expirationType')!,
effectiveTimestamp
);
fetchedMessage.set('expirationStartTimestamp', expirationStartTimestamp);
}
} else if (shouldMarkMessageAsSynced) { } else if (shouldMarkMessageAsSynced) {
fetchedMessage.set({ synced: true }); fetchedMessage.set({ synced: true });
// TODO handle sync messages separately
} }
sentTo = _.union(sentTo, [sentMessage.device]); sentTo = _.union(sentTo, [sentMessage.device]);
@ -131,15 +140,6 @@ async function handleMessageSentSuccess(
sent_at: effectiveTimestamp, sent_at: effectiveTimestamp,
}); });
if (fetchedMessage.get('expirationType')) {
const expirationStartTimestamp = setExpirationStartTimestamp(
fetchedMessage,
fetchedMessage.get('expirationType')!,
effectiveTimestamp
);
fetchedMessage.set('expirationStartTimestamp', expirationStartTimestamp);
}
await fetchedMessage.commit(); await fetchedMessage.commit();
fetchedMessage.getConversation()?.updateLastMessage(); fetchedMessage.getConversation()?.updateLastMessage();
} }
@ -165,21 +165,16 @@ async function handleMessageSentFailure(
if (isOurDevice && !fetchedMessage.get('sync')) { if (isOurDevice && !fetchedMessage.get('sync')) {
fetchedMessage.set({ sentSync: false }); fetchedMessage.set({ sentSync: false });
} }
}
// TODO Need to handle messages failing to send differently? if (fetchedMessage.get('expirationType')) {
if (fetchedMessage.get('expirationType') === 'deleteAfterSend') {
const expirationStartTimestamp = setExpirationStartTimestamp( const expirationStartTimestamp = setExpirationStartTimestamp(
fetchedMessage, fetchedMessage,
'deleteAfterSend' fetchedMessage.get('expirationType')!
); );
fetchedMessage.set('expirationStartTimestamp', expirationStartTimestamp); fetchedMessage.set('expirationStartTimestamp', expirationStartTimestamp);
} }
fetchedMessage.set({
expirationStartTimestamp: Date.now(),
});
}
// always mark the message as sent. // always mark the message as sent.
// the fact that we have errors on the sent is based on the saveErrors() // the fact that we have errors on the sent is based on the saveErrors()
fetchedMessage.set({ fetchedMessage.set({

@ -8,6 +8,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'; import { MessageModel } from '../models/message';
import { getNowWithNetworkOffset } from '../session/apis/snode_api/SNodeAPI';
// 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'];
@ -201,15 +202,11 @@ export function setExpirationStartTimestamp(
mode: DisappearingMessageType, mode: DisappearingMessageType,
timestamp?: number timestamp?: number
) { ) {
let expirationStartTimestamp = Date.now(); let expirationStartTimestamp = getNowWithNetworkOffset();
if (timestamp) { if (timestamp) {
expirationStartTimestamp = Math.min(Date.now(), timestamp); expirationStartTimestamp = Math.max(getNowWithNetworkOffset(), timestamp);
window.log.info( message.set('expirationStartTimestamp', expirationStartTimestamp);
`WIP: setExpirationStartTimestamp has a timestamp, comparing`,
Date.now(),
timestamp
);
} }
if (mode === 'deleteAfterRead') { if (mode === 'deleteAfterRead') {

Loading…
Cancel
Save