Link previews: show full size image less often
This commit is contained in:
parent
92a35649da
commit
8c25ffd6f5
7 changed files with 220 additions and 53 deletions
34
ts/linkPreviews/shouldUseFullSizeLinkPreviewImage.ts
Normal file
34
ts/linkPreviews/shouldUseFullSizeLinkPreviewImage.ts
Normal file
|
@ -0,0 +1,34 @@
|
|||
// Copyright 2021 Signal Messenger, LLC
|
||||
// SPDX-License-Identifier: AGPL-3.0-only
|
||||
|
||||
import { LinkPreviewType } from '../types/message/LinkPreviews';
|
||||
import { isImageAttachment } from '../types/Attachment';
|
||||
|
||||
const MINIMUM_FULL_SIZE_DIMENSION = 200;
|
||||
|
||||
export function shouldUseFullSizeLinkPreviewImage({
|
||||
isStickerPack,
|
||||
image,
|
||||
}: Readonly<LinkPreviewType>): boolean {
|
||||
if (isStickerPack || !isImageAttachment(image)) {
|
||||
return false;
|
||||
}
|
||||
|
||||
const { width, height } = image;
|
||||
|
||||
return (
|
||||
isDimensionFullSize(width) &&
|
||||
isDimensionFullSize(height) &&
|
||||
!isRoughlySquare(width, height)
|
||||
);
|
||||
}
|
||||
|
||||
function isDimensionFullSize(dimension: unknown): dimension is number {
|
||||
return (
|
||||
typeof dimension === 'number' && dimension >= MINIMUM_FULL_SIZE_DIMENSION
|
||||
);
|
||||
}
|
||||
|
||||
function isRoughlySquare(width: number, height: number): boolean {
|
||||
return Math.abs(1 - width / height) < 0.05;
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue