From a5f5b898f6499403816a5d2467e56077799c5af0 Mon Sep 17 00:00:00 2001 From: Vincent Date: Thu, 2 Jul 2020 16:23:43 +1000 Subject: [PATCH] fix-group-names --- js/views/create_group_dialog_view.js | 63 +++++++++++++++++++++++ ts/test/session/utils/SyncMessage_test.ts | 28 +++++----- 2 files changed, 75 insertions(+), 16 deletions(-) diff --git a/js/views/create_group_dialog_view.js b/js/views/create_group_dialog_view.js index 21d9aac5a..8e482e5e6 100644 --- a/js/views/create_group_dialog_view.js +++ b/js/views/create_group_dialog_view.js @@ -6,6 +6,69 @@ window.Whisper = window.Whisper || {}; + Whisper.UpdateGroupNameDialogView = Whisper.View.extend({ + className: 'loki-dialog modal', + initialize(groupConvo) { + this.groupName = groupConvo.get('name'); + + this.conversation = groupConvo; + this.titleText = i18n('updateGroupDialogTitle'); + this.close = this.close.bind(this); + this.onSubmit = this.onSubmit.bind(this); + this.isPublic = groupConvo.isPublic(); + this.groupId = groupConvo.id; + this.members = groupConvo.get('members') || []; + this.avatarPath = groupConvo.getAvatarPath(); + + const ourPK = textsecure.storage.user.getNumber(); + + this.isAdmin = groupConvo.get('groupAdmins').includes(ourPK); + + // public chat settings overrides + if (this.isPublic) { + // fix the title + this.titleText = `${i18n('updatePublicGroupDialogTitle')}: ${ + this.groupName + }`; + // I'd much prefer to integrate mods with groupAdmins + // but lets discuss first... + this.isAdmin = groupConvo.isModerator( + window.storage.get('primaryDevicePubKey') + ); + } + + this.$el.focus(); + this.render(); + }, + render() { + this.dialogView = new Whisper.ReactWrapperView({ + className: 'create-group-dialog', + Component: window.Signal.Components.UpdateGroupNameDialog, + props: { + titleText: this.titleText, + isPublic: this.isPublic, + groupName: this.groupName, + okText: i18n('ok'), + cancelText: i18n('cancel'), + isAdmin: this.isAdmin, + i18n, + onSubmit: this.onSubmit, + onClose: this.close, + avatarPath: this.avatarPath, + }, + }); + + this.$el.append(this.dialogView.el); + return this; + }, + onSubmit(groupName, avatar) { + window.doUpdateGroup(this.groupId, groupName, this.members, avatar); + }, + close() { + this.remove(); + }, + }); + Whisper.UpdateGroupMembersDialogView = Whisper.View.extend({ className: 'loki-dialog modal', initialize(groupConvo) { diff --git a/ts/test/session/utils/SyncMessage_test.ts b/ts/test/session/utils/SyncMessage_test.ts index df14f6627..ff6f168d9 100644 --- a/ts/test/session/utils/SyncMessage_test.ts +++ b/ts/test/session/utils/SyncMessage_test.ts @@ -21,22 +21,18 @@ describe('Sync Message Utils', () => { // Fill half with secondaries, half with primaries const numConversations = 20; - const primaryConversations = new Array(numConversations / 2) - .fill({}) - .map( - () => - new TestUtils.MockConversation({ - type: TestUtils.MockConversationType.Primary, - }) - ); - const secondaryConversations = new Array(numConversations / 2) - .fill({}) - .map( - () => - new TestUtils.MockConversation({ - type: TestUtils.MockConversationType.Secondary, - }) - ); + const primaryConversations = new Array(numConversations / 2).fill({}).map( + () => + new TestUtils.MockConversation({ + type: TestUtils.MockConversationType.Primary, + }) + ); + const secondaryConversations = new Array(numConversations / 2).fill({}).map( + () => + new TestUtils.MockConversation({ + type: TestUtils.MockConversationType.Secondary, + }) + ); const conversations = [...primaryConversations, ...secondaryConversations]; const sandbox = sinon.createSandbox();