refactor: create categories (WIP)

This commit is contained in:
Boris Melnik 2022-01-25 23:39:20 +03:00 committed by Sale Djenic
parent caa85a79b4
commit 0065f5cae5
8 changed files with 34 additions and 16 deletions

View File

@ -275,6 +275,9 @@ method createCommunityChannel*(
description: string) = description: string) =
self.communityService.createCommunityChannel(self.sectionId, name, description) self.communityService.createCommunityChannel(self.sectionId, name, description)
method createCommunityCategory*(self: Controller, name: string, channels: seq[string]) =
self.communityService.createCommunityCategory(self.sectionId, name, channels)
method leaveCommunity*(self: Controller) = method leaveCommunity*(self: Controller) =
self.communityService.leaveCommunity(self.sectionId) self.communityService.leaveCommunity(self.sectionId)

View File

@ -126,6 +126,9 @@ method declineRequestToJoinCommunity*(self: AccessInterface, requestId: string)
method createCommunityChannel*(self: AccessInterface, name: string, description: string) {.base.} = method createCommunityChannel*(self: AccessInterface, name: string, description: string) {.base.} =
raise newException(ValueError, "No implementation available") raise newException(ValueError, "No implementation available")
method createCommunityCategory*(self: AccessInterface, name: string, channels: seq[string]) {.base.} =
raise newException(ValueError, "No implementation available")
method leaveCommunity*(self: AccessInterface) {.base.} = method leaveCommunity*(self: AccessInterface) {.base.} =
raise newException(ValueError, "No implementation available") raise newException(ValueError, "No implementation available")

View File

@ -541,6 +541,12 @@ method declineRequestToJoinCommunity*(self: Module, requestId: string) =
method createCommunityChannel*(self: Module, name, description: string,) = method createCommunityChannel*(self: Module, name, description: string,) =
self.controller.createCommunityChannel(name, description) 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 leaveCommunity*(self: Module) = method leaveCommunity*(self: Module) =
self.controller.leaveCommunity() self.controller.leaveCommunity()

View File

@ -108,3 +108,6 @@ method setCommunityMuted*(self: AccessInterface, muted: bool) {.base.} =
method inviteUsersToCommunity*(self: AccessInterface, pubKeysJSON: string): string {.base.} = method inviteUsersToCommunity*(self: AccessInterface, pubKeysJSON: string): string {.base.} =
raise newException(ValueError, "No implementation available") raise newException(ValueError, "No implementation available")
method createCommunityCategory*(self: AccessInterface, name: string, channels: string) {.base.} =
raise newException(ValueError, "No implementation available")

View File

@ -205,3 +205,6 @@ QtObject:
proc inviteUsersToCommunity*(self: View, pubKeysJSON: string): string {.slot.} = proc inviteUsersToCommunity*(self: View, pubKeysJSON: string): string {.slot.} =
result = self.delegate.inviteUsersToCommunity(pubKeysJSON) result = self.delegate.inviteUsersToCommunity(pubKeysJSON)
proc createCommunityCategory*(self: View, name: string, channels: string) {.slot.} =
self.delegate.createCommunityCategory(name, channels)

View File

