diff --git a/src/app/modules/main/chat_section/controller.nim b/src/app/modules/main/chat_section/controller.nim index 5d702eed0e..772fe9b25e 100644 --- a/src/app/modules/main/chat_section/controller.nim +++ b/src/app/modules/main/chat_section/controller.nim @@ -113,6 +113,15 @@ method init*(self: Controller) = self.chatService.updateOrAddChat(args.chat) self.delegate.onCommunityChannelEdited(args.chat) + self.events.on(SIGNAL_COMMUNITY_CATEGORY_CREATED) do(e:Args): + let args = CommunityCategoryArgs(e) + if (args.communityId == self.sectionId): + var chats:seq[ChatDto] = @[] + for chat in args.chats: + self.chatService.updateOrAddChat(chat) + chats.add(chat) + self.delegate.onCommunityCategoryCreated(args.category, chats) + self.events.on(SIGNAL_COMMUNITY_CHANNEL_REORDERED) do(e:Args): let args = CommunityChatOrderArgs(e) if (args.communityId == self.sectionId): diff --git a/src/app/modules/main/chat_section/module.nim b/src/app/modules/main/chat_section/module.nim index 460f4c4543..6ad474bf8e 100644 --- a/src/app/modules/main/chat_section/module.nim +++ b/src/app/modules/main/chat_section/module.nim @@ -382,6 +382,22 @@ method removeCommunityChat*(self: Module, chatId: string) = self.controller.removeCommunityChat(chatId) +method onCommunityCategoryCreated*(self: Module, cat: Category, chats: seq[ChatDto]) = + var categoryItem = initItem(cat.id, cat.name, "", false, "", "", ChatType.Category.int, false, + false, 0, false, false, cat.position) + var categoryChannels: seq[SubItem] + for chatDto in chats: + let hasNotification = chatDto.unviewedMessagesCount > 0 or chatDto.unviewedMentionsCount > 0 + let notificationsCount = chatDto.unviewedMentionsCount + let channelItem = initSubItem(chatDto.id, cat.id, chatDto.name, chatDto.identicon, false, chatDto.color, + chatDto.description, chatDto.chatType.int, true, hasNotification, notificationsCount, chatDto.muted, + false, chatDto.position) + self.view.chatsModel().removeItemById(chatDto.id) + categoryChannels.add(channelItem) + + categoryItem.prependSubItems(categoryChannels) + self.view.chatsModel().appendItem(categoryItem) + method onCommunityChannelDeletedOrChatLeft*(self: Module, chatId: string) = if(not self.chatContentModules.contains(chatId)): return @@ -541,11 +557,8 @@ method declineRequestToJoinCommunity*(self: Module, requestId: string) = method createCommunityChannel*(self: Module, name, description: string,) = self.controller.createCommunityChannel(name, description) -proc createChannelsSeq(self: Module, channels: string): seq[string] = - return map(parseJson(channels).getElems(), proc(x:JsonNode):string = x.getStr()) - -method createCommunityCategory*(self: Module, name: string, channels: string) = - self.controller.createCommunityCategory(name, self.createChannelsSeq(channels)) +method createCommunityCategory*(self: Module, name: string, channels: seq[string]) = + self.controller.createCommunityCategory(name, channels) 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 d1e6622237..1bc37007e6 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 @@ -46,3 +46,6 @@ method onCommunityChannelEdited*(self: AccessInterface, chat: ChatDto) {.base.} method reorderChannels*(self: AccessInterface, chatId, categoryId: string, position: int) {.base.} = raise newException(ValueError, "No implementation available") + +method onCommunityCategoryCreated*(self: AccessInterface, category: Category, chats: seq[ChatDto]) {.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 48c3d67c2d..db8ed25e44 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 @@ -109,5 +109,5 @@ method setCommunityMuted*(self: AccessInterface, muted: bool) {.base.} = method inviteUsersToCommunity*(self: AccessInterface, pubKeysJSON: string): string {.base.} = raise newException(ValueError, "No implementation available") -method createCommunityCategory*(self: AccessInterface, name: string, channels: string) {.base.} = +method createCommunityCategory*(self: AccessInterface, name: string, channels: seq[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 9f8379704f..6ec8910c07 100644 --- a/src/app/modules/main/chat_section/view.nim +++ b/src/app/modules/main/chat_section/view.nim @@ -1,4 +1,4 @@ -import NimQml, json +import NimQml, json, sequtils import model as chats_model import item, sub_item, active_item import ../../shared_models/contacts_model as contacts_model @@ -207,4 +207,5 @@ QtObject: result = self.delegate.inviteUsersToCommunity(pubKeysJSON) proc createCommunityCategory*(self: View, name: string, channels: string) {.slot.} = - self.delegate.createCommunityCategory(name, channels) \ No newline at end of file + let channelsSeq = map(parseJson(channels).getElems(), proc(x:JsonNode):string = x.getStr()) + self.delegate.createCommunityCategory(name, channelsSeq) \ No newline at end of file diff --git a/src/app/modules/main/communities/controller.nim b/src/app/modules/main/communities/controller.nim index ee2f9d02ea..f08cdeebc3 100644 --- a/src/app/modules/main/communities/controller.nim +++ b/src/app/modules/main/communities/controller.nim @@ -125,21 +125,6 @@ method deleteCommunityChat*( chatId: string) = self.communityService.deleteCommunityChat(communityId, chatId) -method createCommunityCategory*( - self: Controller, - communityId: string, - name: string, - channels: seq[string]) = - self.communityService.createCommunityCategory(communityId, name, channels) - -method editCommunityCategory*( - self: Controller, - communityId: string, - categoryId: string, - name: string, - channels: seq[string]) = - self.communityService.editCommunityCategory(communityId, categoryId, name, channels) - method deleteCommunityCategory*( self: Controller, communityId: string, diff --git a/src/app/modules/main/communities/controller_interface.nim b/src/app/modules/main/communities/controller_interface.nim index bf72401b31..eec89429ab 100644 --- a/src/app/modules/main/communities/controller_interface.nim +++ b/src/app/modules/main/communities/controller_interface.nim @@ -31,12 +31,6 @@ method reorderCommunityChat*(self: AccessInterface, communityId: string, categor method deleteCommunityChat*(self: AccessInterface, communityId: string, chatId: string) {.base.} = raise newException(ValueError, "No implementation available") -method createCommunityCategory*(self: AccessInterface, communityId: string, name: string, channels: seq[string]) {.base.} = - raise newException(ValueError, "No implementation available") - -method editCommunityCategory*(self: AccessInterface, communityId: string, categoryId: string, name: string, channels: seq[string]) {.base.} = - raise newException(ValueError, "No implementation available") - method deleteCommunityCategory*(self: AccessInterface, communityId: string, categoryId: string) {.base.} = raise newException(ValueError, "No implementation available") diff --git a/src/app/modules/main/communities/module.nim b/src/app/modules/main/communities/module.nim index 3ba261610d..e8e1fcb0b3 100644 --- a/src/app/modules/main/communities/module.nim +++ b/src/app/modules/main/communities/module.nim @@ -139,14 +139,6 @@ method createCommunity*(self: Module, name: string, description: string, aX: int, aY: int, bX: int, bY: int) = self.controller.createCommunity(name, description, access, ensOnly, color, imagePath, aX, aY, bX, bY) -method createCommunityCategory*(self: Module, communityId: string, name: string, channels: string) = - let channelsSeq = map(parseJson(channels).getElems(), proc(x:JsonNode):string = x.getStr()) - self.controller.createCommunityCategory(communityId, name, channelsSeq) - -method editCommunityCategory*(self: Module, communityId: string, categoryId: string, name: string, channels: string) = - let channelsSeq = map(parseJson(channels).getElems(), proc(x:JsonNode):string = x.getStr()) - self.controller.editCommunityCategory(communityId, categoryid, name, channelsSeq) - method deleteCommunityCategory*(self: Module, communityId: string, categoryId: string) = self.controller.deleteCommunityCategory(communityId, categoryId) diff --git a/src/app/modules/main/communities/private_interfaces/module_access_interface.nim b/src/app/modules/main/communities/private_interfaces/module_access_interface.nim index c66a734ad8..2ab4c5af88 100644 --- a/src/app/modules/main/communities/private_interfaces/module_access_interface.nim +++ b/src/app/modules/main/communities/private_interfaces/module_access_interface.nim @@ -25,12 +25,6 @@ method joinCommunity*(self: AccessInterface, communityId: string): string {.base method createCommunity*(self: AccessInterface, name: string, description: string, access: int, ensOnly: bool, color: string, imagePath: string, aX: int, aY: int, bX: int, bY: int) {.base.} = raise newException(ValueError, "No implementation available") -method createCommunityCategory*(self: AccessInterface, communityId: string, name: string, channels: string) {.base.} = - raise newException(ValueError, "No implementation available") - -method editCommunityCategory*(self: AccessInterface, communityId: string, categoryId: string, name: string, channels: string) {.base.} = - raise newException(ValueError, "No implementation available") - method deleteCommunityCategory*(self: AccessInterface, communityId: string, categoryId: string) {.base.} = raise newException(ValueError, "No implementation available") diff --git a/src/app/modules/main/communities/view.nim b/src/app/modules/main/communities/view.nim index 8b0dcab873..ee72cf3832 100644 --- a/src/app/modules/main/communities/view.nim +++ b/src/app/modules/main/communities/view.nim @@ -67,12 +67,6 @@ QtObject: aX: int, aY: int, bX: int, bY: int) {.slot.} = self.delegate.createCommunity(name, description, access, ensOnly, color, imagePath, aX, aY, bX, bY) - proc createCommunityCategory*(self: View, communityId: string, name: string, channels: string) {.slot.} = - self.delegate.createCommunityCategory(communityId, name, channels) - - proc editCommunityCategory*(self: View, communityId: string, categoryId: string, name: string, channels: string) {.slot.} = - self.delegate.editCommunityCategory(communityId, categoryId, name, channels) - proc deleteCommunityCategory*(self: View, communityId: string, categoryId: string): string {.slot.} = self.delegate.deleteCommunityCategory(communityId, categoryId) diff --git a/src/app_service/service/community/service.nim b/src/app_service/service/community/service.nim index c812dc711e..9cc6893f5a 100644 --- a/src/app_service/service/community/service.nim +++ b/src/app_service/service/community/service.nim @@ -1,4 +1,4 @@ -import NimQml, Tables, json, sequtils, std/algorithm, strformat, chronicles, json_serialization +import NimQml, Tables, json, sequtils, std/algorithm, strformat, strutils, chronicles, json_serialization import ./dto/community as community_dto @@ -43,7 +43,7 @@ type CommunityCategoryArgs* = ref object of Args communityId*: string category*: Category - channels*: seq[string] + chats*: seq[ChatDto] CommunityMemberArgs* = ref object of Args communityId*: string @@ -132,10 +132,12 @@ QtObject: return chat proc findIndexById(id: string, chats: seq[Chat]): int = + var idx = -1 for chat in chats: + inc idx if(chat.id == id): - return 0 - return -1 + return idx + return idx proc handleCommunityUpdates(self: Service, communities: seq[CommunityDto], updatedChats: seq[ChatDto]) = let community = communities[0] @@ -541,10 +543,20 @@ QtObject: raise newException(RpcException, "Error creating community category: " & error.message) if response.result != nil and response.result.kind != JNull: + var chats: seq[ChatDto] = @[] + for chatId, v in response.result["communityChanges"].getElems()[0]["chatsModified"].pairs(): + let idx = findIndexById(chatId, self.joinedCommunities[communityId].chats) + if idx > -1: + self.joinedCommunities[communityId].chats[idx].categoryId = v["CategoryModified"].getStr() + self.joinedCommunities[communityId].chats[idx].position = v["PositionModified"].getInt() + var c = mapChatToChatDto(self.joinedCommunities[communityId].chats[idx], communityId) + c.id = communityId & c.id + if c.categoryId != "": + chats.add(c) for k, v in response.result["communityChanges"].getElems()[0]["categoriesAdded"].pairs(): let category = v.toCategory() self.events.emit(SIGNAL_COMMUNITY_CATEGORY_CREATED, - CommunityCategoryArgs(communityId: communityId, category: category, channels: channels)) + CommunityCategoryArgs(communityId: communityId, category: category, chats: chats)) except Exception as e: error "Error creating community category", msg = e.msg, communityId, name @@ -566,7 +578,7 @@ QtObject: for k, v in response.result["communityChanges"].getElems()[0]["categoriesModified"].pairs(): let category = v.toCategory() self.events.emit(SIGNAL_COMMUNITY_CATEGORY_EDITED, - CommunityCategoryArgs(communityId: communityId, category: category, channels: channels)) + CommunityCategoryArgs(communityId: communityId, category: category #[, channels: channels]#)) # TODO: add channels except Exception as e: error "Error creating community category", msg = e.msg, communityId, name diff --git a/ui/app/AppLayouts/Chat/popups/community/CreateCategoryPopup.qml b/ui/app/AppLayouts/Chat/popups/community/CreateCategoryPopup.qml index 746acf0a17..66646fe9f0 100644 --- a/ui/app/AppLayouts/Chat/popups/community/CreateCategoryPopup.qml +++ b/ui/app/AppLayouts/Chat/popups/community/CreateCategoryPopup.qml @@ -58,7 +58,7 @@ StatusModal { input.placeholderText: qsTr("Category title") validators: [StatusMinLengthValidator { minLength: 1 - errorMessage: Utils.getErrorMessage(errors, qsTr("category name")) + errorMessage: Utils.getErrorMessage(nameInput.errors, qsTr("category name")) }] } @@ -117,9 +117,10 @@ StatusModal { delegate: StatusListItem { anchors.horizontalCenter: parent.horizontalCenter - visible: true/*root.isEdit ? - model.categoryId === root.categoryId || model.categoryId === "" : - model.categoryId === ""*/ + visible: { + // TODO: if edit, show only the subitems of the current category + return root.isEdit ? null : !model.isCategory + } height: visible ? implicitHeight : 0 title: "#" + model.name icon.isLetterIdenticon: true @@ -131,7 +132,6 @@ StatusModal { id: channelItemCheckbox checked: root.isEdit ? root.channels.indexOf(model.itemId) > - 1 : false onCheckedChanged: { - print("CHECK CHANNEL", model.itemId) var idx = root.channels.indexOf(model.itemId) if(checked){ if(idx === -1){ diff --git a/ui/app/AppLayouts/Chat/views/CommunityColumnView.qml b/ui/app/AppLayouts/Chat/views/CommunityColumnView.qml index 670f8a7b0c..31a84f34fa 100644 --- a/ui/app/AppLayouts/Chat/views/CommunityColumnView.qml +++ b/ui/app/AppLayouts/Chat/views/CommunityColumnView.qml @@ -68,8 +68,7 @@ Item { text: qsTrId("create-category") icon.name: "channel-category" enabled: communityData.amISectionAdmin - // Not Refactored Yet - onTriggered: Global.openPopup(createCategoryPopup, {communityId: root.store.chatCommunitySectionModule.activeItem.id}) + onTriggered: Global.openPopup(createCategoryPopup) } StatusMenuSeparator {} @@ -187,9 +186,8 @@ Item { //% "Create category" text: qsTrId("create-category") icon.name: "channel-category" - // Not Refactored Yet enabled: communityData.amISectionAdmin - onTriggered: Global.openPopup(createCategoryPopup, {communityId: root.store.chatCommunitySectionModule.activeItem.id}) + onTriggered: Global.openPopup(createCategoryPopup) } StatusMenuSeparator {}