Files
mattermost-mobile/share_extension/utils/index.ts
Elias Nahum 6eadc527bb Gekidou Android share extension (#6803)
* Refactor app database queries to not require the app database as argument

* Android Share Extension and fix notifications prompt

* feedback review
2022-11-30 23:18:56 +02:00

44 lines
1.1 KiB
TypeScript

// Copyright (c) 2015-present Mattermost, Inc. All Rights Reserved.
// See LICENSE.txt for license information.
export function toFileInfo(f: SharedItem): FileInfo {
return {
post_id: '',
user_id: '',
extension: f.extension,
mime_type: f.type,
has_preview_image: (f.width || 0) > 0,
height: f.height || 0,
width: f.width || 0,
name: f.filename || '',
size: f.size || 0,
uri: f.value,
};
}
export function imageDimensions(imgHeight: number, imgWidth: number, maxHeight: number, viewportWidth: number) {
if (!imgHeight || !imgWidth) {
return {
height: 0,
width: 0,
};
}
const widthRatio = imgWidth / imgHeight;
const heightRatio = imgWidth / imgHeight;
let height = imgHeight;
let width = imgWidth;
if (imgWidth >= viewportWidth) {
width = viewportWidth;
height = width * widthRatio;
}
if (height > maxHeight) {
height = maxHeight;
width = height * heightRatio;
}
return {height, width};
}