feat(communities): create categories

This commit is contained in:
Richard Ramos 2022-01-27 20:02:06 -04:00 committed by Sale Djenic
parent 24fa56e3b8
commit b67e97a05c
13 changed files with 59 additions and 64 deletions

View File

@ -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):

View File

@ -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()

View File

@ -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")

View File

@ -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")

View File

@ -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)
let channelsSeq = map(parseJson(channels).getElems(), proc(x:JsonNode):string = x.getStr())
self.delegate.createCommunityCategory(name, channelsSeq)

View File

@ -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,

View File

@ -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")

View File

@ -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)

View File

@ -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")

View File

@ -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)

View File

@ -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

View File

@ -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){

View File

@ -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 {}