Remove any unsent messages when app is started.
This commit is contained in:
parent
ece266fffd
commit
4148628e70
15
app/sql.js
15
app/sql.js
|
@ -96,6 +96,7 @@ module.exports = {
|
|||
getMessageById,
|
||||
getAllMessages,
|
||||
getAllMessageIds,
|
||||
getAllUnsentMessages,
|
||||
getMessagesBySentAt,
|
||||
getExpiredMessages,
|
||||
getOutgoingWithoutExpiresAt,
|
||||
|
@ -203,6 +204,7 @@ async function updateToSchemaVersion1(currentVersion, instance) {
|
|||
|
||||
unread INTEGER,
|
||||
expires_at INTEGER,
|
||||
sent BOOLEAN,
|
||||
sent_at INTEGER,
|
||||
schemaVersion INTEGER,
|
||||
conversationId STRING,
|
||||
|
@ -1115,6 +1117,7 @@ async function saveMessage(data, { forceSave } = {}) {
|
|||
received_at,
|
||||
schemaVersion,
|
||||
// eslint-disable-next-line camelcase
|
||||
sent,
|
||||
sent_at,
|
||||
source,
|
||||
sourceDevice,
|
||||
|
@ -1137,6 +1140,7 @@ async function saveMessage(data, { forceSave } = {}) {
|
|||
$hasVisualMediaAttachments: hasVisualMediaAttachments,
|
||||
$received_at: received_at,
|
||||
$schemaVersion: schemaVersion,
|
||||
$sent: sent,
|
||||
$sent_at: sent_at,
|
||||
$source: source,
|
||||
$sourceDevice: sourceDevice,
|
||||
|
@ -1158,6 +1162,7 @@ async function saveMessage(data, { forceSave } = {}) {
|
|||
id = $id,
|
||||
received_at = $received_at,
|
||||
schemaVersion = $schemaVersion,
|
||||
sent = $sent,
|
||||
sent_at = $sent_at,
|
||||
source = $source,
|
||||
sourceDevice = $sourceDevice,
|
||||
|
@ -1189,6 +1194,7 @@ async function saveMessage(data, { forceSave } = {}) {
|
|||
hasVisualMediaAttachments,
|
||||
received_at,
|
||||
schemaVersion,
|
||||
sent,
|
||||
sent_at,
|
||||
source,
|
||||
sourceDevice,
|
||||
|
@ -1207,6 +1213,7 @@ async function saveMessage(data, { forceSave } = {}) {
|
|||
$hasVisualMediaAttachments,
|
||||
$received_at,
|
||||
$schemaVersion,
|
||||
$sent,
|
||||
$sent_at,
|
||||
$source,
|
||||
$sourceDevice,
|
||||
|
@ -1293,6 +1300,14 @@ async function getMessageBySender({ source, sourceDevice, sent_at }) {
|
|||
return map(rows, row => jsonToObject(row.json));
|
||||
}
|
||||
|
||||
async function getAllUnsentMessages() {
|
||||
const rows = await db.all(`
|
||||
SELECT json FROM messages WHERE NOT sent
|
||||
ORDER BY sent_at DESC;
|
||||
`);
|
||||
return map(rows, row => jsonToObject(row.json));
|
||||
}
|
||||
|
||||
async function getUnreadByConversation(conversationId) {
|
||||
const rows = await db.all(
|
||||
`SELECT json FROM messages WHERE
|
||||
|
|
|
@ -318,11 +318,14 @@
|
|||
Views.Initialization.setMessage(window.i18n('optimizingApplication'));
|
||||
|
||||
window.log.info('Cleanup: starting...');
|
||||
const messagesForCleanup = await window.Signal.Data.getOutgoingWithoutExpiresAt(
|
||||
{
|
||||
MessageCollection: Whisper.MessageCollection,
|
||||
}
|
||||
);
|
||||
const results = await Promise.all([
|
||||
window.Signal.Data.getOutgoingWithoutExpiresAt({ MessageCollection: Whisper.MessageCollection }),
|
||||
window.Signal.Data.getAllUnsentMessages({ MessageCollection: Whisper.MessageCollection }),
|
||||
]);
|
||||
|
||||
// Combine the models
|
||||
const messagesForCleanup = results.reduce((array, current) => array.concat(current.toArray()), []);
|
||||
|
||||
window.log.info(
|
||||
`Cleanup: Found ${messagesForCleanup.length} messages for cleanup`
|
||||
);
|
||||
|
|
|
@ -94,6 +94,7 @@
|
|||
timestamp: new Date().getTime(),
|
||||
attachments: [],
|
||||
pow: false,
|
||||
sent: false,
|
||||
};
|
||||
},
|
||||
validate(attributes) {
|
||||
|
|
|
@ -133,6 +133,7 @@ module.exports = {
|
|||
getMessageBySender,
|
||||
getMessageById,
|
||||
getAllMessages,
|
||||
getAllUnsentMessages,
|
||||
getAllMessageIds,
|
||||
getMessagesBySentAt,
|
||||
getExpiredMessages,
|
||||
|
@ -810,6 +811,12 @@ async function getAllMessages({ MessageCollection }) {
|
|||
return new MessageCollection(encoded);
|
||||
}
|
||||
|
||||
async function getAllUnsentMessages({ MessageCollection }) {
|
||||
const messages = await channels.getAllUnsentMessages();
|
||||
const encoded = messages.map(m => keysToArrayBuffer(MESSAGE_PRE_KEYS, m));
|
||||
return new MessageCollection(encoded);
|
||||
}
|
||||
|
||||
async function getAllMessageIds() {
|
||||
const ids = await channels.getAllMessageIds();
|
||||
return ids;
|
||||
|
|
Loading…
Reference in New Issue