From fd746a475a3f4f0b4b9e52a17b5a3a61b2ac27c8 Mon Sep 17 00:00:00 2001 From: Vincent Date: Mon, 13 Jul 2020 14:02:08 +1000 Subject: [PATCH] ui polished and ttl constants --- _locales/en/messages.json | 12 +- libtextsecure/outgoing_message.js | 10 +- preload.js | 44 ++++++ stylesheets/_conversation.scss | 8 +- .../session/settings/SessionSettings.tsx | 10 +- ts/session/types/ClosedGroup.ts | 134 ------------------ ts/test/session/sending/MessageSender_test.ts | 2 +- ts/util/user.ts | 9 -- ts/window.d.ts | 1 + 9 files changed, 72 insertions(+), 158 deletions(-) delete mode 100644 ts/session/types/ClosedGroup.ts diff --git a/_locales/en/messages.json b/_locales/en/messages.json index 7fc3b92b3..221572ebb 100644 --- a/_locales/en/messages.json +++ b/_locales/en/messages.json @@ -878,7 +878,7 @@ "message": "Waiting for device to register..." }, "pairNewDevicePrompt": { - "message": "Scan the QR Code on your secondary device" + "message": "Scan the QR Code on your other device" }, "pairedDevices": { "message": "Linked Devices" @@ -2240,7 +2240,7 @@ "message": "Remove" }, "invalidHexId": { - "message": "Invalid Session ID or LNS Name", + "message": "Invalid Session ID", "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. Your Session ID is totally private, anonymous, and has no connection to your real identity." + "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." }, "getStarted": { "message": "Get started" @@ -2460,7 +2460,7 @@ "message": "Enter Session ID" }, "pasteSessionIDRecipient": { - "message": "Enter a Session ID or LNS name" + "message": "Enter a Session ID" }, "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": "Pairing Device" + "message": "Linking Device" }, "gotPairingRequest": { - "message": "Pairing request received" + "message": "Linking request received" }, "devicePairedSuccessfully": { "message": "Device linked successfully" diff --git a/libtextsecure/outgoing_message.js b/libtextsecure/outgoing_message.js index 0dd3ed43a..0ad7e73cc 100644 --- a/libtextsecure/outgoing_message.js +++ b/libtextsecure/outgoing_message.js @@ -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 4 * 24 * 60 * 60 * 1000; // 4 days for device unpairing + return window.CONSTANTS.TTL_DEFAULT_DEVICE_UNPAIRING; case 'onlineBroadcast': - return 60 * 1000; // 1 minute for online broadcast message - case 'pairing-request': - return 2 * 60 * 1000; // 2 minutes for pairing requests + return window.CONSTANTS.TTL_DEFAULT_ONLINE_BROADCAST; default: - return 24 * 60 * 60 * 1000; // 1 day default for any other message + return window.CONSTANTS.TTL_DEFAULT_REGULAR_MESSAGE; } }; diff --git a/preload.js b/preload.js index 0a45db23f..db2fb75a6 100644 --- a/preload.js +++ b/preload.js @@ -75,6 +75,44 @@ 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; @@ -91,6 +129,12 @@ 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/_conversation.scss b/stylesheets/_conversation.scss index 6b0e38c39..1aaf0643f 100644 --- a/stylesheets/_conversation.scss +++ b/stylesheets/_conversation.scss @@ -5,7 +5,6 @@ .panel, .panel-wrapper { - height: calc(100% - #{$header-height}); overflow-y: scroll; } @@ -22,9 +21,16 @@ .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; diff --git a/ts/components/session/settings/SessionSettings.tsx b/ts/components/session/settings/SessionSettings.tsx index 9a3933f4d..1a173a5a5 100644 --- a/ts/components/session/settings/SessionSettings.tsx +++ b/ts/components/session/settings/SessionSettings.tsx @@ -441,7 +441,10 @@ export class SettingsView extends React.Component { id: 'message-ttl', title: window.i18n('messageTTL'), description: window.i18n('messageTTLSettingDescription'), - hidden: false, + // TODO: Revert + // TTL set to 2 days for mobile push notification compabability + // temporary fix .t 13/07/2020 + hidden: true, type: SessionSettingType.Slider, category: SessionSettingCategory.Privacy, setFn: undefined, @@ -452,7 +455,10 @@ export class SettingsView extends React.Component { step: 6, min: 12, max: 96, - defaultValue: 24, + defaultValue: window.msAsUnit( + window.CONSTANTS.TTL_DEFAULT_REGULAR_MESSAGE, + 'hour' + ), info: (value: number) => `${value} Hours`, }, confirmationDialogParams: undefined, diff --git a/ts/session/types/ClosedGroup.ts b/ts/session/types/ClosedGroup.ts deleted file mode 100644 index 0eddf992b..000000000 --- a/ts/session/types/ClosedGroup.ts +++ /dev/null @@ -1,134 +0,0 @@ - - -// This is the (Closed | Medium) Group equivalent to the SessionGroup type. - -import { PubKey } from '.'; -import { UserUtil } from '../../util'; - -enum ClosedGroupType { - SMALL, - MEDIUM, -} - -interface ClosedGroupParams { - id: PubKey; - type: ClosedGroupType; - admins: Array; - members: Array; -} - -class ClosedGroup { - public readonly id: PubKey; - public readonly type: ClosedGroupType; - public admins: Array; - public members: Array; - - constructor(params: ClosedGroupParams) { - this.id = params.id; - this.type = params.type; - this.admins = params.admins; - this.members = params.members; - } - - public static async create(name: string, type: ClosedGroupType, members: Array, onSuccess: any): Promise { - const { ConversationController, StringView, libsignal } = window; - - // Manage small group size - // TODO - Eventually we want to default to MediumGroups and abandon regular groups - // once medium groups have been thoroughly tested - if ( - type === ClosedGroupType.SMALL && - members.length === 0 || - members.length >= window.CONSTANTS.SMALL_GROUP_SIZE_LIMIT - ) { - console.warn(`ClosedGroup create: Cannot create a small group with more than ${window.CONSTANTS.SMALL_GROUP_SIZE_LIMIT} members`); - } - - const primaryDevice = UserUtil.getCurrentPrimaryDevicePubKey(); - const allMembers = [primaryDevice, ...members]; - - // Create Group Identity - const identityKeys = await libsignal.KeyHelper.generateIdentityKeyPair(); - - const keypair = await libsignal.KeyHelper.generateIdentityKeyPair(); - const id = StringView.arrayBufferToHex(keypair.pubKey); - - // Medium groups - const senderKey = (type === ClosedGroupType.MEDIUM) - ? await window.SenderKeyAPI.createSenderKeyForGroup(id, primaryDevice) - : undefined; - - const secretKey = (type === ClosedGroupType.MEDIUM) - ? identityKeys.privKey - : undefined; - - const groupSecretKeyHex = StringView.arrayBufferToHex( - identityKeys.privKey - ); - - const ev = { - groupDetails: { - id, - name, - members: allMembers, - recipients: allMembers, - active: true, - expireTimer: 0, - avatar: '', - secretKey, - senderKey, - is_medium_group: type === ClosedGroupType.MEDIUM, - }, - confirm: () => null, - }; - - await window.NewReceiver.onGroupReceived(ev); - } - - public static get(id: PubKey): ClosedGroup | undefined { - // Gets a closed group from its group id - return; - } - - public update(): Promise> { - // - } - - public updateMembers(): Promise> { - // Abstraction on update - - // Update the conversation and this object - } - - public async removeMembers(): Promise> { - // Abstraction on updateMembers - } - - public async addMembers(): Promise> { - // Abstraction on updateMembers - } - - public async setName(): Promise { - // Set or update the name of the group - } - - public leave() { - // Leave group - } - - - // static from(groupId) { - // // Returns a new instance from a groupId if it's valid - // const groupIdAsPubKey = groupId instanceof _1.PubKey - // ? groupId - // : _1.PubKey.from(groupId); - // openGroupParams = { - // groupId: - // }; - // return new SessionGroup(openGroupParams); - // } - - -} - - diff --git a/ts/test/session/sending/MessageSender_test.ts b/ts/test/session/sending/MessageSender_test.ts index ccc729c29..9fe7bf212 100644 --- a/ts/test/session/sending/MessageSender_test.ts +++ b/ts/test/session/sending/MessageSender_test.ts @@ -49,7 +49,7 @@ describe('MessageSender', () => { [string, Uint8Array, number, number], Promise >(); - + TestUtils.stubWindow('lokiMessageAPI', { sendMessage: lokiMessageAPISendStub, }); diff --git a/ts/util/user.ts b/ts/util/user.ts index bacaefb69..cea991b17 100644 --- a/ts/util/user.ts +++ b/ts/util/user.ts @@ -10,15 +10,6 @@ export async function getCurrentDevicePubKey(): Promise { return item.value.split('.')[0]; } -export async function getCurrentPrimaryDevicePubKey(): Promise { - const item = await getItemById('primaryDevicePubKey'); - if (!item || !item.value) { - return undefined; - } - - return item.value; -} - export async function getIdentityKeyPair(): Promise { const item = await getItemById('identityKey'); diff --git a/ts/window.d.ts b/ts/window.d.ts index 5ea680b4c..e05ae8c95 100644 --- a/ts/window.d.ts +++ b/ts/window.d.ts @@ -19,6 +19,7 @@ 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;