Persist drafts

This commit is contained in:
Scott Nonnenberg 2019-08-06 17:40:25 -07:00
parent 5ebd8bc690
commit 9d4f2afa5a
23 changed files with 1048 additions and 720 deletions

View file

@ -9,7 +9,6 @@ const {
isFunction,
isObject,
map,
merge,
set,
} = require('lodash');
@ -29,6 +28,7 @@ const ERASE_SQL_KEY = 'erase-sql-key';
const ERASE_ATTACHMENTS_KEY = 'erase-attachments';
const ERASE_STICKERS_KEY = 'erase-stickers';
const ERASE_TEMP_KEY = 'erase-temp';
const ERASE_DRAFTS_KEY = 'erase-drafts';
const CLEANUP_ORPHANED_ATTACHMENTS_KEY = 'cleanup-orphaned-attachments';
const _jobs = Object.create(null);
@ -598,7 +598,10 @@ async function updateConversation(id, data, { Conversation }) {
throw new Error(`Conversation ${id} does not exist!`);
}
const merged = merge({}, existing.attributes, data);
const merged = {
...existing.attributes,
...data,
};
await channels.updateConversation(merged);
}
@ -1007,6 +1010,7 @@ async function removeOtherData() {
callChannel(ERASE_ATTACHMENTS_KEY),
callChannel(ERASE_STICKERS_KEY),
callChannel(ERASE_TEMP_KEY),
callChannel(ERASE_DRAFTS_KEY),
]);
}

View file

@ -103,20 +103,21 @@ function initializeMigrations({
return null;
}
const {
createAbsolutePathGetter,
createReader,
createWriterForExisting,
createWriterForNew,
getDraftPath,
getPath,
getStickersPath,
getTempPath,
createReader,
createAbsolutePathGetter,
createWriterForNew,
createWriterForExisting,
} = Attachments;
const {
makeObjectUrl,
revokeObjectUrl,
getImageDimensions,
makeImageThumbnail,
makeObjectUrl,
makeVideoScreenshot,
revokeObjectUrl,
} = VisualType;
const attachmentsPath = getPath(userDataPath);
@ -147,11 +148,18 @@ function initializeMigrations({
tempPath
);
const draftPath = getDraftPath(userDataPath);
const getAbsoluteDraftPath = createAbsolutePathGetter(draftPath);
const writeNewDraftData = createWriterForNew(draftPath);
const deleteDraftFile = Attachments.createDeleter(draftPath);
const readDraftData = createReader(draftPath);
return {
attachmentsPath,
copyIntoAttachmentsDirectory,
copyIntoTempDirectory,
deleteAttachmentData: deleteOnDisk,
deleteDraftFile,
deleteExternalMessageFiles: MessageType.deleteAllExternalFiles({
deleteAttachmentData: Type.deleteData(deleteOnDisk),
deleteOnDisk,
@ -159,6 +167,7 @@ function initializeMigrations({
deleteSticker,
deleteTempFile,
getAbsoluteAttachmentPath,
getAbsoluteDraftPath,
getAbsoluteStickerPath,
getAbsoluteTempPath,
getPlaceholderMigrations,
@ -169,6 +178,7 @@ function initializeMigrations({
loadQuoteData,
loadStickerData,
readAttachmentData,
readDraftData,
readStickerData,
readTempData,
run,
@ -218,6 +228,7 @@ function initializeMigrations({
logger,
}),
writeNewAttachmentData: createWriterForNew(attachmentsPath),
writeNewDraftData,
};
}