Set disappearing check timer reliably - on all message saves
This commit is contained in:
parent
9dd756f96a
commit
22613c8cc4
6 changed files with 39 additions and 31 deletions
|
@ -11,28 +11,35 @@
|
|||
window.Whisper = window.Whisper || {};
|
||||
|
||||
async function destroyExpiredMessages() {
|
||||
const messages = await window.Signal.Data.getExpiredMessages({
|
||||
MessageCollection: Whisper.MessageCollection,
|
||||
});
|
||||
try {
|
||||
const messages = await window.Signal.Data.getExpiredMessages({
|
||||
MessageCollection: Whisper.MessageCollection,
|
||||
});
|
||||
|
||||
await Promise.all(
|
||||
messages.map(async message => {
|
||||
window.log.info('Message expired', {
|
||||
sentAt: message.get('sent_at'),
|
||||
});
|
||||
await Promise.all(
|
||||
messages.map(async message => {
|
||||
window.log.info('Message expired', {
|
||||
sentAt: message.get('sent_at'),
|
||||
});
|
||||
|
||||
// We delete after the trigger to allow the conversation time to process
|
||||
// the expiration before the message is removed from the database.
|
||||
await window.Signal.Data.removeMessage(message.id, {
|
||||
Message: Whisper.Message,
|
||||
});
|
||||
// We delete after the trigger to allow the conversation time to process
|
||||
// the expiration before the message is removed from the database.
|
||||
await window.Signal.Data.removeMessage(message.id, {
|
||||
Message: Whisper.Message,
|
||||
});
|
||||
|
||||
const conversation = message.getConversation();
|
||||
if (conversation) {
|
||||
conversation.trigger('expired', message);
|
||||
}
|
||||
})
|
||||
);
|
||||
const conversation = message.getConversation();
|
||||
if (conversation) {
|
||||
conversation.trigger('expired', message);
|
||||
}
|
||||
})
|
||||
);
|
||||
} catch (error) {
|
||||
window.log.error(
|
||||
'destroyExpiredMessages: Error deleting expired messages',
|
||||
error && error.stack ? error.stack : error
|
||||
);
|
||||
}
|
||||
|
||||
checkExpiringMessages();
|
||||
}
|
||||
|
@ -50,6 +57,7 @@
|
|||
}
|
||||
|
||||
const expiresAt = next.get('expires_at');
|
||||
Whisper.ExpiringMessagesListener.nextExpiration = expiresAt;
|
||||
window.log.info('next message expires', new Date(expiresAt).toISOString());
|
||||
|
||||
let wait = expiresAt - Date.now();
|
||||
|
@ -73,6 +81,7 @@
|
|||
);
|
||||
|
||||
Whisper.ExpiringMessagesListener = {
|
||||
nextExpiration: null,
|
||||
init(events) {
|
||||
checkExpiringMessages();
|
||||
events.on('timetravel', throttledCheckExpiringMessages);
|
||||
|
|
|
@ -1304,7 +1304,6 @@
|
|||
});
|
||||
}
|
||||
|
||||
Whisper.ExpiringMessagesListener.update();
|
||||
window.log.info('Set message expiration', {
|
||||
expiresAt,
|
||||
sentAt: this.get('sent_at'),
|
||||
|
@ -1313,6 +1312,9 @@
|
|||
},
|
||||
});
|
||||
|
||||
Whisper.Message.refreshExpirationTimer = () =>
|
||||
Whisper.ExpiringMessagesListener.update();
|
||||
|
||||
Whisper.MessageCollection = Backbone.Collection.extend({
|
||||
model: Whisper.Message,
|
||||
// Keeping this for legacy upgrade pre-migrate to SQLCipher
|
||||
|
|
|
@ -1003,13 +1003,9 @@ async function saveAllMessages(db, rawMessages) {
|
|||
|
||||
const { conversationId } = messages[0];
|
||||
|
||||
for (let index = 0, max = messages.length; index < max; index += 1) {
|
||||
// Yes, we really want to do these in order
|
||||
// eslint-disable-next-line no-await-in-loop
|
||||
await window.Signal.Data.saveMessage(messages[index], {
|
||||
forceSave: true,
|
||||
});
|
||||
}
|
||||
await window.Signal.Data.saveMessages(messages, {
|
||||
forceSave: true,
|
||||
});
|
||||
|
||||
window.log.info(
|
||||
'Saved',
|
||||
|
|
|
@ -201,8 +201,9 @@ async function removeDB() {
|
|||
await channels.removeDB();
|
||||
}
|
||||
|
||||
async function saveMessage(data, { forceSave } = {}) {
|
||||
async function saveMessage(data, { forceSave, Message } = {}) {
|
||||
const id = await channels.saveMessage(_cleanData(data), { forceSave });
|
||||
Message.refreshExpirationTimer();
|
||||
return id;
|
||||
}
|
||||
|
||||
|
|
|
@ -1,5 +1,5 @@
|
|||
/* eslint-env node */
|
||||
/* global log, Signal */
|
||||
/* global log, Signal, Whisper */
|
||||
|
||||
const fs = require('fs-extra');
|
||||
const path = require('path');
|
||||
|
@ -59,7 +59,7 @@ exports.createConversation = async ({
|
|||
await sleep(index * 100);
|
||||
log.info(`Create message ${index + 1}`);
|
||||
const message = await createRandomMessage({ conversationId });
|
||||
return Signal.Data.saveMessage(message);
|
||||
return Signal.Data.saveMessage(message, { Message: Whisper.Message });
|
||||
})
|
||||
);
|
||||
};
|
||||
|
|
|
@ -40,7 +40,7 @@
|
|||
reset() {
|
||||
return Promise.all([
|
||||
Whisper.Database.clear(),
|
||||
Window.Signal.Data.removeAll(),
|
||||
window.Signal.Data.removeAll(),
|
||||
]);
|
||||
},
|
||||
};
|
||||
|
|
Loading…
Reference in a new issue