make sure to store generated thumbnail with the attachment message

This commit is contained in:
audric 2022-01-12 18:56:33 +11:00
parent 8feecb777b
commit 1c8e81d8e6
5 changed files with 22 additions and 30 deletions

View File

@ -609,6 +609,7 @@ export class ConversationModel extends Backbone.Model<ConversationAttributes> {
public async sendMessageJob(message: MessageModel, expireTimer: number | undefined) {
try {
const uploads = await message.uploadData();
const { id } = message;
const destination = this.id;

View File

@ -746,6 +746,7 @@ export class MessageModel extends Backbone.Model<MessageAttributes> {
quotePromise,
]);
window.log.info(`Upload of message data for message ${this.idForLogging()} is finished.`);
return {
body,
attachments,

View File

@ -177,7 +177,7 @@ export const processNewAttachment = async (attachment: {
const onDiskAttachmentPath = await migrateDataToFileSystem(rotatedAttachment.data);
const attachmentWithoutData = omit({ ...attachment, path: onDiskAttachmentPath }, 'data');
const attachmentWithoutData = omit({ ...attachment, path: onDiskAttachmentPath }, ['data']);
const finalAttachment = await captureDimensionsAndScreenshot(attachmentWithoutData);
return { ...finalAttachment, size: rotatedAttachment.data.byteLength };

View File

@ -193,33 +193,22 @@ type CaptureDimensionType = { contentType: string; path: string };
export const captureDimensionsAndScreenshot = async (
attachment: CaptureDimensionType
): Promise<| CaptureDimensionType
| (CaptureDimensionType & {
): Promise<CaptureDimensionType & {
width?: number;
height?: number;
thumbnail: {
path: string;
contentType: string;
width: number;
height: number;
thumbnail: {
path: string;
contentType: string;
width: number;
height: number;
};
})
| (CaptureDimensionType & {
} | null;
screenshot: {
path: string;
contentType: string;
width: number;
height: number;
thumbnail: {
path: string;
contentType: string;
width: number;
height: number;
};
screenshot: {
path: string;
contentType: string;
width: number;
height: number;
};
})> => {
} | null;
}> => {
const { contentType } = attachment;
if (
@ -227,12 +216,12 @@ export const captureDimensionsAndScreenshot = async (
(!GoogleChrome.isImageTypeSupported(contentType) &&
!GoogleChrome.isVideoTypeSupported(contentType))
) {
return attachment;
return { ...attachment, screenshot: null, thumbnail: null };
}
// If the attachment hasn't been downloaded yet, we won't have a path
if (!attachment.path) {
return attachment;
return { ...attachment, screenshot: null, thumbnail: null };
}
const absolutePath = getAbsoluteAttachmentPath(attachment.path);
@ -258,6 +247,7 @@ export const captureDimensionsAndScreenshot = async (
width: THUMBNAIL_SIDE,
height: THUMBNAIL_SIDE,
},
screenshot: null,
};
} catch (error) {
window.log.error(
@ -265,7 +255,7 @@ export const captureDimensionsAndScreenshot = async (
'error processing image; skipping screenshot generation',
toLogFormat(error)
);
return attachment;
return { ...attachment, screenshot: null, thumbnail: null };
}
}
@ -312,7 +302,7 @@ export const captureDimensionsAndScreenshot = async (
'captureDimensionsAndScreenshot: error processing video; skipping screenshot generation',
toLogFormat(error)
);
return attachment;
return { ...attachment, screenshot: null, thumbnail: null };
} finally {
if (screenshotObjectUrl) {
revokeObjectUrl(screenshotObjectUrl);

View File

@ -237,8 +237,8 @@ export async function getFileAndStoreLocally(
path: attachmentSavedLocally.path,
width: scaled.width,
height: scaled.height,
screenshot: null,
thumbnail: null,
screenshot: attachmentSavedLocally.screenshot,
thumbnail: attachmentSavedLocally.thumbnail,
size: attachmentSavedLocally.size,
// url: undefined,