Files
mattermost-mobile/app/utils/general/index.ts
Elias Nahum 5de54471b7 [Gekidou] Gallery (#6008)
* Gallery screen (ground work)

* Open the gallery from posts

* Open the gallery from post draft

* feedback review

* Feedback review 2

* do not remove dm channel names and localization fix

* update to the latest network-client

* do not override file width, height and imageThumbail if received file does not have it set

* bring back ScrollView wrapper for message component

* Remove Text wrapper for markdown paragraph

* Fix YouTube play icon placeholder

* Make video file play button container round

* Add gif image placeholder

* Save images & videos to camera roll

* Feedback review 3

* load video thumbnail when post is in viewport

* simplify prefix
2022-03-01 13:55:44 -03:00

54 lines
1.4 KiB
TypeScript

// Copyright (c) 2015-present Mattermost, Inc. All Rights Reserved.
// See LICENSE.txt for license information.
import ReactNativeHapticFeedback, {HapticFeedbackTypes} from 'react-native-haptic-feedback';
type SortByCreatAt = (Session | Channel | Team | Post) & {
create_at: number;
}
// eslint-disable-next-line @typescript-eslint/no-unused-vars
export function emptyFunction(..._args: any[]) {
// do nothing
}
// Generates a RFC-4122 version 4 compliant globally unique identifier.
export const generateId = (prefix?: string): string => {
// implementation taken from http://stackoverflow.com/a/2117523
let id = 'xxxxxxxx-xxxx-4xxx-yxxx-xxxxxxxxxxxx';
id = id.replace(/[xy]/g, (c) => {
const r = Math.floor(Math.random() * 16);
let v;
if (c === 'x') {
v = r;
} else {
// eslint-disable-next-line no-mixed-operators
v = (r & 0x3) | 0x8;
}
return v.toString(16);
});
if (prefix) {
return `${prefix}-${id}`;
}
return id;
};
export function hapticFeedback(method: HapticFeedbackTypes = 'impactLight') {
ReactNativeHapticFeedback.trigger(method, {
enableVibrateFallback: false,
ignoreAndroidSystemSettings: false,
});
}
export const sortByNewest = (a: SortByCreatAt, b: SortByCreatAt) => {
if (a.create_at > b.create_at) {
return -1;
}
return 1;
};