From c338bdf6aefef39a3629f03bd93124cf80f70802 Mon Sep 17 00:00:00 2001 From: Richard Ramos Date: Mon, 31 Jan 2022 20:32:53 -0400 Subject: [PATCH] refactor(communities): delete categories --- .../modules/main/chat_section/controller.nim | 8 ++++ .../chat_section/controller_interface.nim | 4 +- src/app/modules/main/chat_section/module.nim | 17 +++++++++ .../module_controller_delegate_interface.nim | 3 ++ .../module_view_delegate_interface.nim | 3 ++ src/app/modules/main/chat_section/view.nim | 5 ++- .../popups/community/CreateCategoryPopup.qml | 4 +- ui/app/AppLayouts/Chat/stores/RootStore.qml | 3 +- .../Chat/views/CommunityColumnView.qml | 38 ++++++++++--------- 9 files changed, 61 insertions(+), 24 deletions(-) diff --git a/src/app/modules/main/chat_section/controller.nim b/src/app/modules/main/chat_section/controller.nim index c28b6bfed6..5c9dcc209b 100644 --- a/src/app/modules/main/chat_section/controller.nim +++ b/src/app/modules/main/chat_section/controller.nim @@ -125,6 +125,11 @@ method init*(self: Controller) = if (args.communityId == self.sectionId): self.delegate.onCommunityCategoryCreated(args.category, args.chats) + self.events.on(SIGNAL_COMMUNITY_CATEGORY_DELETED) do(e:Args): + let args = CommunityCategoryArgs(e) + if (args.communityId == self.sectionId): + self.delegate.onCommunityCategoryDeleted(args.category) + self.events.on(SIGNAL_COMMUNITY_CHANNEL_REORDERED) do(e:Args): let args = CommunityChatOrderArgs(e) if (args.communityId == self.sectionId): @@ -306,6 +311,9 @@ method editCommunityChannel*( method createCommunityCategory*(self: Controller, name: string, channels: seq[string]) = self.communityService.createCommunityCategory(self.sectionId, name, channels) +method deleteCommunityCategory*(self: Controller, categoryId: string) = + self.communityService.deleteCommunityCategory(self.sectionId, categoryId) + method leaveCommunity*(self: Controller) = self.communityService.leaveCommunity(self.sectionId) diff --git a/src/app/modules/main/chat_section/controller_interface.nim b/src/app/modules/main/chat_section/controller_interface.nim index 51faa4e06d..0e21f580a0 100644 --- a/src/app/modules/main/chat_section/controller_interface.nim +++ b/src/app/modules/main/chat_section/controller_interface.nim @@ -116,7 +116,6 @@ method joinGroup*(self: AccessInterface) {.base.} = method joinGroupChatFromInvitation*(self: AccessInterface, groupName: string, chatId: string, adminPK: string) {.base.} = raise newException(ValueError, "No implementation available") - method acceptRequestToJoinCommunity*(self: AccessInterface, requestId: string) {.base.} = raise newException(ValueError, "No implementation available") @@ -132,6 +131,9 @@ method editCommunityChannel*(self: AccessInterface, channelId: string, name: str method createCommunityCategory*(self: AccessInterface, name: string, channels: seq[string]) {.base.} = raise newException(ValueError, "No implementation available") +method deleteCommunityCategory*(self: AccessInterface, categoryId: string) {.base.} = + raise newException(ValueError, "No implementation available") + method leaveCommunity*(self: AccessInterface) {.base.} = raise newException(ValueError, "No implementation available") diff --git a/src/app/modules/main/chat_section/module.nim b/src/app/modules/main/chat_section/module.nim index 3e92c0f372..5c6e7e4641 100644 --- a/src/app/modules/main/chat_section/module.nim +++ b/src/app/modules/main/chat_section/module.nim @@ -441,6 +441,20 @@ method onCommunityCategoryCreated*(self: Module, cat: Category, chats: seq[ChatD categoryItem.prependSubItems(categoryChannels) self.view.chatsModel().appendItem(categoryItem) +method onCommunityCategoryDeleted*(self: Module, cat: Category) = + let chats = self.controller.getChats(self.controller.getMySectionId(), cat.id) + for c in chats: + let chatDto = self.controller.getChatDetails(self.controller.getMySectionId(), c.id) + let hasNotification = chatDto.unviewedMessagesCount > 0 or chatDto.unviewedMentionsCount > 0 + let notificationsCount = chatDto.unviewedMentionsCount + let amIChatAdmin = self.controller.getMyCommunity().admin + let channelItem = initItem(chatDto.id, chatDto.name, chatDto.identicon, false, chatDto.color, + chatDto.description, chatDto.chatType.int, amIChatAdmin, hasNotification, notificationsCount, + chatDto.muted, active = false, chatDto.position, "") + self.view.chatsModel().appendItem(channelItem) + + self.view.chatsModel().removeItemById(cat.id) + method onCommunityChannelDeletedOrChatLeft*(self: Module, chatId: string) = if(not self.chatContentModules.contains(chatId)): return @@ -599,6 +613,9 @@ method editCommunityChannel*(self: Module, channelId, name, description, categor method createCommunityCategory*(self: Module, name: string, channels: seq[string]) = self.controller.createCommunityCategory(name, channels) +method deleteCommunityCategory*(self: Module, categoryId: string) = + self.controller.deleteCommunityCategory(categoryId) + method leaveCommunity*(self: Module) = self.controller.leaveCommunity() diff --git a/src/app/modules/main/chat_section/private_interfaces/module_controller_delegate_interface.nim b/src/app/modules/main/chat_section/private_interfaces/module_controller_delegate_interface.nim index 908ba70502..ca4b0d7004 100644 --- a/src/app/modules/main/chat_section/private_interfaces/module_controller_delegate_interface.nim +++ b/src/app/modules/main/chat_section/private_interfaces/module_controller_delegate_interface.nim @@ -53,3 +53,6 @@ method reorderChannels*(self: AccessInterface, chatId, categoryId: string, posit method onCommunityCategoryCreated*(self: AccessInterface, category: Category, chats: seq[ChatDto]) {.base.} = raise newException(ValueError, "No implementation available") + +method onCommunityCategoryDeleted*(self: AccessInterface, category: Category) {.base.} = + raise newException(ValueError, "No implementation available") diff --git a/src/app/modules/main/chat_section/private_interfaces/module_view_delegate_interface.nim b/src/app/modules/main/chat_section/private_interfaces/module_view_delegate_interface.nim index 522299dc9b..08bec5a951 100644 --- a/src/app/modules/main/chat_section/private_interfaces/module_view_delegate_interface.nim +++ b/src/app/modules/main/chat_section/private_interfaces/module_view_delegate_interface.nim @@ -114,3 +114,6 @@ method inviteUsersToCommunity*(self: AccessInterface, pubKeysJSON: string): stri method createCommunityCategory*(self: AccessInterface, name: string, channels: seq[string]) {.base.} = raise newException(ValueError, "No implementation available") + +method deleteCommunityCategory*(self: AccessInterface, categoryId: string) {.base.} = + raise newException(ValueError, "No implementation available") diff --git a/src/app/modules/main/chat_section/view.nim b/src/app/modules/main/chat_section/view.nim index 5316f84a16..57dbe3c181 100644 --- a/src/app/modules/main/chat_section/view.nim +++ b/src/app/modules/main/chat_section/view.nim @@ -223,4 +223,7 @@ QtObject: proc createCommunityCategory*(self: View, name: string, channels: string) {.slot.} = let channelsSeq = map(parseJson(channels).getElems(), proc(x:JsonNode):string = x.getStr()) - self.delegate.createCommunityCategory(name, channelsSeq) \ No newline at end of file + self.delegate.createCommunityCategory(name, channelsSeq) + + proc deleteCommunityCategory*(self: View, categoryId: string) {.slot.} = + self.delegate.deleteCommunityCategory(categoryId) diff --git a/ui/app/AppLayouts/Chat/popups/community/CreateCategoryPopup.qml b/ui/app/AppLayouts/Chat/popups/community/CreateCategoryPopup.qml index 92a4251e26..8470ffeb15 100644 --- a/ui/app/AppLayouts/Chat/popups/community/CreateCategoryPopup.qml +++ b/ui/app/AppLayouts/Chat/popups/community/CreateCategoryPopup.qml @@ -194,8 +194,8 @@ StatusModal { onConfirmButtonClicked: function(){ const error = root.store.deleteCommunityCategory(root.categoryId); if (error) { - creatingError.text = error - return creatingError.open() + categoryError.text = error + return categoryError.open() } close(); root.close() diff --git a/ui/app/AppLayouts/Chat/stores/RootStore.qml b/ui/app/AppLayouts/Chat/stores/RootStore.qml index ba4b657361..bdf771042f 100644 --- a/ui/app/AppLayouts/Chat/stores/RootStore.qml +++ b/ui/app/AppLayouts/Chat/stores/RootStore.qml @@ -159,8 +159,7 @@ QtObject { } function deleteCommunityCategory(categoryId) { - // Not Refactored Yet -// chatsModelInst.communities.deleteCommunityCategory(chatsModelInst.communities.activeCommunity.id, categoryId); + chatCommunitySectionModule.deleteCommunityCategory(categoryId); } function leaveCommunity() { diff --git a/ui/app/AppLayouts/Chat/views/CommunityColumnView.qml b/ui/app/AppLayouts/Chat/views/CommunityColumnView.qml index 93e9aa0bc4..fbaf838119 100644 --- a/ui/app/AppLayouts/Chat/views/CommunityColumnView.qml +++ b/ui/app/AppLayouts/Chat/views/CommunityColumnView.qml @@ -209,24 +209,27 @@ Item { property var categoryItem openHandler: function (id) { - // Not Refactored Yet -// categoryItem = root.store.chatsModelInst.communities.activeCommunity.getCommunityCategoryItemById(id) + let jsonObj = root.communitySectionModule.getItemAsJson(id) + let obj = JSON.parse(jsonObj) + if (obj.error) { + console.error("error parsing chat item json object, id: ", id, " error: ", obj.error) + close() + return + } + categoryItem = obj } StatusMenuItem { - // Not Refactored Yet enabled: communityData.amISectionAdmin //% "Edit Category" text: qsTrId("edit-category") icon.name: "edit" onTriggered: { - // Not Refactored Yet -// Global.openPopup(createCategoryPopup, { -// communityId: root.store.chatsModelInst.communities.activeCommunity.id, -// isEdit: true, -// categoryId: categoryItem.id, -// categoryName: categoryItem.name -// }) + Global.openPopup(createCategoryPopup, { + isEdit: true, + categoryId: categoryItem.categoryId, + categoryName: categoryItem.name + }) } } @@ -247,7 +250,7 @@ Item { //% "Are you sure you want to delete %1 category? Channels inside the category won’t be deleted." confirmationText: qsTrId("are-you-sure-you-want-to-delete--1-category--channels-inside-the-category-won-t-be-deleted-") .arg(categoryItem.name), - categoryId: categoryItem.id + categoryId: categoryItem.categoryId }) } } @@ -431,13 +434,12 @@ Item { close(); } onConfirmButtonClicked: function(){ - // Not Refactored Yet -// const error = root.store.chatsModelInst.communities.deleteCommunityCategory(root.store.chatsModelInst.communities.activeCommunity.id, categoryId) -// if (error) { -// creatingError.text = error -// return creatingError.open() -// } -// close(); + const error = root.store.deleteCommunityCategory(categoryId); + if (error) { + deleteError.text = error + return deleteError.open() + } + close(); } } }