mattermost-mobile/app/utils/files.tsx
Daniel Espino García 5c2153f83b
Add Report a Problem functionality (#8605)
* Add Report a Problem functionality

* update cache pinned SHA version from 4.0.2 to 4.2.0

* Address feedback

* Fix tests

* Fix some issues and update kotlin coroutines version

* Fix delete file for iOS

* Bump 1 more version for coroutines

* Use rxjava instead of kotlin coroutines to avoid security issue

* Move path prefix to avoid test error

* Address feedback

* Address feedback

* Address feedback

* Use mailto on iOS

* Fix tests related to button changes

* Address feedback

* Update icon and fix onboarding buttons

* Fix test

---------

Co-authored-by: Angelos Kyratzakos <angelos.kyratzakos@mattermost.com>
Co-authored-by: Mattermost Build <build@mattermost.com>
2025-04-24 11:12:55 +02:00

44 lines
1.6 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));
};