From f8cd997b13bf134a5fa38b538f93f04c5fb9de4e Mon Sep 17 00:00:00 2001 From: Vincent Date: Mon, 13 Jul 2020 15:57:53 +1000 Subject: [PATCH] constants-to-ts --- libtextsecure/outgoing_message.js | 8 ++-- preload.js | 44 ----------------- stylesheets/_session_left_pane.scss | 2 +- ts/components/session/SessionIdEditable.tsx | 14 +++++- .../session/settings/SessionSettings.tsx | 6 ++- ts/session/constants.ts | 13 +++++ ts/session/index.ts | 3 +- .../outgoing/content/ContentMessage.ts | 4 +- .../outgoing/content/EndSessionMessage.ts | 3 +- .../content/SessionEstablishedMessage.ts | 3 +- .../outgoing/content/SessionRequestMessage.ts | 3 +- .../outgoing/content/TypingMessage.ts | 3 +- .../content/data/DeviceUnlinkMessage.ts | 3 +- .../content/link/DeviceLinkRequestMessage.ts | 3 +- ts/session/utils/Number.ts | 47 +++++++++++++++++++ ts/session/utils/index.ts | 2 + ts/window.d.ts | 1 - 17 files changed, 99 insertions(+), 63 deletions(-) create mode 100644 ts/session/constants.ts create mode 100644 ts/session/utils/Number.ts diff --git a/libtextsecure/outgoing_message.js b/libtextsecure/outgoing_message.js index 0ad7e73cc..68de4dfb3 100644 --- a/libtextsecure/outgoing_message.js +++ b/libtextsecure/outgoing_message.js @@ -15,13 +15,13 @@ const NUM_SEND_CONNECTIONS = 3; const getTTLForType = type => { switch (type) { case 'pairing-request': - return window.CONSTANTS.TTL_DEFAULT_PAIRING_REQUEST; + return window.libsession.Constants.TTL_DEFAULT.PAIRING_REQUEST; case 'device-unpairing': - return window.CONSTANTS.TTL_DEFAULT_DEVICE_UNPAIRING; + return window.libsession.Constants.TTL_DEFAULT.DEVICE_UNPAIRING; case 'onlineBroadcast': - return window.CONSTANTS.TTL_DEFAULT_ONLINE_BROADCAST; + return window.libsession.Constants.TTL_DEFAULT.ONLINE_BROADCAST; default: - return window.CONSTANTS.TTL_DEFAULT_REGULAR_MESSAGE; + return window.libsession.Constants.TTL_DEFAULT.REGULAR_MESSAGE; } }; diff --git a/preload.js b/preload.js index db2fb75a6..0a45db23f 100644 --- a/preload.js +++ b/preload.js @@ -75,44 +75,6 @@ window.isBeforeVersion = (toCheck, baseVersion) => { } }; -window.timeAsMs = (value, unit) => { - // Converts a time to milliseconds - // Valid units: second, minute, hour, day - const unitAsSingular = unit.replace(new RegExp('s?$'), ''); - - switch (unitAsSingular) { - case 'second': - return value * 1000; - case 'minute': - return value * 60 * 1000; - case 'hour': - return value * 60 * 60 * 1000; - case 'day': - return value * 24 * 60 * 60 * 1000; - default: - return value; - } -}; - -window.msAsUnit = (value, unit) => { - // Converts milliseconds to your preferred unit - // Valid units: second(s), minute(s), hour(s), day(s) - const unitAsSingular = unit.replace(new RegExp('s?$'), ''); - - switch (unitAsSingular) { - case 'second': - return value / 1000; - case 'minute': - return value / 60 / 1000; - case 'hour': - return value / 60 / 60 / 1000; - case 'day': - return value / 24 / 60 / 60 / 1000; - default: - return value; - } -}; - // eslint-disable-next-line func-names window.CONSTANTS = new (function() { this.MAX_LOGIN_TRIES = 3; @@ -129,12 +91,6 @@ window.CONSTANTS = new (function() { this.NOTIFICATION_ENABLE_TIMEOUT_SECONDS = 10; this.SESSION_ID_LENGTH = 66; - // TTL Defaults - this.TTL_DEFAULT_PAIRING_REQUEST = window.timeAsMs(2, 'minutes'); - this.TTL_DEFAULT_DEVICE_UNPAIRING = window.timeAsMs(4, 'days'); - this.TTL_DEFAULT_ONLINE_BROADCAST = window.timeAsMs(1, 'minute'); - this.TTL_DEFAULT_REGULAR_MESSAGE = window.timeAsMs(2, 'days'); - // Loki Name System (LNS) this.LNS_DEFAULT_LOOKUP_TIMEOUT = 6000; // Minimum nodes version for LNS lookup diff --git a/stylesheets/_session_left_pane.scss b/stylesheets/_session_left_pane.scss index a5ed85e82..ab1341ba7 100644 --- a/stylesheets/_session_left_pane.scss +++ b/stylesheets/_session_left_pane.scss @@ -242,7 +242,7 @@ $session-compose-margin: 20px; align-items: center; overflow-y: auto; overflow-x: hidden; - + .session-icon .exit { padding: 13px; } diff --git a/ts/components/session/SessionIdEditable.tsx b/ts/components/session/SessionIdEditable.tsx index e2a6cd134..36dbd1843 100644 --- a/ts/components/session/SessionIdEditable.tsx +++ b/ts/components/session/SessionIdEditable.tsx @@ -29,7 +29,14 @@ export class SessionIdEditable extends React.PureComponent { } public render() { - const { placeholder, editable, text, value, maxLength, isGroup } = this.props; + const { + placeholder, + editable, + text, + value, + maxLength, + isGroup, + } = this.props; return (
{ >