From bed9ce5be228a91108abc679b930d234a1429ca1 Mon Sep 17 00:00:00 2001 From: Beaudan Date: Thu, 22 Nov 2018 16:49:15 +1100 Subject: [PATCH] Added read receipt checkbox to the settings window which enables or disables the sending and receiving of read receipts --- _locales/en/messages.json | 4 ++++ js/background.js | 4 ++++ js/settings_start.js | 1 + js/views/settings_view.js | 26 +++++++++++++++++++++++++- main.js | 2 ++ preload.js | 2 ++ settings.html | 4 ++++ settings_preload.js | 2 ++ 8 files changed, 44 insertions(+), 1 deletion(-) diff --git a/_locales/en/messages.json b/_locales/en/messages.json index 8398fba44..734b4e7b8 100644 --- a/_locales/en/messages.json +++ b/_locales/en/messages.json @@ -1050,6 +1050,10 @@ "message": "Notifications", "description": "Header for notification settings" }, + "readReceiptSettingDescription": { + "message": "Enable the sending and receiving of read receipts", + "description": "Description of the read receipts setting" + }, "notificationSettingsDialog": { "message": "When messages arrive, display notifications that reveal:", "description": "Explain the purpose of the notification settings" diff --git a/js/background.js b/js/background.js index d0059dd0e..54ca0bcc9 100644 --- a/js/background.js +++ b/js/background.js @@ -236,6 +236,10 @@ window.setMenuBarVisibility(!value); }, + getReadReceiptSetting: () => + storage.get('read-receipt-setting'), + setReadReceiptSetting: value => + storage.put('read-receipt-setting', value), getNotificationSetting: () => storage.get('notification-setting', 'message'), setNotificationSetting: value => diff --git a/js/settings_start.js b/js/settings_start.js index f29d09224..01c47aa5c 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(), + readReceiptSetting: await window.getReadReceiptSetting(), notificationSetting: await window.getNotificationSetting(), audioNotification: await window.getAudioNotification(), diff --git a/js/views/settings_view.js b/js/views/settings_view.js index 5604e8599..cc18b8b08 100644 --- a/js/views/settings_view.js +++ b/js/views/settings_view.js @@ -50,6 +50,25 @@ }, }); + const ReadReceiptSettingView = Whisper.View.extend({ + initialize(options) { + this.value = options.value; + this.setFn = options.setFn; + this.populate(); + }, + events: { + change: 'change', + }, + change(e) { + this.value = e.target.checked; + this.setFn(this.value); + window.log.info('read-receipt-setting changed to', this.value); + }, + populate() { + this.$('input').prop('checked', Boolean(this.value)); + }, + }); + const RadioButtonGroupView = Whisper.View.extend({ initialize(options) { this.name = options.name; @@ -117,7 +136,11 @@ value: window.initialData.mediaPermissions, setFn: window.setMediaPermissions, }); - + new ReadReceiptSettingView({ + el: this.$('.read-receipt-setting'), + value: window.initialData.readReceiptSetting, + setFn: window.setReadReceiptSetting, + }); const blockedNumberView = new Whisper.BlockedNumberView().render(); this.$('.blocked-user-setting').append(blockedNumberView.el); @@ -152,6 +175,7 @@ clearDataExplanation: i18n('clearDataExplanation'), permissions: i18n('permissions'), mediaPermissionsDescription: i18n('mediaPermissionsDescription'), + readReceiptSettingDescription: i18n('readReceiptSettingDescription'), spellCheckHeader: i18n('spellCheck'), spellCheckDescription: i18n('spellCheckDescription'), blockedHeader: 'Blocked Users', diff --git a/main.js b/main.js index 33ab52a21..1e794c6da 100644 --- a/main.js +++ b/main.js @@ -905,6 +905,8 @@ installSettingsSetter('theme-setting'); installSettingsGetter('hide-menu-bar'); installSettingsSetter('hide-menu-bar'); +installSettingsGetter('read-receipt-setting'); +installSettingsSetter('read-receipt-setting'); installSettingsGetter('notification-setting'); installSettingsSetter('notification-setting'); installSettingsGetter('audio-notification'); diff --git a/preload.js b/preload.js index 821d4ea8f..6fe8ecc96 100644 --- a/preload.js +++ b/preload.js @@ -141,6 +141,8 @@ installSetter('theme-setting', 'setThemeSetting'); installGetter('hide-menu-bar', 'getHideMenuBar'); installSetter('hide-menu-bar', 'setHideMenuBar'); +installGetter('read-receipt-setting', 'getReadReceiptSetting'); +installSetter('read-receipt-setting', 'setReadReceiptSetting'); installGetter('notification-setting', 'getNotificationSetting'); installSetter('notification-setting', 'setNotificationSetting'); installGetter('audio-notification', 'getAudioNotification'); diff --git a/settings.html b/settings.html index 41db19de6..96bbfb556 100644 --- a/settings.html +++ b/settings.html @@ -105,6 +105,10 @@ +
+ + +

diff --git a/settings_preload.js b/settings_preload.js index 55decf0b8..1e20e8717 100644 --- a/settings_preload.js +++ b/settings_preload.js @@ -41,6 +41,8 @@ window.setHideMenuBar = makeSetter('hide-menu-bar'); window.getSpellCheck = makeGetter('spell-check'); window.setSpellCheck = makeSetter('spell-check'); +window.getReadReceiptSetting = makeGetter('read-receipt-setting'); +window.setReadReceiptSetting = makeSetter('read-receipt-setting'); window.getNotificationSetting = makeGetter('notification-setting'); window.setNotificationSetting = makeSetter('notification-setting'); window.getAudioNotification = makeGetter('audio-notification');