Files
mattermost-mobile/app/utils/files.tsx
Elias Nahum 7aa5bd0611 Update Dependencies and bug fixes (#7000)
* update dependencies

* update dependencies

* feedback review

* update @mattermost/react-native-turbo-mailer
2023-01-24 09:14:23 +02:00

50 lines
1.7 KiB
TypeScript

// Copyright (c) 2015-present Mattermost, Inc. All Rights Reserved.
// See LICENSE.txt for license information.
import {fileToGalleryItem} from '@utils/gallery';
import type ChannelModel from '@typings/database/models/servers/channel';
export const getNumberFileMenuOptions = (canDownloadFiles: boolean, publicLinkEnabled: boolean) => {
let numberItems = 1;
numberItems += canDownloadFiles ? 1 : 0;
numberItems += publicLinkEnabled ? 1 : 0;
return numberItems;
};
// return an object with key:value of channelID:channelDisplayName
export const getChannelNamesWithID = (fileChannels: ChannelModel[]) => {
return fileChannels.reduce<{[id: string]: string | undefined}>((acc, v) => {
acc[v.id] = v.displayName;
return acc;
}, {});
};
// return array of fileInfos (image and non-image) sorted by create_at date
export const getOrderedFileInfos = (fileInfos: FileInfo[]) => {
return fileInfos.sort((a: FileInfo, b: FileInfo) => {
return (b.create_at || 0) - (a.create_at || 0);
});
};
// returns object with keys of fileInfo.id and value of the ordered index from
// orderedFilesForGallery
export const getFileInfosIndexes = (orderedFilesForGallery: FileInfo[]) => {
return orderedFilesForGallery.reduce<{[id: string]: number | undefined}>((acc, v, idx) => {
if (v.id) {
acc[v.id] = idx;
}
return acc;
}, {});
};
// return ordered FileInfo[] converted to GalleryItemType[]
export const getOrderedGalleryItems = (orderedFileInfos: FileInfo[]) => {
return orderedFileInfos.map((f) => fileToGalleryItem(f, f.user_id));
};
export const pathWithPrefix = (prefix: string, path: string) => {
const p = path.startsWith(prefix) ? '' : prefix;
return `${p}${path}`;
};