@ -31,7 +31,7 @@ StatusModal {
if(isEdit){ if(isEdit){
root.contentItem.categoryName.input.text = categoryName root.contentItem.categoryName.input.text = categoryName
// Not Refactored Yet // Not Refactored Yet
// channels = JSON.parse(root.store.chatsModelInst.communities.activeCommunity.getChatIdsByCategory(categoryId)) // channels = //JSON.parse(root.store.chatsModelInst.communities.activeCommunity.getChatIdsByCategory(categoryId))
} }
root.contentItem.categoryName.input.forceActiveFocus(Qt.MouseFocusReason) root.contentItem.categoryName.input.forceActiveFocus(Qt.MouseFocusReason)
} }
@ -111,15 +111,15 @@ StatusModal {
height: childrenRect.height height: childrenRect.height
width: parent.width width: parent.width
// Not Refactored Yet // Not Refactored Yet
// model: root.store.activeCommunityChatsModel model: root.store.chatCommunitySectionModule.model//activeCommunityChatsModel
interactive: false interactive: false
clip: true clip: true
delegate: StatusListItem { delegate: StatusListItem {
anchors.horizontalCenter: parent.horizontalCenter anchors.horizontalCenter: parent.horizontalCenter
visible: root.isEdit ? visible: true/*root.isEdit ?
model.categoryId === root.categoryId || model.categoryId === "" : model.categoryId === root.categoryId || model.categoryId === "" :
model.categoryId === "" model.categoryId === ""*/
height: visible ? implicitHeight : 0 height: visible ? implicitHeight : 0
title: "#" + model.name title: "#" + model.name
icon.isLetterIdenticon: true icon.isLetterIdenticon: true
@ -129,12 +129,13 @@ StatusModal {
components: [ components: [
StatusCheckBox { StatusCheckBox {
id: channelItemCheckbox id: channelItemCheckbox
checked: root.isEdit ? root.channels.indexOf(model.id) > - 1 : false checked: root.isEdit ? root.channels.indexOf(model.itemId) > - 1 : false
onCheckedChanged: { onCheckedChanged: {
var idx = root.channels.indexOf(model.id) print("CHECK CHANNEL", model.itemId)
var idx = root.channels.indexOf(model.itemId)
if(checked){ if(checked){
if(idx === -1){ if(idx === -1){
root.channels.push(model.id) root.channels.push(model.itemId)
} }
} else { } else {
if(idx > -1){ if(idx > -1){
@ -221,9 +222,9 @@ StatusModal {
let error = "" let error = ""
if (isEdit) { if (isEdit) {
error = root.store.editCommunityCategory(communityId, categoryId, Utils.filterXSS(root.contentItem.categoryName.input.text), JSON.stringify(channels)); // error = root.store.editCommunityCategory(communityId, categoryId, Utils.filterXSS(root.contentItem.categoryName.input.text), JSON.stringify(channels));
} else { } else {
error = root.store.createCommunityCategory(communityId, Utils.filterXSS(root.contentItem.categoryName.input.text), JSON.stringify(channels)); error = root.store.createCommunityCategory(root.contentItem.categoryName.input.text, JSON.stringify(channels));
} }
if (error) { if (error) {

View File

@ -146,9 +146,8 @@ QtObject {
communitiesModuleInst.createCommunity(communityName, communityDescription, checkedMembership, ensOnlySwitchChecked, communityColor, communityImage, imageCropperModalaX, imageCropperModalaY, imageCropperModalbX, imageCropperModalbY); communitiesModuleInst.createCommunity(communityName, communityDescription, checkedMembership, ensOnlySwitchChecked, communityColor, communityImage, imageCropperModalaX, imageCropperModalaY, imageCropperModalbX, imageCropperModalbY);
} }
function createCommunityCategory(communityId, categoryName, channels) { function createCommunityCategory(categoryName, channels) {
// Not Refactored Yet chatCommunitySectionModule.createCommunityCategory(categoryName, channels)
// chatsModelInst.communities.createCommunityCategory(communityId, categoryName, channels);
} }
function editCommunityCategory(communityId, categoryId, categoryName, channels) { function editCommunityCategory(communityId, categoryId, categoryName, channels) {

View File

@ -69,7 +69,7 @@ Item {
icon.name: "channel-category" icon.name: "channel-category"
enabled: communityData.amISectionAdmin enabled: communityData.amISectionAdmin
// Not Refactored Yet // Not Refactored Yet
// onTriggered: Global.openPopup(createCategoryPopup, {communityId: chatsModel.communities.activeCommunity.id}) onTriggered: Global.openPopup(createCategoryPopup, {communityId: root.store.chatCommunitySectionModule.activeItem.id})
} }
StatusMenuSeparator {} StatusMenuSeparator {}
@ -189,7 +189,7 @@ Item {
icon.name: "channel-category" icon.name: "channel-category"
// Not Refactored Yet // Not Refactored Yet
enabled: communityData.amISectionAdmin enabled: communityData.amISectionAdmin
// onTriggered: Global.openPopup(createCategoryPopup, {communityId: root.store.chatsModelInst.communities.activeCommunity.id}) onTriggered: Global.openPopup(createCategoryPopup, {communityId: root.store.chatCommunitySectionModule.activeItem.id})
} }
StatusMenuSeparator {} StatusMenuSeparator {}