mattermost-mobile/app/utils/general/index.ts
Elias Nahum c452ef8038
[Gekidou] Login entry point (#5568)
* Login entry point

* feedback review

* sort imports

* Fix model relations

* Handle when no current team or current channel has been selected

* Fix MFA unit test

* update prepareCommonSystemValues arguments
2021-07-26 12:03:43 +04:00

39 lines
1 KiB
TypeScript

// Copyright (c) 2015-present Mattermost, Inc. All Rights Reserved.
// See LICENSE.txt for license information.
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 = (): 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);
});
return id;
};
export const sortByNewest = (a: SortByCreatAt, b: SortByCreatAt) => {
if (a.create_at > b.create_at) {
return -1;
}
return 1;
};