mirror of
https://github.com/signalapp/Signal-Desktop.git
synced 2025-12-24 12:19:41 +00:00
Stickers
Co-authored-by: scott@signal.org Co-authored-by: ken@signal.org
This commit is contained in:
committed by
Scott Nonnenberg
parent
8c8856785b
commit
29de50c12a
@@ -179,7 +179,7 @@ exports.loadData = readAttachmentData => {
|
||||
}
|
||||
|
||||
const data = await readAttachmentData(attachment.path);
|
||||
return Object.assign({}, attachment, { data });
|
||||
return Object.assign({}, attachment, { data, size: data.byteLength });
|
||||
};
|
||||
};
|
||||
|
||||
|
||||
@@ -140,11 +140,12 @@ async function deleteExternalFiles(conversation, options = {}) {
|
||||
}
|
||||
|
||||
module.exports = {
|
||||
deleteExternalFiles,
|
||||
migrateConversation,
|
||||
maybeUpdateAvatar,
|
||||
maybeUpdateProfileAvatar,
|
||||
createLastMessageUpdate,
|
||||
arrayBufferToBase64,
|
||||
base64ToArrayBuffer,
|
||||
computeHash,
|
||||
createLastMessageUpdate,
|
||||
deleteExternalFiles,
|
||||
maybeUpdateAvatar,
|
||||
maybeUpdateProfileAvatar,
|
||||
migrateConversation,
|
||||
};
|
||||
|
||||
@@ -308,7 +308,33 @@ const toVersion9 = exports._withSchemaVersion({
|
||||
});
|
||||
const toVersion10 = exports._withSchemaVersion({
|
||||
schemaVersion: 10,
|
||||
upgrade: exports._mapPreviewAttachments(Attachment.migrateDataToFileSystem),
|
||||
upgrade: async (message, context) => {
|
||||
const processPreviews = exports._mapPreviewAttachments(
|
||||
Attachment.migrateDataToFileSystem
|
||||
);
|
||||
const processSticker = async (stickerMessage, stickerContext) => {
|
||||
const { sticker } = stickerMessage;
|
||||
if (!sticker || !sticker.data || !sticker.data.data) {
|
||||
return stickerMessage;
|
||||
}
|
||||
|
||||
return {
|
||||
...stickerMessage,
|
||||
sticker: {
|
||||
...sticker,
|
||||
data: await Attachment.migrateDataToFileSystem(
|
||||
sticker.data,
|
||||
stickerContext
|
||||
),
|
||||
},
|
||||
};
|
||||
};
|
||||
|
||||
const previewProcessed = await processPreviews(message, context);
|
||||
const stickerProcessed = await processSticker(previewProcessed, context);
|
||||
|
||||
return stickerProcessed;
|
||||
},
|
||||
});
|
||||
|
||||
const VERSIONS = [
|
||||
@@ -462,6 +488,44 @@ exports.processNewAttachment = async (
|
||||
return finalAttachment;
|
||||
};
|
||||
|
||||
exports.processNewSticker = async (
|
||||
stickerData,
|
||||
{
|
||||
writeNewStickerData,
|
||||
getAbsoluteStickerPath,
|
||||
getImageDimensions,
|
||||
logger,
|
||||
} = {}
|
||||
) => {
|
||||
if (!isFunction(writeNewStickerData)) {
|
||||
throw new TypeError('context.writeNewStickerData is required');
|
||||
}
|
||||
if (!isFunction(getAbsoluteStickerPath)) {
|
||||
throw new TypeError('context.getAbsoluteStickerPath is required');
|
||||
}
|
||||
if (!isFunction(getImageDimensions)) {
|
||||
throw new TypeError('context.getImageDimensions is required');
|
||||
}
|
||||
if (!isObject(logger)) {
|
||||
throw new TypeError('context.logger is required');
|
||||
}
|
||||
|
||||
const path = await writeNewStickerData(stickerData);
|
||||
const absolutePath = await getAbsoluteStickerPath(path);
|
||||
|
||||
const { width, height } = await getImageDimensions({
|
||||
objectUrl: absolutePath,
|
||||
logger,
|
||||
});
|
||||
|
||||
return {
|
||||
contentType: 'image/webp',
|
||||
path,
|
||||
width,
|
||||
height,
|
||||
};
|
||||
};
|
||||
|
||||
exports.createAttachmentLoader = loadAttachmentData => {
|
||||
if (!isFunction(loadAttachmentData)) {
|
||||
throw new TypeError(
|
||||
@@ -532,6 +596,23 @@ exports.loadPreviewData = loadAttachmentData => {
|
||||
};
|
||||
};
|
||||
|
||||
exports.loadStickerData = loadAttachmentData => {
|
||||
if (!isFunction(loadAttachmentData)) {
|
||||
throw new TypeError('loadStickerData: loadAttachmentData is required');
|
||||
}
|
||||
|
||||
return async sticker => {
|
||||
if (!sticker || !sticker.data) {
|
||||
return null;
|
||||
}
|
||||
|
||||
return {
|
||||
...sticker,
|
||||
data: await loadAttachmentData(sticker.data),
|
||||
};
|
||||
};
|
||||
};
|
||||
|
||||
exports.deleteAllExternalFiles = ({ deleteAttachmentData, deleteOnDisk }) => {
|
||||
if (!isFunction(deleteAttachmentData)) {
|
||||
throw new TypeError(
|
||||
@@ -546,7 +627,7 @@ exports.deleteAllExternalFiles = ({ deleteAttachmentData, deleteOnDisk }) => {
|
||||
}
|
||||
|
||||
return async message => {
|
||||
const { attachments, quote, contact, preview } = message;
|
||||
const { attachments, quote, contact, preview, sticker } = message;
|
||||
|
||||
if (attachments && attachments.length) {
|
||||
await Promise.all(attachments.map(deleteAttachmentData));
|
||||
@@ -590,6 +671,14 @@ exports.deleteAllExternalFiles = ({ deleteAttachmentData, deleteOnDisk }) => {
|
||||
})
|
||||
);
|
||||
}
|
||||
|
||||
if (sticker && sticker.data && sticker.data.path) {
|
||||
await deleteOnDisk(sticker.data.path);
|
||||
|
||||
if (sticker.data.thumbnail && sticker.data.thumbnail.path) {
|
||||
await deleteOnDisk(sticker.data.thumbnail.path);
|
||||
}
|
||||
}
|
||||
};
|
||||
};
|
||||
|
||||
|
||||
Reference in New Issue
Block a user