From 3fd10e79159ff6066329081505fc5faf2f74552a Mon Sep 17 00:00:00 2001 From: Richard Ramos Date: Tue, 25 Jan 2022 10:51:38 -0400 Subject: [PATCH] fix: community chat positions --- .../modules/main/chat_section/controller.nim | 8 ++++- .../chat_section/controller_interface.nim | 8 ++++- src/app/modules/main/chat_section/module.nim | 8 ++++- .../module_view_delegate_interface.nim | 6 ++++ src/app/modules/main/chat_section/view.nim | 8 ++++- .../modules/main/communities/controller.nim | 4 +++ src/app_service/service/community/service.nim | 31 +++++++++++++++++++ ui/app/AppLayouts/Chat/stores/RootStore.qml | 8 +++++ .../Chat/views/CommunityColumnView.qml | 8 ++--- 9 files changed, 79 insertions(+), 10 deletions(-) diff --git a/src/app/modules/main/chat_section/controller.nim b/src/app/modules/main/chat_section/controller.nim index 6e2554936..9074ab1a7 100644 --- a/src/app/modules/main/chat_section/controller.nim +++ b/src/app/modules/main/chat_section/controller.nim @@ -351,4 +351,10 @@ method setCommunityMuted*(self: Controller, muted: bool) = self.communityService.setCommunityMuted(self.sectionId, muted) method inviteUsersToCommunity*(self: Controller, pubKeys: string): string = - result = self.communityService.inviteUsersToCommunityById(self.sectionId, pubKeys) \ No newline at end of file + result = self.communityService.inviteUsersToCommunityById(self.sectionId, pubKeys) + +method reorderCommunityCategories*(self: Controller, categoryId: string, position: int) = + self.communityService.reorderCommunityCategories(self.sectionId, categoryId, position) + +method reorderCommunityChat*(self: Controller, categoryId: string, chatId: string, position: int): string = + self.communityService.reorderCommunityChat(self.sectionId, categoryId, chatId, position) diff --git a/src/app/modules/main/chat_section/controller_interface.nim b/src/app/modules/main/chat_section/controller_interface.nim index d859d4d9f..5b09cd5b7 100644 --- a/src/app/modules/main/chat_section/controller_interface.nim +++ b/src/app/modules/main/chat_section/controller_interface.nim @@ -150,4 +150,10 @@ method setCommunityMuted*(self: AccessInterface, muted: bool) {.base.} = raise newException(ValueError, "No implementation available") method inviteUsersToCommunity*(self: AccessInterface, pubKeys: string): string {.base.} = - raise newException(ValueError, "No implementation available") \ No newline at end of file + raise newException(ValueError, "No implementation available") + +method reorderCommunityCategories*(self: AccessInterface, categoryId: string, position: int) = + raise newException(ValueError, "No implementation available") + +method reorderCommunityChat*(self: AccessInterface, categoryId: string, chatId: string, position: int): string = + 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 39e044330..1fc569258 100644 --- a/src/app/modules/main/chat_section/module.nim +++ b/src/app/modules/main/chat_section/module.nim @@ -676,4 +676,10 @@ method prepareEditCategoryModel*(self: Module, categoryId: string) = let c = self.controller.getChatDetails(communityId, chat.id) let item = initItem(c.id, c.name, "", false, c.color, c.description, c.chatType.int, false, false, 0, c.muted, false, active = false, c.position, categoryId) - self.view.editCategoryChannelsModel().appendItem(item) \ No newline at end of file + self.view.editCategoryChannelsModel().appendItem(item) + +method reorderCommunityCategories*(self: Module, categoryId: string, position: int) = + self.controller.reorderCommunityCategories(categoryId, position) + +method reorderCommunityChat*(self: Module, categoryId: string, chatId: string, position: int): string = + self.controller.reorderCommunityChat(categoryId, chatId, position) 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 62be8bf8e..a8a73af4f 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 @@ -123,3 +123,9 @@ method deleteCommunityCategory*(self: AccessInterface, categoryId: string) {.bas method prepareEditCategoryModel*(self: AccessInterface, categoryId: string) {.base.} = raise newException(ValueError, "No implementation available") + +method reorderCommunityCategories*(self: AccessInterface, categoryId: string, position: int) = + raise newException(ValueError, "No implementation available") + +method reorderCommunityChat*(self: AccessInterface, categoryId: string, chatId: string, position: int): string = + 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 4312a4624..648cd24a1 100644 --- a/src/app/modules/main/chat_section/view.nim +++ b/src/app/modules/main/chat_section/view.nim @@ -249,4 +249,10 @@ QtObject: self.delegate.deleteCommunityCategory(categoryId) proc prepareEditCategoryModel*(self: View, categoryId: string) {.slot.} = - self.delegate.prepareEditCategoryModel(categoryId) \ No newline at end of file + self.delegate.prepareEditCategoryModel(categoryId) + + proc reorderCommunityCategories*(self: View, categoryId: string, position: int) {.slot} = + self.delegate.reorderCommunityCategories(categoryId, position) + + proc reorderCommunityChat*(self: View, categoryId: string, chatId: string, position: int): string {.slot} = + self.delegate.reorderCommunityChat(categoryId, chatId, position) diff --git a/src/app/modules/main/communities/controller.nim b/src/app/modules/main/communities/controller.nim index 8248d7086..a90941f81 100644 --- a/src/app/modules/main/communities/controller.nim +++ b/src/app/modules/main/communities/controller.nim @@ -51,6 +51,10 @@ method init*(self: Controller) = method getAllCommunities*(self: Controller): seq[CommunityDto] = result = self.communityService.getAllCommunities() + self.events.on(SIGNAL_COMMUNITY_CATEGORY_REORDERED) do(e:Args): + let args = CommunityCategoryOrderArgs(e) + # self.delegate.communityCategoryReordered() + method joinCommunity*(self: Controller, communityId: string): string = self.communityService.joinCommunity(communityId) diff --git a/src/app_service/service/community/service.nim b/src/app_service/service/community/service.nim index 28759c184..c14c348e0 100644 --- a/src/app_service/service/community/service.nim +++ b/src/app_service/service/community/service.nim @@ -43,6 +43,11 @@ type categoryId*: string position*: int + CommunityCategoryOrderArgs* = ref object of Args + communityId*: string + categoryId*: string + position*: int + CommunityCategoryArgs* = ref object of Args communityId*: string category*: Category @@ -67,6 +72,7 @@ const SIGNAL_COMMUNITY_CHANNEL_DELETED* = "communityChannelDeleted" const SIGNAL_COMMUNITY_CATEGORY_CREATED* = "communityCategoryCreated" const SIGNAL_COMMUNITY_CATEGORY_EDITED* = "communityCategoryEdited" const SIGNAL_COMMUNITY_CATEGORY_DELETED* = "communityCategoryDeleted" +const SIGNAL_COMMUNITY_CATEGORY_REORDERED* = "communityCategoryReordered" const SIGNAL_COMMUNITY_MEMBER_APPROVED* = "communityMemberApproved" QtObject: @@ -639,6 +645,31 @@ QtObject: except Exception as e: error "Error deleting community category", msg = e.msg, communityId, categoryId + proc reorderCommunityCategories*( + self: Service, + communityId: string, + categoryId: string, + position: int) = + try: + let response = status_go.reorderCommunityCategories( + communityId, + categoryId, + position) + + if response.error != nil: + let error = Json.decode($response.error, RpcError) + raise newException(RpcException, "Error reordering community category: " & error.message) + + self.events.emit(SIGNAL_COMMUNITY_CATEGORY_REORDERED, + CommunityCategoryOrderArgs( + communityId: communityId, + categoryId: categoryId, + position: position + ) + ) + except Exception as e: + error "Error reordering category channel", msg = e.msg, communityId, categoryId, position + proc requestCommunityInfo*(self: Service, communityId: string) = try: let response = status_go.requestCommunityInfo(communityId) diff --git a/ui/app/AppLayouts/Chat/stores/RootStore.qml b/ui/app/AppLayouts/Chat/stores/RootStore.qml index 0d358d818..050f4fda8 100644 --- a/ui/app/AppLayouts/Chat/stores/RootStore.qml +++ b/ui/app/AppLayouts/Chat/stores/RootStore.qml @@ -210,4 +210,12 @@ QtObject { function removeCommunityChat(chatId) { chatCommunitySectionModule.removeCommunityChat(chatId) } + + function reorderCommunityCategories(categoryId, to){ + chatCommunitySectionModule.reorderCommunityCategories(categoryId, to) + } + + function reorderCommunityChat(categoryId, chatId, to){ + chatCommunitySectionModule.reorderCommunityChat(categoryId, chatId, to) + } } diff --git a/ui/app/AppLayouts/Chat/views/CommunityColumnView.qml b/ui/app/AppLayouts/Chat/views/CommunityColumnView.qml index 308490dab..dbe833b4a 100644 --- a/ui/app/AppLayouts/Chat/views/CommunityColumnView.qml +++ b/ui/app/AppLayouts/Chat/views/CommunityColumnView.qml @@ -160,12 +160,8 @@ Item { // onChatItemSelected: root.store.chatsModelInst.channelView.setActiveChannel(id) // onChatItemUnmuted: root.store.chatsModelInst.channelView.unmuteChatItem(id) -// onChatItemReordered: function (categoryId, id, from, to) { -// root.store.chatsModelInst.communities.reorderCommunityChannel(chatsModel.communities.activeCommunity.id, categoryId, id, to); -// } -// onChatListCategoryReordered: function (categoryId, from, to) { -// root.store.chatsModelInst.communities.reorderCommunityCategories(chatsModel.communities.activeCommunity.id, categoryId, to); -// } + onChatItemReordered: root.store.reorderCommunityChat(categoryId, id, to) + onChatListCategoryReordered: root.store.reorderCommunityCategories(categoryId, to) onCategoryAddButtonClicked: Global.openPopup(createChannelPopup, { categoryId: id