diff --git a/_locales/en/messages.json b/_locales/en/messages.json index a29bb9195..e7420151b 100644 --- a/_locales/en/messages.json +++ b/_locales/en/messages.json @@ -1692,5 +1692,17 @@ }, "unlock": { "message": "Unlock" + }, + "setPassword": { + "message": "Set Password", + "description": "Button action that the user can click to set a password" + }, + "changePassword": { + "message": "Set Password", + "description": "Button action that the user can click to change a password" + }, + "removePassword": { + "message": "Set Password", + "description": "Button action that the user can click to remove a password" } } diff --git a/js/background.js b/js/background.js index dc94d55ba..faef150b6 100644 --- a/js/background.js +++ b/js/background.js @@ -610,6 +610,12 @@ window.log.error('Error showing PoW cog'); } }); + + Whisper.events.on('password-updated', () => { + if (appView && appView.inboxView) { + appView.inboxView.trigger('password-updated'); + } + }); } window.getSyncRequest = () => diff --git a/js/views/inbox_view.js b/js/views/inbox_view.js index 643cd135e..dc52dbbbe 100644 --- a/js/views/inbox_view.js +++ b/js/views/inbox_view.js @@ -6,6 +6,7 @@ /* global Whisper: false */ /* global textsecure: false */ /* global clipboard: false */ +/* global Signal: false */ // eslint-disable-next-line func-names (function() { @@ -106,6 +107,8 @@ el: this.$('.main-header-placeholder'), items: this.getMainHeaderItems(), }); + this.onPasswordUpdated(); + this.on('password-updated', () => this.onPasswordUpdated()); this.conversation_stack = new Whisper.ConversationStack({ el: this.$('.conversation-stack'), @@ -340,8 +343,25 @@ this._mainHeaderItem('editDisplayName', () => { window.Whisper.events.trigger('onEditProfile'); }), + ...this.passwordHeaderItems || [], ]; }, + async onPasswordUpdated() { + const hasPassword = await Signal.Data.getPasswordHash(); + const items = this.getMainHeaderItems(); + if (hasPassword) { + items.push( + this._mainHeaderItem('changePassword'), + this._mainHeaderItem('removePassword') + ); + } else { + items.push( + this._mainHeaderItem('setPassword') + ); + } + + this.mainHeaderView.updateItems(items); + }, _mainHeaderItem(textKey, onClick) { return { id: textKey, diff --git a/js/views/main_header_view.js b/js/views/main_header_view.js index 6366f914d..77da0632e 100644 --- a/js/views/main_header_view.js +++ b/js/views/main_header_view.js @@ -1,4 +1,4 @@ -/* global Whisper, textsecure, ConversationController, Signal, i18n */ +/* global Whisper, textsecure, ConversationController, Signal */ // eslint-disable-next-line func-names (function() { @@ -14,8 +14,6 @@ 'click .copy-key': 'onCopyKey', }, initialize(options) { - this.items = options.items || []; - this.ourNumber = textsecure.storage.user.getNumber(); const me = ConversationController.getOrCreate(this.ourNumber, 'private'); @@ -34,14 +32,19 @@ this.$content = this.$('.main-header-content-wrapper'); this.$content.hide(); - this.registerCallbacks(); + this.updateItems(options.items); }, - registerCallbacks() { - this.items.forEach(item => { + updateItems(items) { + this.$content.html(''); + (items || []).forEach(item => { + // Add the item + this.$content.append(`