constants-to-ts

pull/1242/head
Vincent 5 years ago
parent 506b55bfe2
commit c020eddef6

@ -878,7 +878,7 @@
"message": "Waiting for device to register..."
},
"pairNewDevicePrompt": {
"message": "Scan the QR Code on your other device"
"message": "Scan the QR Code on your secondary device"
},
"pairedDevices": {
"message": "Linked Devices"
@ -2240,7 +2240,7 @@
"message": "Remove"
},
"invalidHexId": {
"message": "Invalid Session ID",
"message": "Invalid Session ID or LNS Name",
"description": "Error string shown when user types an invalid pubkey hex string"
},
"invalidLnsFormat": {
@ -2360,7 +2360,7 @@
"message": "Say hello to your Session ID"
},
"allUsersAreRandomly...": {
"message": "Your Session ID is the unique address people can use to contact you on Session. With no connection to your real identity, your Session ID is totally anonymous and private by design."
"message": "Your Session ID is the unique address people can use to contact you on Session. Your Session ID is totally private, anonymous, and has no connection to your real identity."
},
"getStarted": {
"message": "Get started"
@ -2409,7 +2409,7 @@
"message": "Enter your <strong>Session ID</strong> below to link this device to your <strong>Session ID</strong>."
},
"enterSessionIDHere": {
"message": "Enter your Session ID"
"message": "Enter your Session ID here"
},
"continueYourSession": {
"message": "Continue Your Session"
@ -2460,7 +2460,7 @@
"message": "Enter Session ID"
},
"pasteSessionIDRecipient": {
"message": "Enter a Session ID"
"message": "Enter a Session ID or LNS name"
},
"usersCanShareTheir...": {
"message": "Users can share their Session ID from their account settings, or by sharing their QR code."
@ -2604,10 +2604,10 @@
"message": "Secret words"
},
"pairingDevice": {
"message": "Linking Device"
"message": "Pairing Device"
},
"gotPairingRequest": {
"message": "Linking request received"
"message": "Pairing request received"
},
"devicePairedSuccessfully": {
"message": "Device linked successfully"

@ -14,14 +14,14 @@ const NUM_SEND_CONNECTIONS = 3;
const getTTLForType = type => {
switch (type) {
case 'pairing-request':
return window.CONSTANTS.TTL_DEFAULT_PAIRING_REQUEST;
case 'device-unpairing':
return window.CONSTANTS.TTL_DEFAULT_DEVICE_UNPAIRING;
return 4 * 24 * 60 * 60 * 1000; // 4 days for device unpairing
case 'onlineBroadcast':
return window.CONSTANTS.TTL_DEFAULT_ONLINE_BROADCAST;
return 60 * 1000; // 1 minute for online broadcast message
case 'pairing-request':
return 2 * 60 * 1000; // 2 minutes for pairing requests
default:
return window.CONSTANTS.TTL_DEFAULT_REGULAR_MESSAGE;
return 24 * 60 * 60 * 1000; // 1 day default for any other message
}
};

@ -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

@ -5,6 +5,7 @@
.panel,
.panel-wrapper {
height: calc(100% - #{$header-height});
overflow-y: scroll;
}
@ -21,16 +22,9 @@
.panel-wrapper {
display: flex;
flex-direction: column;
flex-grow: 1;
overflow: initial;
}
.conversation-content-left {
display: flex;
flex-direction: column;
flex-grow: 1;
}
.main.panel {
.discussion-container {
flex-grow: 1;

@ -1350,16 +1350,6 @@ label {
overflow: hidden;
user-select: all;
overflow-y: auto;
padding: 0px 5px 20px 5px;
&.session-id-editable-textarea:placeholder-shown {
padding: 20px 5px 0px 5px;
}
&.group-id-editable-textarea {
margin-top: 15px;
white-space: nowrap;
}
}
input {
@ -1604,10 +1594,6 @@ input {
}
}
.create-group-name-input {
display: flex;
justify-content: center;
width: 100%;
.session-id-editable {
height: 60px !important;

@ -238,11 +238,9 @@ $session-compose-margin: 20px;
box-shadow: 0 0 100px 0 rgba(0, 0, 0, 0.5);
display: flex;
flex-direction: column;
flex-grow: 1;
align-items: center;
overflow-y: auto;
overflow-x: hidden;
.session-icon .exit {
padding: 13px;
}
@ -309,8 +307,6 @@ $session-compose-margin: 20px;
}
.session-id-editable {
width: 90%;
textarea::-webkit-inner-spin-button {
margin: 0px 20px;
width: -webkit-fill-available;

@ -196,7 +196,6 @@ export class SessionClosableOverlay extends React.Component<Props, State> {
editable={!noContactsForClosedGroup}
placeholder={placeholder}
value={groupName}
isGroup={true}
maxLength={window.CONSTANTS.MAX_GROUPNAME_LENGTH}
onChange={this.onGroupNameChanged}
onPressEnter={() => onButtonClick(groupName, selectedMembers)}

@ -9,7 +9,6 @@ interface Props {
onChange?: any;
onPressEnter?: any;
maxLength?: number;
isGroup?: boolean;
}
export class SessionIdEditable extends React.PureComponent<Props> {
@ -29,7 +28,7 @@ export class SessionIdEditable extends React.PureComponent<Props> {
}
public render() {
const { placeholder, editable, text, value, maxLength, isGroup } = this.props;
const { placeholder, editable, text, value, maxLength } = this.props;
return (
<div
@ -39,8 +38,7 @@ export class SessionIdEditable extends React.PureComponent<Props> {
)}
>
<textarea
className={classNames(
isGroup ? 'group-id-editable-textarea' : 'session-id-editable-textarea')}
className="session-id-editable-textarea"
ref={this.inputRef}
placeholder={placeholder}
disabled={!editable}

@ -10,6 +10,8 @@ import {
import { UserUtil } from '../../../util';
import { MultiDeviceProtocol } from '../../../session/protocols';
import { PubKey } from '../../../session/types';
import { Constants } from '../../../session';
import { NumberUtils } from '../../../session/utils';
export enum SessionSettingCategory {
Appearance = 'appearance',
@ -441,10 +443,7 @@ export class SettingsView extends React.Component<SettingsViewProps, State> {
id: 'message-ttl',
title: window.i18n('messageTTL'),
description: window.i18n('messageTTLSettingDescription'),
// TODO: Revert
// TTL set to 2 days for mobile push notification compabability
// temporary fix .t 13/07/2020
hidden: true,
hidden: false,
type: SessionSettingType.Slider,
category: SessionSettingCategory.Privacy,
setFn: undefined,
@ -455,10 +454,7 @@ export class SettingsView extends React.Component<SettingsViewProps, State> {
step: 6,
min: 12,
max: 96,
defaultValue: window.msAsUnit(
window.CONSTANTS.TTL_DEFAULT_REGULAR_MESSAGE,
'hour'
),
defaultValue: 24,
info: (value: number) => `${value} Hours`,
},
confirmationDialogParams: undefined,

@ -0,0 +1,13 @@
import { NumberUtils } from './utils';
// Default TTL
export const TTL_DEFAULT = {
PAIRING_REQUEST: NumberUtils.timeAsMs(2, 'minutes'),
DEVICE_UNPAIRING: NumberUtils.timeAsMs(4, 'days'),
SESSION_REQUEST: NumberUtils.timeAsMs(4, 'days'),
SESSION_ESTABLISHED: NumberUtils.timeAsMs(2, 'days'),
END_SESSION_MESSAGE: NumberUtils.timeAsMs(4, 'days'),
TYPING_MESSAGE: NumberUtils.timeAsMs(1, 'minute'),
ONLINE_BROADCAST: NumberUtils.timeAsMs(1, 'minute'),
REGULAR_MESSAGE: NumberUtils.timeAsMs(2, 'days'),
};

@ -2,7 +2,8 @@ import * as Messages from './messages';
import * as Protocols from './protocols';
import * as Types from './types';
import * as Utils from './utils';
import * as Constants from './constants';
export * from './instance';
export { Messages, Utils, Protocols, Types };
export { Messages, Utils, Protocols, Types, Constants };

@ -1,5 +1,6 @@
import { Message } from '../Message';
import { SignalService } from '../../../../protobuf';
import { Constants } from '../../..';
export abstract class ContentMessage extends Message {
public plainTextBuffer(): Uint8Array {
@ -14,7 +15,6 @@ export abstract class ContentMessage extends Message {
* this value can be used in all child classes
*/
protected getDefaultTTL(): number {
// 1 day default for any other message
return 24 * 60 * 60 * 1000;
return Constants.TTL_DEFAULT.REGULAR_MESSAGE;
}
}

@ -1,9 +1,10 @@
import { SessionRequestMessage } from './SessionRequestMessage';
import { SignalService } from '../../../../protobuf';
import { Constants } from '../../..';
export class EndSessionMessage extends SessionRequestMessage {
public ttl(): number {
return 4 * 24 * 60 * 60 * 1000; // 4 days
return Constants.TTL_DEFAULT.END_SESSION_MESSAGE;
}
protected contentProto(): SignalService.Content {

@ -2,6 +2,7 @@ import { ContentMessage } from './ContentMessage';
import { SignalService } from '../../../../protobuf';
import * as crypto from 'crypto';
import { MessageParams } from '../Message';
import { Constants } from '../../..';
export class SessionEstablishedMessage extends ContentMessage {
public readonly padding: Buffer;
@ -18,7 +19,7 @@ export class SessionEstablishedMessage extends ContentMessage {
this.padding = crypto.randomBytes(paddingLength);
}
public ttl(): number {
return 5 * 60 * 1000;
return Constants.TTL_DEFAULT.SESSION_ESTABLISHED;
}
protected contentProto(): SignalService.Content {

@ -1,6 +1,7 @@
import { ContentMessage } from './ContentMessage';
import { SignalService } from '../../../../protobuf';
import { MessageParams } from '../Message';
import { Constants } from '../../..';
export interface PreKeyBundleType {
identityKey: Uint8Array;
@ -17,7 +18,6 @@ interface SessionRequestParams extends MessageParams {
}
export class SessionRequestMessage extends ContentMessage {
public static readonly ttl = 4 * 24 * 60 * 60 * 1000; // 4 days
private readonly preKeyBundle: PreKeyBundleType;
constructor(params: SessionRequestParams) {
@ -25,8 +25,12 @@ export class SessionRequestMessage extends ContentMessage {
this.preKeyBundle = params.preKeyBundle;
}
public static getTTL(): number {
return Constants.TTL_DEFAULT.SESSION_REQUEST;
}
public ttl(): number {
return SessionRequestMessage.ttl;
return SessionRequestMessage.getTTL();
}
protected getPreKeyBundleMessage(): SignalService.PreKeyBundleMessage {

@ -1,9 +1,9 @@
import { ContentMessage } from './ContentMessage';
import { SignalService } from '../../../../protobuf';
import { TextEncoder } from 'util';
import { MessageParams } from '../Message';
import { StringUtils } from '../../../utils';
import { PubKey } from '../../../types';
import { Constants } from '../../..';
interface TypingMessageParams extends MessageParams {
isTyping: boolean;
@ -26,7 +26,7 @@ export class TypingMessage extends ContentMessage {
}
public ttl(): number {
return 60 * 1000; // 1 minute for typing indicators
return Constants.TTL_DEFAULT.TYPING_MESSAGE;
}
protected contentProto(): SignalService.Content {

@ -1,9 +1,10 @@
import { DataMessage } from './DataMessage';
import { SignalService } from '../../../../../protobuf';
import { Constants } from '../../../..';
export class DeviceUnlinkMessage extends DataMessage {
public ttl(): number {
return 4 * 24 * 60 * 60 * 1000; // 4 days for device unlinking
return Constants.TTL_DEFAULT.DEVICE_UNPAIRING;
}
public dataProto(): SignalService.DataMessage {

@ -1,6 +1,7 @@
import { ContentMessage } from '../ContentMessage';
import { SignalService } from '../../../../../protobuf';
import { MessageParams } from '../../Message';
import { Constants } from '../../../..';
export interface DeviceLinkMessageParams extends MessageParams {
primaryDevicePubKey: string;
secondaryDevicePubKey: string;
@ -20,7 +21,7 @@ export class DeviceLinkRequestMessage extends ContentMessage {
}
public ttl(): number {
return 2 * 60 * 1000; // 2 minutes for pairing requests
return Constants.TTL_DEFAULT.PAIRING_REQUEST;
}
protected getDataMessage(): SignalService.DataMessage | undefined {

@ -82,7 +82,7 @@ export class SessionProtocol {
const now = Date.now();
const sentTimestamps = Object.entries(this.sentSessionsTimestamp);
const promises = sentTimestamps.map(async ([device, sent]) => {
const expireTime = sent + SessionRequestMessage.ttl;
const expireTime = sent + SessionRequestMessage.getTTL();
// Check if we need to send a session request
if (now < expireTime) {
return;

@ -0,0 +1,47 @@
type TimeUnit =
| 'second'
| 'seconds'
| 'minute'
| 'minutes'
| 'hour'
| 'hours'
| 'day'
| 'days';
export const timeAsMs = (value: number, unit: TimeUnit) => {
// 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;
}
};
export const msAsUnit = (value: number, unit: TimeUnit) => {
// 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;
}
};

@ -2,6 +2,7 @@ import * as MessageUtils from './Messages';
import * as GroupUtils from './Groups';
import * as SyncMessageUtils from './SyncMessage';
import * as StringUtils from './String';
import * as NumberUtils from './Number';
import * as PromiseUtils from './Promise';
import * as ProtobufUtils from './Protobuf';
@ -14,6 +15,7 @@ export {
SyncMessageUtils,
GroupUtils,
StringUtils,
NumberUtils,
PromiseUtils,
ProtobufUtils,
};

@ -124,7 +124,7 @@ describe('SessionProtocol', () => {
});
// Set the time just before expiry
clock.tick(SessionRequestMessage.ttl - 100);
clock.tick(SessionRequestMessage.getTTL() - 100);
await SessionProtocol.checkSessionRequestExpiry();
expect(getItemById.calledWith('sentSessionsTimestamp'));
@ -140,7 +140,7 @@ describe('SessionProtocol', () => {
});
// Expire the request
clock.tick(SessionRequestMessage.ttl + 100);
clock.tick(SessionRequestMessage.getTTL() + 100);
await SessionProtocol.checkSessionRequestExpiry();
expect(getItemById.calledWith('sentSessionsTimestamp'));
@ -159,7 +159,7 @@ describe('SessionProtocol', () => {
sandbox.stub(SessionProtocol, 'sendSessionRequestIfNeeded').resolves();
// Expire the request
clock.tick(SessionRequestMessage.ttl + 100);
clock.tick(SessionRequestMessage.getTTL() + 100);
await SessionProtocol.checkSessionRequestExpiry();
expect(getItemById.calledWith('sentSessionsTimestamp'));

@ -49,7 +49,6 @@ describe('MessageSender', () => {
[string, Uint8Array, number, number],
Promise<void>
>();
TestUtils.stubWindow('lokiMessageAPI', {
sendMessage: lokiMessageAPISendStub,
});

1
ts/window.d.ts vendored

@ -19,7 +19,6 @@ If you import anything in global.d.ts, the type system won't work correctly.
declare global {
interface Window {
CONSTANTS: any;
msAsUnit: any;
ConversationController: any;
Events: any;
Lodash: any;

Loading…
Cancel
Save