From 87113b6cc1263037b263f30541ebc0b8039f614a Mon Sep 17 00:00:00 2001 From: Mikunj Date: Fri, 11 Jan 2019 15:34:22 +1100 Subject: [PATCH] Added message ttl setting storage --- js/background.js | 16 ++++++++++++++++ js/settings_start.js | 1 + main.js | 3 +++ preload.js | 10 ++++++++++ settings_preload.js | 3 +++ 5 files changed, 33 insertions(+) diff --git a/js/background.js b/js/background.js index e53e79d5b..43fe75458 100644 --- a/js/background.js +++ b/js/background.js @@ -221,6 +221,10 @@ } first = false; + // The min and max message ttl value + const MIN_MESSAGE_TTL = 12; + const MAX_MESSAGE_TTL = 96; + // These make key operations available to IPC handlers created in preload.js window.Events = { getDeviceName: () => textsecure.storage.user.getDeviceName(), @@ -237,6 +241,18 @@ window.setMenuBarVisibility(!value); }, + getMessageTTL: () => { + // Make sure the ttl is between a given range + const current = storage.get('message-ttl', 24); + return Math.max(MIN_MESSAGE_TTL, Math.min(current, MAX_MESSAGE_TTL)); + }, + setMessageTTL: value => { + // Make sure the ttl is between a given range and is valid + const ttl = (typeof value !== 'number') ? 24 : value; + const current = Math.max(MIN_MESSAGE_TTL, Math.min(ttl, MAX_MESSAGE_TTL)); + storage.put('message-ttl', current); + }, + getReadReceiptSetting: () => storage.get('read-receipt-setting'), setReadReceiptSetting: value => diff --git a/js/settings_start.js b/js/settings_start.js index 01c47aa5c..02b842456 100644 --- a/js/settings_start.js +++ b/js/settings_start.js @@ -18,6 +18,7 @@ const getInitialData = async () => ({ themeSetting: await window.getThemeSetting(), hideMenuBar: await window.getHideMenuBar(), + messageTTL: await window.getMessageTTL(), readReceiptSetting: await window.getReadReceiptSetting(), notificationSetting: await window.getNotificationSetting(), audioNotification: await window.getAudioNotification(), diff --git a/main.js b/main.js index 5c26db5fe..c29c01ca5 100644 --- a/main.js +++ b/main.js @@ -1053,6 +1053,9 @@ installSettingsSetter('theme-setting'); installSettingsGetter('hide-menu-bar'); installSettingsSetter('hide-menu-bar'); +installSettingsGetter('message-ttl'); +installSettingsSetter('message-ttl'); + installSettingsGetter('read-receipt-setting'); installSettingsSetter('read-receipt-setting'); installSettingsGetter('notification-setting'); diff --git a/preload.js b/preload.js index e6942138a..36d8ebcac 100644 --- a/preload.js +++ b/preload.js @@ -154,6 +154,16 @@ installSetter('theme-setting', 'setThemeSetting'); installGetter('hide-menu-bar', 'getHideMenuBar'); installSetter('hide-menu-bar', 'setHideMenuBar'); +// Get the message TTL setting +window.getMessageTTL = () => { + if (window.Events.getMessageTTL) { + return window.Events.getMessageTTL(); + } + return null; +} +installGetter('message-ttl', 'getMessageTTL'); +installSetter('message-ttl', 'setMessageTTL'); + installGetter('read-receipt-setting', 'getReadReceiptSetting'); installSetter('read-receipt-setting', 'setReadReceiptSetting'); installGetter('notification-setting', 'getNotificationSetting'); diff --git a/settings_preload.js b/settings_preload.js index 1e20e8717..d772fec4e 100644 --- a/settings_preload.js +++ b/settings_preload.js @@ -41,6 +41,9 @@ window.setHideMenuBar = makeSetter('hide-menu-bar'); window.getSpellCheck = makeGetter('spell-check'); window.setSpellCheck = makeSetter('spell-check'); +window.getMessageTTL = makeGetter('message-ttl'); +window.setMessageTTL = makeSetter('message-ttl'); + window.getReadReceiptSetting = makeGetter('read-receipt-setting'); window.setReadReceiptSetting = makeSetter('read-receipt-setting'); window.getNotificationSetting = makeGetter('notification-setting');