Move to some of our global utility methods
This commit is contained in:
parent
403fb1fd60
commit
84c7a4c293
2 changed files with 25 additions and 26 deletions
|
@ -628,7 +628,10 @@
|
|||
async makeThumbnailAttachment(attachment) {
|
||||
const attachmentWithData = await loadAttachmentData(attachment);
|
||||
const { data, contentType } = attachmentWithData;
|
||||
const objectUrl = this.makeObjectUrl(data, contentType);
|
||||
const objectUrl = Signal.Util.arrayBufferToObjectURL({
|
||||
data,
|
||||
type: contentType,
|
||||
});
|
||||
|
||||
const thumbnail = Signal.Util.GoogleChrome.isImageTypeSupported(contentType)
|
||||
? await Whisper.FileInputView.makeImageThumbnail(128, objectUrl)
|
||||
|
@ -638,7 +641,10 @@
|
|||
|
||||
const arrayBuffer = await this.blobToArrayBuffer(thumbnail);
|
||||
const finalContentType = 'image/png';
|
||||
const finalObjectUrl = this.makeObjectUrl(arrayBuffer, finalContentType);
|
||||
const finalObjectUrl = Signal.Util.arrayBufferToObjectURL({
|
||||
data: arrayBuffer,
|
||||
type: finalContentType,
|
||||
});
|
||||
|
||||
return {
|
||||
data: arrayBuffer,
|
||||
|
@ -1126,12 +1132,6 @@
|
|||
forceRender(message) {
|
||||
message.trigger('change', message);
|
||||
},
|
||||
makeObjectUrl(data, contentType) {
|
||||
const blob = new Blob([data], {
|
||||
type: contentType,
|
||||
});
|
||||
return URL.createObjectURL(blob);
|
||||
},
|
||||
makeMessagesLookup(messages) {
|
||||
return messages.reduce((acc, message) => {
|
||||
const { source, sent_at: sentAt } = message.attributes;
|
||||
|
@ -1189,7 +1189,7 @@
|
|||
} catch (error) {
|
||||
console.log(
|
||||
'Problem loading attachment data for quoted message from database',
|
||||
error && error.stack ? error.stack : error
|
||||
Signal.Types.Errors.toLogFormat(error)
|
||||
);
|
||||
return false;
|
||||
}
|
||||
|
@ -1244,10 +1244,11 @@
|
|||
}
|
||||
try {
|
||||
const thumbnailWithData = await loadAttachmentData(thumbnail);
|
||||
thumbnailWithData.objectUrl = this.makeObjectUrl(
|
||||
thumbnailWithData.data,
|
||||
thumbnailWithData.contentType
|
||||
);
|
||||
const { data, contentType } = thumbnailWithData;
|
||||
thumbnailWithData.objectUrl = Signal.Util.arrayBufferToObjectURL({
|
||||
data,
|
||||
type: contentType,
|
||||
});
|
||||
|
||||
// If we update this data in place, there's the risk that this data could be
|
||||
// saved back to the database
|
||||
|
|
|
@ -84,7 +84,7 @@
|
|||
video.addEventListener('error', (error) => {
|
||||
console.log(
|
||||
'makeVideoThumbnail error',
|
||||
error && error.stack ? error.stack : error
|
||||
Signal.Types.Errors.toLogFormat(error)
|
||||
);
|
||||
reject(error);
|
||||
});
|
||||
|
@ -93,13 +93,6 @@
|
|||
}));
|
||||
}
|
||||
|
||||
function makeObjectUrl(data, contentType) {
|
||||
const blob = new Blob([data], {
|
||||
type: contentType,
|
||||
});
|
||||
return URL.createObjectURL(blob);
|
||||
}
|
||||
|
||||
function blobToArrayBuffer(blob) {
|
||||
return new Promise((resolve, reject) => {
|
||||
const fileReader = new FileReader();
|
||||
|
@ -114,8 +107,11 @@
|
|||
|
||||
async function makeVideoThumbnail(size, videoObjectUrl) {
|
||||
const blob = await makeVideoScreenshot(videoObjectUrl);
|
||||
const arrayBuffer = await blobToArrayBuffer(blob);
|
||||
const screenshotObjectUrl = makeObjectUrl(arrayBuffer, 'image/png');
|
||||
const data = await blobToArrayBuffer(blob);
|
||||
const screenshotObjectUrl = Signal.Util.arrayBufferToObjectURL({
|
||||
data,
|
||||
type: 'image/png',
|
||||
});
|
||||
|
||||
const thumbnail = await makeImageThumbnail(size, screenshotObjectUrl);
|
||||
URL.revokeObjectURL(screenshotObjectUrl);
|
||||
|
@ -244,9 +240,11 @@
|
|||
const thumbnail = await makeVideoScreenshot(this.previewObjectUrl);
|
||||
URL.revokeObjectURL(this.previewObjectUrl);
|
||||
|
||||
const arrayBuffer = await blobToArrayBuffer(thumbnail);
|
||||
|
||||
this.previewObjectUrl = makeObjectUrl(arrayBuffer, 'image/png');
|
||||
const data = await blobToArrayBuffer(thumbnail);
|
||||
this.previewObjectUrl = Signal.Util.arrayBufferToObjectURL({
|
||||
data,
|
||||
type: 'image/png',
|
||||
});
|
||||
this.addThumb(this.previewObjectUrl, { addPlayIcon: true });
|
||||
};
|
||||
|
||||
|
|
Loading…
Reference in a new issue