From 449f44cc5a00c84fef2f2917a9cdcfad161b8631 Mon Sep 17 00:00:00 2001 From: Mikunj Date: Tue, 27 Nov 2018 11:47:20 +1100 Subject: [PATCH] Added changing user nicknames. --- _locales/en/messages.json | 8 ++++++++ js/conversation_controller.js | 3 +++ js/views/conversation_view.js | 19 +++++++++++++++++++ js/views/nickname_dialog_view.js | 2 +- .../conversation/ConversationHeader.tsx | 13 +++++++++++++ 5 files changed, 44 insertions(+), 1 deletion(-) diff --git a/_locales/en/messages.json b/_locales/en/messages.json index 14915f324..9f5dc789c 100644 --- a/_locales/en/messages.json +++ b/_locales/en/messages.json @@ -1349,6 +1349,14 @@ "message": "Disappearing messages", "description": "Conversation menu option to enable disappearing messages" }, + "changeNickname": { + "message": "Change nickname", + "description": "Conversation menu option to change user nickname" + }, + "clearNickname": { + "message": "Clear nickname", + "description": "Conversation menu option to clear user nickname" + }, "timerOption_0_seconds_abbreviated": { "message": "off", "description": diff --git a/js/conversation_controller.js b/js/conversation_controller.js index 035963e3b..dc11eb45e 100644 --- a/js/conversation_controller.js +++ b/js/conversation_controller.js @@ -226,6 +226,9 @@ await Promise.all( conversations.map(conversation => conversation.updateLastMessage()) ); + + // Update profiles + conversations.map(conversation => conversation.updateProfile()); window.log.info('ConversationController: done with initial fetch'); } catch (error) { window.log.error( diff --git a/js/views/conversation_view.js b/js/views/conversation_view.js index 588babf78..e8ff75c5c 100644 --- a/js/views/conversation_view.js +++ b/js/views/conversation_view.js @@ -174,6 +174,7 @@ name: item.getName(), value: item.get('seconds'), })), + hasNickname: !!storage.getNickname(this.model.id), onSetDisappearingMessages: seconds => this.setDisappearingMessages(seconds), @@ -204,6 +205,24 @@ onUnblockUser: () => { this.model.unblock(); }, + onChangeNickname: () => { + window.Whisper.events.trigger('showNicknameDialog', { + pubKey: this.model.id, + nickname: storage.getNickname(this.model.id), + onOk: async (newName) => { + if (_.isEmpty(newName)) { + await storage.removeNickname(this.model.id) + } else { + await storage.saveNickname(this.model.id, newName); + } + this.model.updateProfile(); + }, + }); + }, + onClearNickname: async () => { + await storage.removeNickname(this.model.id); + this.model.updateProfile(); + }, }; }; this.titleView = new Whisper.ReactWrapperView({ diff --git a/js/views/nickname_dialog_view.js b/js/views/nickname_dialog_view.js index 8d4d092eb..1010068db 100644 --- a/js/views/nickname_dialog_view.js +++ b/js/views/nickname_dialog_view.js @@ -11,7 +11,7 @@ templateName: 'nickname-dialog', initialize(options) { this.message = options.message; - this.name = options.name; + this.name = options.name || ''; this.resolve = options.resolve; this.okText = options.okText || i18n('ok'); diff --git a/ts/components/conversation/ConversationHeader.tsx b/ts/components/conversation/ConversationHeader.tsx index 0162243f4..490fd541e 100644 --- a/ts/components/conversation/ConversationHeader.tsx +++ b/ts/components/conversation/ConversationHeader.tsx @@ -36,6 +36,7 @@ interface Props { expirationSettingName?: string; showBackButton: boolean; timerOptions: Array; + hasNickname?: boolean; onSetDisappearingMessages: (seconds: number) => void; onDeleteMessages: () => void; @@ -48,6 +49,9 @@ interface Props { onBlockUser: () => void; onUnblockUser: () => void; + + onClearNickname: () => void; + onChangeNickname: () => void; } export class ConversationHeader extends React.Component { @@ -186,6 +190,9 @@ export class ConversationHeader extends React.Component { timerOptions, onBlockUser, onUnblockUser, + hasNickname, + onClearNickname, + onChangeNickname, } = this.props; const disappearingTitle = i18n('disappearingMessages') as any; @@ -225,6 +232,12 @@ export class ConversationHeader extends React.Component { {!isMe ? ( {blockTitle} ) : null} + {!isMe ? ( + {i18n('changeNickname')} + ) : null} + {!isMe && hasNickname ? ( + {i18n('clearNickname')} + ) : null} {i18n('deleteMessages')} );