mirror of
https://github.com/signalapp/Signal-Desktop.git
synced 2026-04-27 03:43:27 +01:00
Persist drafts
This commit is contained in:
70
app/sql.js
70
app/sql.js
@@ -140,6 +140,7 @@ module.exports = {
|
||||
|
||||
removeKnownAttachments,
|
||||
removeKnownStickers,
|
||||
removeKnownDraftAttachments,
|
||||
};
|
||||
|
||||
function generateUUID() {
|
||||
@@ -2867,6 +2868,24 @@ function getExternalFilesForConversation(conversation) {
|
||||
return files;
|
||||
}
|
||||
|
||||
function getExternalDraftFilesForConversation(conversation) {
|
||||
const draftAttachments = conversation.draftAttachments || [];
|
||||
const files = [];
|
||||
|
||||
forEach(draftAttachments, attachment => {
|
||||
const { path: file, screenshotPath } = attachment;
|
||||
if (file) {
|
||||
files.push(file);
|
||||
}
|
||||
|
||||
if (screenshotPath) {
|
||||
files.push(screenshotPath);
|
||||
}
|
||||
});
|
||||
|
||||
return files;
|
||||
}
|
||||
|
||||
async function removeKnownAttachments(allAttachments) {
|
||||
const lookup = fromPairs(map(allAttachments, file => [file, true]));
|
||||
const chunkSize = 50;
|
||||
@@ -2999,3 +3018,54 @@ async function removeKnownStickers(allStickers) {
|
||||
|
||||
return Object.keys(lookup);
|
||||
}
|
||||
|
||||
async function removeKnownDraftAttachments(allStickers) {
|
||||
const lookup = fromPairs(map(allStickers, file => [file, true]));
|
||||
const chunkSize = 50;
|
||||
|
||||
const total = await getConversationCount();
|
||||
console.log(
|
||||
`removeKnownDraftAttachments: About to iterate through ${total} conversations`
|
||||
);
|
||||
|
||||
let complete = false;
|
||||
let count = 0;
|
||||
// Though conversations.id is a string, this ensures that, when coerced, this
|
||||
// value is still a string but it's smaller than every other string.
|
||||
let id = 0;
|
||||
|
||||
while (!complete) {
|
||||
// eslint-disable-next-line no-await-in-loop
|
||||
const rows = await db.all(
|
||||
`SELECT json FROM conversations
|
||||
WHERE id > $id
|
||||
ORDER BY id ASC
|
||||
LIMIT $chunkSize;`,
|
||||
{
|
||||
$id: id,
|
||||
$chunkSize: chunkSize,
|
||||
}
|
||||
);
|
||||
|
||||
const conversations = map(rows, row => jsonToObject(row.json));
|
||||
forEach(conversations, conversation => {
|
||||
const externalFiles = getExternalDraftFilesForConversation(conversation);
|
||||
forEach(externalFiles, file => {
|
||||
delete lookup[file];
|
||||
});
|
||||
});
|
||||
|
||||
const lastMessage = last(conversations);
|
||||
if (lastMessage) {
|
||||
({ id } = lastMessage);
|
||||
}
|
||||
complete = conversations.length < chunkSize;
|
||||
count += conversations.length;
|
||||
}
|
||||
|
||||
console.log(
|
||||
`removeKnownDraftAttachments: Done processing ${count} conversations`
|
||||
);
|
||||
|
||||
return Object.keys(lookup);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user