From c58a656a5270fb58265a4bed74f4854edf851e22 Mon Sep 17 00:00:00 2001 From: Jonathan Rainville Date: Tue, 12 Apr 2022 14:54:01 -0400 Subject: [PATCH] fix(group-chats): fix context menu and pinned messages popup --- .../modules/main/chat_section/controller.nim | 5 ++- .../main/chat_section/io_interface.nim | 2 +- src/app/modules/main/chat_section/module.nim | 4 +- src/app/modules/main/chat_section/view.nim | 4 +- .../AppLayouts/Chat/popups/GroupInfoPopup.qml | 36 ++++++++-------- .../AppLayouts/Chat/views/ChatContentView.qml | 6 +++ .../Chat/views/ChatContextMenuView.qml | 41 ++++++++++++------- ui/app/AppLayouts/Chat/views/ChatView.qml | 3 -- .../Chat/views/ContactsColumnView.qml | 6 +++ 9 files changed, 62 insertions(+), 45 deletions(-) diff --git a/src/app/modules/main/chat_section/controller.nim b/src/app/modules/main/chat_section/controller.nim index 5d58cc3fc1..73515a2848 100644 --- a/src/app/modules/main/chat_section/controller.nim +++ b/src/app/modules/main/chat_section/controller.nim @@ -298,8 +298,9 @@ proc addGroupMembers*(self: Controller, chatId: string, pubKeys: seq[string]) = proc removeMemberFromGroupChat*(self: Controller, communityID: string, chatId: string, pubKey: string) = self.chatService.removeMemberFromGroupChat(communityID, chatId, pubKey) -proc renameGroupChat*(self: Controller, communityID: string, chatId: string, newName: string) = - self.chatService.renameGroupChat(communityID, chatId, newName) +proc renameGroupChat*(self: Controller, chatId: string, newName: string) = + let communityId = if self.isCommunitySection: self.sectionId else: "" + self.chatService.renameGroupChat(communityId, chatId, newName) proc makeAdmin*(self: Controller, communityID: string, chatId: string, pubKey: string) = self.chatService.makeAdmin(communityID, chatId, pubKey) diff --git a/src/app/modules/main/chat_section/io_interface.nim b/src/app/modules/main/chat_section/io_interface.nim index eed317a335..4ae3f15a50 100644 --- a/src/app/modules/main/chat_section/io_interface.nim +++ b/src/app/modules/main/chat_section/io_interface.nim @@ -200,7 +200,7 @@ method addGroupMembers*(self: AccessInterface, chatId: string, pubKeys: string) method removeMemberFromGroupChat*(self: AccessInterface, communityID: string, chatId: string, pubKey: string) {.base.} = raise newException(ValueError, "No implementation available") -method renameGroupChat*(self: AccessInterface, communityID: string, chatId: string, newName: string) {.base.} = +method renameGroupChat*(self: AccessInterface, chatId: string, newName: string) {.base.} = raise newException(ValueError, "No implementation available") method makeAdmin*(self: AccessInterface, communityID: string, chatId: string, pubKey: string) {.base.} = diff --git a/src/app/modules/main/chat_section/module.nim b/src/app/modules/main/chat_section/module.nim index e4c0ab582a..ba0e4ceee9 100644 --- a/src/app/modules/main/chat_section/module.nim +++ b/src/app/modules/main/chat_section/module.nim @@ -679,8 +679,8 @@ method addGroupMembers*(self: Module, chatId: string, pubKeys: string) = method removeMemberFromGroupChat*(self: Module, communityID: string, chatId: string, pubKey: string) = self.controller.removeMemberFromGroupChat(communityID, chatId, pubKey) -method renameGroupChat*(self: Module, communityID: string, chatId: string, newName: string) = - self.controller.renameGroupChat(communityID, chatId, newName) +method renameGroupChat*(self: Module, chatId: string, newName: string) = + self.controller.renameGroupChat(chatId, newName) method makeAdmin*(self: Module, communityID: string, chatId: string, pubKey: string) = self.controller.makeAdmin(communityID, chatId, pubKey) diff --git a/src/app/modules/main/chat_section/view.nim b/src/app/modules/main/chat_section/view.nim index a11d181ed9..cc7138f7ce 100644 --- a/src/app/modules/main/chat_section/view.nim +++ b/src/app/modules/main/chat_section/view.nim @@ -187,8 +187,8 @@ QtObject: proc removeMemberFromGroupChat*(self: View, communityID: string, chatId: string, pubKey: string) {.slot.} = self.delegate.removeMemberFromGroupChat(communityID, chatId, pubKey) - proc renameGroupChat*(self: View, communityID: string, chatId: string, newName: string) {.slot.} = - self.delegate.renameGroupChat(communityID, chatId, newName) + proc renameGroupChat*(self: View, chatId: string, newName: string) {.slot.} = + self.delegate.renameGroupChat(chatId, newName) proc makeAdmin*(self: View, communityID: string, chatId: string, pubKey: string) {.slot.} = self.delegate.makeAdmin(communityID, chatId, pubKey) diff --git a/ui/app/AppLayouts/Chat/popups/GroupInfoPopup.qml b/ui/app/AppLayouts/Chat/popups/GroupInfoPopup.qml index ab5c1ef9a6..c980fcafc7 100644 --- a/ui/app/AppLayouts/Chat/popups/GroupInfoPopup.qml +++ b/ui/app/AppLayouts/Chat/popups/GroupInfoPopup.qml @@ -25,6 +25,7 @@ StatusModal { } property var chatSectionModule property var store + property var messageStore property bool addMembers: false property int currMemberCount: chatContentModule.usersModule.model.count property int memberCount: 1 @@ -170,16 +171,28 @@ StatusModal { spacing: Style.current.padding StatusSettingsLineButton { - // Not Refactored Yet - property int pinnedCount: 0 // popup.store.chatsModelInst.messageView.pinnedMessagesList.count + property int pinnedCount: popup.chatContentModule.pinnedMessagesModel.count id: pinnedMessagesBtn visible: pinnedCount > 0 //% "Pinned messages" text: qsTrId("pinned-messages") currentValue: pinnedCount - onClicked: Global.openPopup(pinnedMessagesPopupComponent, {store: popup.store}) + onClicked: { + popup.store.messageStore.messageModule = popup.chatContentModule.messagesModule + popup.store.messageStore.chatSectionModule = popup.chatSectionModule + + Global.openPopup(pinnedMessagesPopupComponent, { + store: popup.store, + messageStore: popup.store.messageStore, + pinnedMessagesModel: popup.chatContentModule.pinnedMessagesModel, + messageToPin: "" + }) + } iconSource: Style.svg("pin") + anchors.left: undefined + anchors.right: undefined + width: parent.width } Separator { @@ -187,23 +200,6 @@ StatusModal { visible: pinnedMessagesBtn.visible } - // Not Refactored Yet -// Connections { -// target: popup.store.chatsModelInst.channelView -// onActiveChannelChanged: { -// if (popup.channelType === GroupInfoPopup.ChannelType.ActiveChannel) { -// popup.channel = popup.store.chatsModelInst.channelView.activeChannel -// resetSelectedMembers() -// } -// } -// onContextChannelChanged: { -// if (popup.channelType === GroupInfoPopup.ChannelType.ContextChannel) { -// popup.channel = popup.store.chatsModelInst.channelView.contextChannel -// resetSelectedMembers() -// } -// } -// } - ListView { id: memberList Layout.fillWidth: true diff --git a/ui/app/AppLayouts/Chat/views/ChatContentView.qml b/ui/app/AppLayouts/Chat/views/ChatContentView.qml index 968fc925a2..794a5c3cf2 100644 --- a/ui/app/AppLayouts/Chat/views/ChatContentView.qml +++ b/ui/app/AppLayouts/Chat/views/ChatContentView.qml @@ -271,6 +271,12 @@ ColumnLayout { onLeaveGroup: { chatContentModule.leaveChat(); } + onRenameGroupChat: { + root.rootStore.chatCommunitySectionModule.renameGroupChat( + chatId, + groupName + ) + } } } diff --git a/ui/app/AppLayouts/Chat/views/ChatContextMenuView.qml b/ui/app/AppLayouts/Chat/views/ChatContextMenuView.qml index 100f8da583..3c7dcc93b6 100644 --- a/ui/app/AppLayouts/Chat/views/ChatContextMenuView.qml +++ b/ui/app/AppLayouts/Chat/views/ChatContextMenuView.qml @@ -39,6 +39,7 @@ StatusPopupMenu { signal deleteCommunityChat(string chatId) signal leaveChat(string chatId) signal leaveGroup(string chatId) + signal renameGroupChat(string chatId, string groupName) signal createCommunityChannel(string chatId, string newName, string newDescription, string newEmoji, string newColor) signal editCommunityChannel(string chatId, string newName, string newDescription, string newEmoji, string newColor, string newCategory) @@ -71,15 +72,18 @@ StatusPopupMenu { } } - StatusMenuItem { - text: qsTr("Add / remove from group") - icon.name: "notification" - enabled: (root.chatType === Constants.chatType.privateGroupChat && - amIChatAdmin) - onTriggered: { - root.addRemoveGroupMember(); - } - } + // TODO needs to be implemented + // This should open up the ad-hoc group chat creation view + // Design https://www.figma.com/file/17fc13UBFvInrLgNUKJJg5/Kuba%E2%8E%9CDesktop?node-id=417%3A243810 + // StatusMenuItem { + // text: qsTr("Add / remove from group") + // icon.name: "notification" + // enabled: (root.chatType === Constants.chatType.privateGroupChat && + // amIChatAdmin) + // onTriggered: { + // root.addRemoveGroupMember(); + // } + // } StatusMenuSeparator { visible: viewProfileMenuItem.enabled @@ -99,20 +103,27 @@ StatusPopupMenu { } StatusMenuItem { - text: qsTr("Edit name and image") + text: qsTr("Edit name") icon.name: "edit" enabled: root.chatType === Constants.chatType.privateGroupChat && root.amIChatAdmin onTriggered: { - Global.openPopup(editChannelPopup, { - isEdit: true, - channelName: root.chatName, - channelDescription: root.chatDescription, - categoryId: root.chatCategoryId + Global.openPopup(renameGroupPopupComponent, { + activeChannelName: root.chatName, }); } } + Component { + id: renameGroupPopupComponent + RenameGroupPopup { + onDoRename: { + root.renameGroupChat(root.chatId, groupName) + close() + } + } + } + StatusMenuItem { text: root.chatMuted ? //% "Unmute chat" diff --git a/ui/app/AppLayouts/Chat/views/ChatView.qml b/ui/app/AppLayouts/Chat/views/ChatView.qml index ab33c91e84..85082d3bca 100644 --- a/ui/app/AppLayouts/Chat/views/ChatView.qml +++ b/ui/app/AppLayouts/Chat/views/ChatView.qml @@ -26,9 +26,6 @@ StatusAppThreePanelLayout { property var contactsStore property bool hasAddedContacts: root.contactsStore.myContactsModel.count > 0 - // Not Refactored - property var messageStore - property RootStore rootStore property Component pinnedMessagesListPopupComponent diff --git a/ui/app/AppLayouts/Chat/views/ContactsColumnView.qml b/ui/app/AppLayouts/Chat/views/ContactsColumnView.qml index e6abb2c3f9..92dbc428d5 100644 --- a/ui/app/AppLayouts/Chat/views/ContactsColumnView.qml +++ b/ui/app/AppLayouts/Chat/views/ContactsColumnView.qml @@ -250,6 +250,12 @@ Item { chatDetails: chatContentModule.chatDetails }) } + onRenameGroupChat: { + chatSectionModule.renameGroupChat( + chatId, + groupName + ) + } } }