* Added DrawerItem component * WIP Account Screen * Added react-native-paper * Added StatusLabel Component * Extracted i18n * TS fix DrawerItem component * WIP Account Screen * Added server name label under log out * Updated translation * WIP * Fixes the Offline text style * Added Metropolis fonts * WIP * Typo clean up * WIP * WIP * WIP * Added server display name * Writing OpenSans properly * WIP * WIP * Added OptionsModal * Opening OptionsModal * Added translation keys * Writes status to local db * Fix missing translation * Fix OptionModal not dismissing * Pushing status to server * Refactored * Added CustomStatusExpiry component * Added sub components * Added CustomLabel * CustomStatus WIP * Added Custom Status screen WIP * WIP - unsetCustomStatus and CustomStatus constant * WIP * WIP * WIP * WIP * WIP * WIP * WIP * Retrieving RecentCustomStatuses from Preferences table * WIP * WIP * WIP * Added Clear After Modal * WIP - Transations * WIP * Done with showing modal cst * wip * Clear After Modal - DONE * fix * Added missing API calls * wip * Causing screen refresh * wip * WIP * WIP * WIP * Code clean up * Added OOO alert box * Refactored Options-Item * Refactored OptionsModalList component * Opening 'status' in BottomSheet instead of OptionsModal * AddReaction screen - WIP * Add Reaction screen - WIP * Added EmojiPickerRow * Added @components/emoji_picker - WIP * Emoji Picker - WIP * WIP * WIP * WIP * SectionList - WIP * Installed react-native-section_list_get_item_layout * Adding API calls - WIP * WIP * Search Bar component - WIP * WIP * WIP * WIP * Rendering Emoticons now - have to tackle some fixmes * Code clean up * Code clean up - WIP * Code clean up * WIP * Major clean up * wip * WIP * Fix rendering issue with SectionIcons and SearchBar * Tackled the CustomEmojiPage * Code clean up * WIP * Done with loading User Profiles for Custom Emoji * Code clean up * Code Clean up * Fix screen Account * Added missing sql file for IOS Pod * Updated Podfile.lock * Using queryConfig instead of queryCommonSystemValues * Fix - Custom status * Fix - Custom Status - Error * Fix - Clear Pass Status - WIP * Fix - Custom Status Clear * Need to fix CST clear * WIP * Status clear - working * Using catchError operator * remove unnecessary prop * Status BottomSheet now has colored indicators * Added KeyboardTrackingView from 'react-native-keyboard-tracking-view' * Code clean up * WIP * code clean up * Added a safety check * Fix - Display suggestions * Code clean up based on PR Review * Code clean up * Code clean up * Code clean up * Corrections * Fix tsc * TS fix * Removed unnecessary prop * Fix SearchBar Ts * Updated tests * Delete search_bar.test.js.snap * Merge branch 'gekidou' into gekidou_account_screen * Revert "Merge branch 'gekidou' into gekidou_account_screen" This reverts commit 5defc313212478a55abf2f92cb4bd64dc7877342. * Fix fonts * Refactor home account screen * fix theme provider * refactor bottom sheet * remove paper provider * update drawer item snapshots * Remove options modal screen * remove react-native-ui-lib dependency * Refactor & fix custom status & navigation (including tablet) * Refactor emoji picker Co-authored-by: Avinash Lingaloo <> Co-authored-by: Elias Nahum <nahumhbl@gmail.com>
121 lines
3.6 KiB
TypeScript
121 lines
3.6 KiB
TypeScript
// Copyright (c) 2015-present Mattermost, Inc. All Rights Reserved.
|
|
// See LICENSE.txt for license information.
|
|
|
|
import moment, {Moment} from 'moment-timezone';
|
|
|
|
import {CUSTOM_STATUS_TIME_PICKER_INTERVALS_IN_MINUTES} from '@constants/custom_status';
|
|
|
|
// isMinimumServerVersion will return true if currentVersion is equal to higher or than
|
|
// the provided minimum version. A non-equal major version will ignore minor and dot
|
|
// versions, and a non-equal minor version will ignore dot version.
|
|
// currentVersion is a string, e.g '4.6.0'
|
|
// minMajorVersion, minMinorVersion, minDotVersion are integers
|
|
export const isMinimumServerVersion = (currentVersion: string, minMajorVersion = 0, minMinorVersion = 0, minDotVersion = 0): boolean => {
|
|
if (!currentVersion || typeof currentVersion !== 'string') {
|
|
return false;
|
|
}
|
|
|
|
const split = currentVersion.split('.');
|
|
|
|
const major = parseInt(split[0], 10);
|
|
const minor = parseInt(split[1] || '0', 10);
|
|
const dot = parseInt(split[2] || '0', 10);
|
|
|
|
if (major > minMajorVersion) {
|
|
return true;
|
|
}
|
|
if (major < minMajorVersion) {
|
|
return false;
|
|
}
|
|
|
|
// Major version is equal, check minor
|
|
if (minor > minMinorVersion) {
|
|
return true;
|
|
}
|
|
if (minor < minMinorVersion) {
|
|
return false;
|
|
}
|
|
|
|
// Minor version is equal, check dot
|
|
if (dot > minDotVersion) {
|
|
return true;
|
|
}
|
|
if (dot < minDotVersion) {
|
|
return false;
|
|
}
|
|
|
|
// Dot version is equal
|
|
return true;
|
|
};
|
|
|
|
export function buildQueryString(parameters: Dictionary<any>): string {
|
|
const keys = Object.keys(parameters);
|
|
if (keys.length === 0) {
|
|
return '';
|
|
}
|
|
|
|
let query = '?';
|
|
for (let i = 0; i < keys.length; i++) {
|
|
const key = keys[i];
|
|
query += key + '=' + encodeURIComponent(parameters[key]);
|
|
|
|
if (i < keys.length - 1) {
|
|
query += '&';
|
|
}
|
|
}
|
|
|
|
return query;
|
|
}
|
|
|
|
export function isEmail(email: string): boolean {
|
|
// writing a regex to match all valid email addresses is really, really hard. (see http://stackoverflow.com/a/201378)
|
|
// this regex ensures:
|
|
// - at least one character that is not a space, comma, or @ symbol
|
|
// - followed by a single @ symbol
|
|
// - followed by at least one character that is not a space, comma, or @ symbol
|
|
// this prevents <Outlook Style> outlook.style@domain.com addresses and multiple comma-separated addresses from being accepted
|
|
return (/^[^ ,@]+@[^ ,@]+$/).test(email);
|
|
}
|
|
|
|
export function safeParseJSON(rawJson: string | Record<string, unknown> | unknown[]) {
|
|
let data = rawJson;
|
|
try {
|
|
if (typeof rawJson == 'string') {
|
|
data = JSON.parse(rawJson);
|
|
}
|
|
} catch {
|
|
// Do nothing
|
|
}
|
|
|
|
return data;
|
|
}
|
|
|
|
export function getCurrentMomentForTimezone(timezone: string) {
|
|
return timezone ? moment.tz(timezone) : moment();
|
|
}
|
|
|
|
export function getUtcOffsetForTimeZone(timezone: string) {
|
|
return moment.tz(timezone).utcOffset();
|
|
}
|
|
|
|
export function isCustomStatusExpirySupported(version: string) {
|
|
return isMinimumServerVersion(version, 5, 37);
|
|
}
|
|
|
|
export function toTitleCase(str: string) {
|
|
function doTitleCase(txt: string) {
|
|
return txt.charAt(0).toUpperCase() + txt.substr(1).toLowerCase();
|
|
}
|
|
return str.replace(/\w\S*/g, doTitleCase);
|
|
}
|
|
|
|
export function getRoundedTime(value: Moment) {
|
|
const roundedTo = CUSTOM_STATUS_TIME_PICKER_INTERVALS_IN_MINUTES;
|
|
const start = moment(value);
|
|
const diff = start.minute() % roundedTo;
|
|
if (diff === 0) {
|
|
return value;
|
|
}
|
|
const remainder = roundedTo - diff;
|
|
return start.add(remainder, 'm').seconds(0).milliseconds(0);
|
|
}
|