From f673589c56dd95db7a3730e914b1f49a617b4338 Mon Sep 17 00:00:00 2001 From: Audric Ackermann Date: Tue, 24 Nov 2020 13:19:21 +1100 Subject: [PATCH] add types for blueimp-load-image --- js/models/messages.js | 1 - package.json | 1 + preload.js | 1 - ts/components/session/RegistrationTabs.tsx | 6 ------ ts/util/attachmentsUtil.ts | 21 ++++++++------------- ts/util/timer.ts | 1 - ts/window.d.ts | 1 - yarn.lock | 5 +++++ 8 files changed, 14 insertions(+), 23 deletions(-) diff --git a/js/models/messages.js b/js/models/messages.js index d03eebe84..dc999ac44 100644 --- a/js/models/messages.js +++ b/js/models/messages.js @@ -618,7 +618,6 @@ onBanUser: () => this.banUser(), onRetrySend: () => this.retrySend(), onShowDetail: () => this.trigger('show-message-detail', this), - onClickLinkPreview: url => this.trigger('navigate-to', url), markRead: readAt => this.markRead(readAt), onShowUserDetails: pubkey => diff --git a/package.json b/package.json index 840fdf340..64e7075bb 100644 --- a/package.json +++ b/package.json @@ -58,6 +58,7 @@ "@journeyapps/sqlcipher": "https://github.com/scottnonnenberg-signal/node-sqlcipher.git#b10f232fac62ba7f8775c9e086bb5558fe7d948b", "@reduxjs/toolkit": "^1.4.0", "@sindresorhus/is": "0.8.0", + "@types/blueimp-load-image": "^2.23.8", "@types/dompurify": "^2.0.0", "@types/emoji-mart": "^2.11.3", "@types/moment": "^2.13.0", diff --git a/preload.js b/preload.js index 3e4ff18df..347e6fb14 100644 --- a/preload.js +++ b/preload.js @@ -379,7 +379,6 @@ const { autoOrientImage } = require('./js/modules/auto_orient_image'); window.autoOrientImage = autoOrientImage; window.dataURLToBlobSync = require('blueimp-canvas-to-blob'); window.filesize = require('filesize'); -window.loadImage = require('blueimp-load-image'); window.getGuid = require('uuid/v4'); window.profileImages = require('./app/profile_images'); diff --git a/ts/components/session/RegistrationTabs.tsx b/ts/components/session/RegistrationTabs.tsx index 8773598e2..c38aca85e 100644 --- a/ts/components/session/RegistrationTabs.tsx +++ b/ts/components/session/RegistrationTabs.tsx @@ -865,12 +865,6 @@ export class RegistrationTabs extends React.Component<{}, State> { language, trimName ); - // FIXME remove everything related to hasSeenLightModeDialog at some point in the future (27/08/2020) - const data = { - id: 'hasSeenLightModeDialog', - value: true, - }; - await createOrUpdateItem(data); trigger('openInbox'); } catch (e) { ToastUtils.pushToastError( diff --git a/ts/util/attachmentsUtil.ts b/ts/util/attachmentsUtil.ts index 6f5268ba6..c5ed673c8 100644 --- a/ts/util/attachmentsUtil.ts +++ b/ts/util/attachmentsUtil.ts @@ -1,7 +1,7 @@ import { StagedAttachmentType } from '../components/session/conversation/SessionCompositionBox'; import { SignalService } from '../protobuf'; import { Constants } from '../session'; - +import loadImage from 'blueimp-load-image'; export interface MaxScaleSize { maxSize?: number; maxHeight?: number; @@ -40,8 +40,7 @@ export async function autoScale( return; } - const gifMaxSize = Constants.CONVERSATION.MAX_ATTACHMENT_FILESIZE_BYTES; - if (file.type === 'image/gif' && file.size <= gifMaxSize) { + if (file.type === 'image/gif' && file.size <= Constants.CONVERSATION.MAX_ATTACHMENT_FILESIZE_BYTES) { resolve(attachment); return; } @@ -51,12 +50,11 @@ export async function autoScale( return; } - const canvas = window.loadImage.scale(img, { + const canvas = (loadImage as any).scale(img, { canvas: true, maxWidth, maxHeight, }); - let quality = 0.95; let i = 4; let blob; @@ -66,22 +64,19 @@ export async function autoScale( canvas.toDataURL('image/jpeg', quality) ); quality = (quality * maxSize) / blob.size; - // Should we disallow the algo drop the quality too low? - // if (quality < 0.5) { - // quality = 0.5; - // } - // NOTE: During testing with a large image, we observed the - // `quality` value being > 1. Should we clamp it to [0.5, 1.0]? - // See: https://developer.mozilla.org/en-US/docs/Web/API/HTMLCanvasElement/toBlob#Syntax + if (quality > 1) { - quality = 1; + quality = 0.95; } + } while (i > 0 && blob.size > maxSize); + resolve({ ...attachment, file: blob, }); + }; img.src = url; }); diff --git a/ts/util/timer.ts b/ts/util/timer.ts index fe14ebfe8..e05d8885e 100644 --- a/ts/util/timer.ts +++ b/ts/util/timer.ts @@ -20,7 +20,6 @@ export function getTimerBucket(expiration: number, length: number): string { if (delta > length) { return '60'; } - const bucket = Math.round((delta / length) * 12); return padStart(String(bucket * 5), 2, '0'); diff --git a/ts/window.d.ts b/ts/window.d.ts index 32d7ab6f4..139336c86 100644 --- a/ts/window.d.ts +++ b/ts/window.d.ts @@ -100,7 +100,6 @@ declare global { GroupBuffer: any; SwarmPolling: SwarmPolling; MediaRecorder: any; - loadImage: any; dataURLToBlobSync: any; autoOrientImage: any; contextMenuShown: boolean; diff --git a/yarn.lock b/yarn.lock index 57301b223..10d19d3f3 100644 --- a/yarn.lock +++ b/yarn.lock @@ -367,6 +367,11 @@ "@types/jquery" "*" "@types/underscore" "*" +"@types/blueimp-load-image@^2.23.8": + version "2.23.8" + resolved "https://registry.yarnpkg.com/@types/blueimp-load-image/-/blueimp-load-image-2.23.8.tgz#0d10f12bf57f050aceac06dcc76390ae759c979a" + integrity sha512-dy98N4odO9L1zgo2a6yVHRRYUeYRJfl0hg3dcapyxqNq5KF8Zgz5lFWgDMOsMC06VAs0mnVKDRJE4+U/A5Km3A== + "@types/bytebuffer@^5.0.41": version "5.0.41" resolved "https://registry.yarnpkg.com/@types/bytebuffer/-/bytebuffer-5.0.41.tgz#6850dba4d4cd2846596b4842874d5bfc01cd3db1"