refactor(community): hook edit community feature

This commit is contained in:
Jonathan Rainville 2022-01-06 10:54:13 -05:00 committed by Sale Djenic
parent 7fbd37a8f7
commit 3678b3af9b
12 changed files with 110 additions and 32 deletions

View File

@ -90,6 +90,26 @@ method createCommunity*(
imageUrl, imageUrl,
aX, aY, bX, bY) aX, aY, bX, bY)
method editCommunity*(
self: Controller,
id: string,
name: string,
description: string,
access: int,
ensOnly: bool,
color: string,
imageUrl: string,
aX: int, aY: int, bX: int, bY: int) =
self.communityService.editCommunity(
id,
name,
description,
access,
ensOnly,
color,
imageUrl,
aX, aY, bX, bY)
method createCommunityChannel*( method createCommunityChannel*(
self: Controller, self: Controller,
communityId: string, communityId: string,

View File

@ -22,6 +22,9 @@ method leaveCommunity*(self: AccessInterface, communityId: string) {.base.} =
method createCommunity*(self: AccessInterface, name: string, description: string, access: int, ensOnly: bool, color: string, imageUrl: string, aX: int, aY: int, bX: int, bY: int) {.base.} = method createCommunity*(self: AccessInterface, name: string, description: string, access: int, ensOnly: bool, color: string, imageUrl: string, aX: int, aY: int, bX: int, bY: int) {.base.} =
raise newException(ValueError, "No implementation available") raise newException(ValueError, "No implementation available")
method editCommunity*(self: AccessInterface, id: string, name: string, description: string, access: int, ensOnly: bool, color: string, imageUrl: string, aX: int, aY: int, bX: int, bY: int) {.base.} =
raise newException(ValueError, "No implementation available")
method createCommunityChannel*(self: AccessInterface, communityId: string, name: string, description: string) {.base.} = method createCommunityChannel*(self: AccessInterface, communityId: string, name: string, description: string) {.base.} =
raise newException(ValueError, "No implementation available") raise newException(ValueError, "No implementation available")

View File

@ -123,13 +123,15 @@ method createCommunity*(self: Module, name: string, description: string,
aX: int, aY: int, bX: int, bY: int) = aX: int, aY: int, bX: int, bY: int) =
self.controller.createCommunity(name, description, access, ensOnly, color, imagePath, aX, aY, bX, bY) self.controller.createCommunity(name, description, access, ensOnly, color, imagePath, aX, aY, bX, bY)
method editCommunity*(self: Module, id: string, name: string, description: string,
access: int, ensOnly: bool, color: string,
imagePath: string,
aX: int, aY: int, bX: int, bY: int) =
self.controller.editCommunity(id, name, description, access, ensOnly, color, imagePath, aX, aY, bX, bY)
method createCommunityChannel*(self: Module, communityId, name, description: string,) = method createCommunityChannel*(self: Module, communityId, name, description: string,) =
self.controller.createCommunityChannel(communityId, name, description) self.controller.createCommunityChannel(communityId, name, description)
method editCommunity*(self: Module, id: string, name: string, description: string, access: int, ensOnly: bool, color: string, imagePath: string, aX: int, aY: int, bX: int, bY: int) =
# self.controller.editCommunity(id, name, description, access, ensOnly, color, imagePath, aX, aY, bX, bY)
discard
method createCommunityCategory*(self: Module, communityId: string, name: string, channels: string) = method createCommunityCategory*(self: Module, communityId: string, name: string, channels: string) =
let channelsSeq = map(parseJson(channels).getElems(), proc(x:JsonNode):string = x.getStr()) let channelsSeq = map(parseJson(channels).getElems(), proc(x:JsonNode):string = x.getStr())
self.controller.createCommunityCategory(communityId, name, channelsSeq) self.controller.createCommunityCategory(communityId, name, channelsSeq)

View File

@ -103,6 +103,9 @@ method init*(self: Controller) =
self.messageService self.messageService
) )
self.events.on(SIGNAL_COMMUNITY_EDITED) do(e:Args):
let args = CommunityArgs(e)
self.delegate.communityEdited(args.community)
self.events.on(SIGNAL_ENS_RESOLVED) do(e: Args): self.events.on(SIGNAL_ENS_RESOLVED) do(e: Args):
var args = ResolvedContactArgs(e) var args = ResolvedContactArgs(e)

View File

@ -495,6 +495,11 @@ method communityJoined*[T](
self.view.addItem(self.createCommunityItem(community)) self.view.addItem(self.createCommunityItem(community))
# TODO do we need to set it as active # TODO do we need to set it as active
method communityEdited*[T](
self: Module[T],
community: CommunityDto) =
self.view.editItem(self.createCommunityItem(community))
method getContactDetailsAsJson*[T](self: Module[T], publicKey: string): string = method getContactDetailsAsJson*[T](self: Module[T], publicKey: string): string =
let contact = self.controller.getContact(publicKey) let contact = self.controller.getContact(publicKey)
let (name, image, isIdenticon) = self.controller.getContactNameAndImage(contact.id) let (name, image, isIdenticon) = self.controller.getContactNameAndImage(contact.id)

View File

@ -23,5 +23,8 @@ method communityJoined*(self: AccessInterface, community: CommunityDto, events:
messageService: message_service.Service) {.base.} = messageService: message_service.Service) {.base.} =
raise newException(ValueError, "No implementation available") raise newException(ValueError, "No implementation available")
method communityEdited*(self: AccessInterface, community: CommunityDto) {.base.} =
raise newException(ValueError, "No implementation available")
method resolvedENS*(self: AccessInterface, publicKey: string, address: string, uuid: string) {.base.} = method resolvedENS*(self: AccessInterface, publicKey: string, address: string, uuid: string) {.base.} =
raise newException(ValueError, "No implementation available") raise newException(ValueError, "No implementation available")

View File

@ -14,6 +14,8 @@ QtObject:
activeSectionVariant: QVariant activeSectionVariant: QVariant
tmpCommunityId: string # shouldn't be used anywhere except in prepareCommunitySectionModuleForCommunityId/getCommunitySectionModule procs tmpCommunityId: string # shouldn't be used anywhere except in prepareCommunitySectionModuleForCommunityId/getCommunitySectionModule procs
proc activeSectionChanged*(self:View) {.signal.}
proc delete*(self: View) = proc delete*(self: View) =
self.model.delete self.model.delete
self.modelVariant.delete self.modelVariant.delete
@ -37,6 +39,12 @@ QtObject:
proc addItem*(self: View, item: SectionItem) = proc addItem*(self: View, item: SectionItem) =
self.model.addItem(item) self.model.addItem(item)
proc editItem*(self: View, item: SectionItem) =
self.model.editItem(item)
if (self.activeSection.getId() == item.id):
self.activeSection.setActiveSectionData(item)
self.activeSectionChanged()
proc model*(self: View): SectionModel = proc model*(self: View): SectionModel =
return self.model return self.model
@ -67,8 +75,6 @@ QtObject:
proc emitStoringPasswordSuccess*(self: View) = proc emitStoringPasswordSuccess*(self: View) =
self.storingPasswordSuccess() self.storingPasswordSuccess()
proc activeSectionChanged*(self:View) {.signal.}
proc getActiveSection(self: View): QVariant {.slot.} = proc getActiveSection(self: View): QVariant {.slot.} =
return self.activeSectionVariant return self.activeSectionVariant

View File

@ -18,7 +18,7 @@ QtObject:
proc setActiveSectionData*(self: ActiveSection, item: SectionItem) = proc setActiveSectionData*(self: ActiveSection, item: SectionItem) =
self.item = item self.item = item
proc getId(self: ActiveSection): string {.slot.} = proc getId*(self: ActiveSection): string {.slot.} =
return self.item.id return self.item.id
QtProperty[string] id: QtProperty[string] id:

View File

@ -121,6 +121,29 @@ QtObject:
self.countChanged() self.countChanged()
proc getItemIndex*(self: SectionModel, id: string): int =
var i = 0
for item in self.items:
if item.id == id:
return i
i.inc()
return -1
proc editItem*(self: SectionModel, item: SectionItem) =
let index = self.getItemIndex(item.id)
if (index == -1):
return
self.items[index] = item
let dataIndex = self.createIndex(index, 0, nil)
self.dataChanged(dataIndex, dataIndex, @[
ModelRole.Name.int,
ModelRole.Description.int,
ModelRole.Image.int,
ModelRole.Icon.int,
ModelRole.Color.int
])
proc getItemById*(self: SectionModel, id: string): SectionItem = proc getItemById*(self: SectionModel, id: string): SectionItem =
for it in self.items: for it in self.items:
if(it.id == id): if(it.id == id):

View File

@ -44,6 +44,7 @@ const SIGNAL_COMMUNITY_JOINED* = "SIGNAL_COMMUNITY_JOINED"
const SIGNAL_COMMUNITY_MY_REQUEST_ADDED* = "SIGNAL_COMMUNITY_MY_REQUEST_ADDED" const SIGNAL_COMMUNITY_MY_REQUEST_ADDED* = "SIGNAL_COMMUNITY_MY_REQUEST_ADDED"
const SIGNAL_COMMUNITY_LEFT* = "SIGNAL_COMMUNITY_LEFT" const SIGNAL_COMMUNITY_LEFT* = "SIGNAL_COMMUNITY_LEFT"
const SIGNAL_COMMUNITY_CREATED* = "SIGNAL_COMMUNITY_CREATED" const SIGNAL_COMMUNITY_CREATED* = "SIGNAL_COMMUNITY_CREATED"
const SIGNAL_COMMUNITY_EDITED* = "SIGNAL_COMMUNITY_EDITED"
const SIGNAL_COMMUNITY_CHANNEL_CREATED* = "SIGNAL_COMMUNITY_CHANNEL_CREATED" const SIGNAL_COMMUNITY_CHANNEL_CREATED* = "SIGNAL_COMMUNITY_CHANNEL_CREATED"
const SIGNAL_COMMUNITY_CHANNEL_EDITED* = "SIGNAL_COMMUNITY_CHANNEL_EDITED" const SIGNAL_COMMUNITY_CHANNEL_EDITED* = "SIGNAL_COMMUNITY_CHANNEL_EDITED"
const SIGNAL_COMMUNITY_CHANNEL_REORDERED* = "SIGNAL_COMMUNITY_CHANNEL_REORDERED" const SIGNAL_COMMUNITY_CHANNEL_REORDERED* = "SIGNAL_COMMUNITY_CHANNEL_REORDERED"
@ -261,7 +262,38 @@ QtObject:
self.events.emit(SIGNAL_COMMUNITY_CREATED, CommunityArgs(community: community)) self.events.emit(SIGNAL_COMMUNITY_CREATED, CommunityArgs(community: community))
except Exception as e: except Exception as e:
error "Error creating community", msg = e.msg error "Error creating community", msg = e.msg
raise newException(RpcException, "Error creating community: " & e.msg)
proc editCommunity*(
self: Service,
id: string,
name: string,
description: string,
access: int,
ensOnly: bool,
color: string,
imageUrl: string,
aX: int, aY: int, bX: int, bY: int) =
try:
var image = singletonInstance.utils.formatImagePath(imageUrl)
let response = status_go.editCommunity(
id,
name,
description,
access,
ensOnly,
color,
image,
aX, aY, bX, bY)
if response.error != nil:
let error = Json.decode($response.error, RpcError)
raise newException(RpcException, "Error editing community: " & error.message)
if response.result != nil and response.result.kind != JNull:
let community = response.result["communities"][0].toCommunityDto()
self.events.emit(SIGNAL_COMMUNITY_EDITED, CommunityArgs(community: community))
except Exception as e:
error "Error editing community", msg = e.msg
proc createCommunityChannel*( proc createCommunityChannel*(
self: Service, self: Service,
@ -283,7 +315,6 @@ QtObject:
) )
except Exception as e: except Exception as e:
error "Error creating community channel", msg = e.msg, communityId, name, description error "Error creating community channel", msg = e.msg, communityId, name, description
raise newException(RpcException, "Error creating community channel: " & e.msg)
proc editCommunityChannel*( proc editCommunityChannel*(
self: Service, self: Service,
@ -311,7 +342,6 @@ QtObject:
self.events.emit(SIGNAL_COMMUNITY_CHANNEL_EDITED, CommunityChatArgs(chat: chat)) self.events.emit(SIGNAL_COMMUNITY_CHANNEL_EDITED, CommunityChatArgs(chat: chat))
except Exception as e: except Exception as e:
error "Error editing community channel", msg = e.msg, communityId, channelId error "Error editing community channel", msg = e.msg, communityId, channelId
raise newException(RpcException, "Error editing community channel: " & e.msg)
proc reorderCommunityChat*( proc reorderCommunityChat*(
self: Service, self: Service,
@ -340,7 +370,6 @@ QtObject:
) )
except Exception as e: except Exception as e:
error "Error reordering community channel", msg = e.msg, communityId, chatId, position error "Error reordering community channel", msg = e.msg, communityId, chatId, position
raise newException(RpcException, "Error reordering community channel: " & e.msg)
proc deleteCommunityChat*(self: Service, communityId: string, chatId: string) = proc deleteCommunityChat*(self: Service, communityId: string, chatId: string) =
try: try:
@ -358,7 +387,6 @@ QtObject:
) )
except Exception as e: except Exception as e:
error "Error deleting community channel", msg = e.msg, communityId, chatId error "Error deleting community channel", msg = e.msg, communityId, chatId
raise newException(RpcException, "Error deleting community channel: " & e.msg)
proc createCommunityCategory*( proc createCommunityCategory*(
self: Service, self: Service,
@ -380,7 +408,6 @@ QtObject:
except Exception as e: except Exception as e:
error "Error creating community category", msg = e.msg, communityId, name error "Error creating community category", msg = e.msg, communityId, name
raise newException(RpcException, "Error creating community category: " & e.msg)
proc editCommunityCategory*( proc editCommunityCategory*(
self: Service, self: Service,
@ -402,7 +429,6 @@ QtObject:
CommunityCategoryArgs(communityId: communityId, category: category, channels: channels)) CommunityCategoryArgs(communityId: communityId, category: category, channels: channels))
except Exception as e: except Exception as e:
error "Error creating community category", msg = e.msg, communityId, name error "Error creating community category", msg = e.msg, communityId, name
raise newException(RpcException, "Error creating community category: " & e.msg)
proc deleteCommunityCategory*(self: Service, communityId: string, categoryId: string) = proc deleteCommunityCategory*(self: Service, communityId: string, categoryId: string) =
try: try:
@ -420,7 +446,6 @@ QtObject:
) )
except Exception as e: except Exception as e:
error "Error deleting community category", msg = e.msg, communityId, categoryId error "Error deleting community category", msg = e.msg, communityId, categoryId
raise newException(RpcException, "Error deleting community category: " & e.msg)
proc requestCommunityInfo*(self: Service, communityId: string) = proc requestCommunityInfo*(self: Service, communityId: string) =
try: try:
@ -430,7 +455,6 @@ QtObject:
raise newException(RpcException, fmt"Error requesting community info: {error.message}") raise newException(RpcException, fmt"Error requesting community info: {error.message}")
except Exception as e: except Exception as e:
error "Error requesting community info", msg = e.msg, communityId error "Error requesting community info", msg = e.msg, communityId
raise newException(RpcException, "Error requesting community info: " & e.msg)
proc importCommunity*(self: Service, communityKey: string) = proc importCommunity*(self: Service, communityKey: string) =
@ -441,7 +465,6 @@ QtObject:
raise newException(RpcException, fmt"Error importing the community: {error.message}") raise newException(RpcException, fmt"Error importing the community: {error.message}")
except Exception as e: except Exception as e:
error "Error requesting community info", msg = e.msg error "Error requesting community info", msg = e.msg
raise newException(RpcException, "Error requesting community info: " & e.msg)
proc exportCommunity*(self: Service, communityId: string): string = proc exportCommunity*(self: Service, communityId: string): string =
try: try:
@ -450,46 +473,39 @@ QtObject:
return response.result.getStr return response.result.getStr
except Exception as e: except Exception as e:
error "Error exporting community", msg = e.msg error "Error exporting community", msg = e.msg
raise newException(RpcException, "Error exporting community: " & e.msg)
proc acceptRequestToJoinCommunity*(self: Service, requestId: string) = proc acceptRequestToJoinCommunity*(self: Service, requestId: string) =
try: try:
discard status_go.acceptRequestToJoinCommunity(requestId) discard status_go.acceptRequestToJoinCommunity(requestId)
except Exception as e: except Exception as e:
error "Error exporting community", msg = e.msg error "Error exporting community", msg = e.msg
raise newException(RpcException, "Error exporting community: " & e.msg)
proc declineRequestToJoinCommunity*(self: Service, requestId: string) = proc declineRequestToJoinCommunity*(self: Service, requestId: string) =
try: try:
discard status_go.declineRequestToJoinCommunity(requestId) discard status_go.declineRequestToJoinCommunity(requestId)
except Exception as e: except Exception as e:
error "Error exporting community", msg = e.msg error "Error exporting community", msg = e.msg
raise newException(RpcException, "Error exporting community: " & e.msg)
# proc inviteUsersToCommunityById*(self: Service, communityId: string, pubKeys: string) = # proc inviteUsersToCommunityById*(self: Service, communityId: string, pubKeys: string) =
# try: # try:
# discard status_go.inviteUsersToCommunityById(communityId, pubKeys) # discard status_go.inviteUsersToCommunityById(communityId, pubKeys)
# except Exception as e: # except Exception as e:
# error "Error exporting community", msg = e.msg # error "Error exporting community", msg = e.msg
# raise newException(RpcException, "Error exporting community: " & e.msg)
proc removeUserFromCommunity*(self: Service, communityId: string, pubKeys: string) = proc removeUserFromCommunity*(self: Service, communityId: string, pubKeys: string) =
try: try:
discard status_go.removeUserFromCommunity(communityId, pubKeys) discard status_go.removeUserFromCommunity(communityId, pubKeys)
except Exception as e: except Exception as e:
error "Error exporting community", msg = e.msg error "Error exporting community", msg = e.msg
raise newException(RpcException, "Error exporting community: " & e.msg)
proc banUserFromCommunity*(self: Service, communityId: string, pubKey: string) = proc banUserFromCommunity*(self: Service, communityId: string, pubKey: string) =
try: try:
discard status_go.banUserFromCommunity(communityId, pubKey) discard status_go.banUserFromCommunity(communityId, pubKey)
except Exception as e: except Exception as e:
error "Error exporting community", msg = e.msg error "Error exporting community", msg = e.msg
raise newException(RpcException, "Error exporting community: " & e.msg)
proc setCommunityMuted*(self: Service, communityId: string, muted: bool) = proc setCommunityMuted*(self: Service, communityId: string, muted: bool) =
try: try:
discard status_go.setCommunityMuted(communityId, muted) discard status_go.setCommunityMuted(communityId, muted)
except Exception as e: except Exception as e:
error "Error exporting community", msg = e.msg error "Error exporting community", msg = e.msg
raise newException(RpcException, "Error exporting community: " & e.msg)

View File

@ -138,8 +138,7 @@ QtObject {
} }
function editCommunity(communityId, communityName, communityDescription, checkedMembership, ensOnlySwitchChecked, communityColor, communityImage, imageCropperModalaX, imageCropperModalaY, imageCropperModalbX, imageCropperModalbY) { function editCommunity(communityId, communityName, communityDescription, checkedMembership, ensOnlySwitchChecked, communityColor, communityImage, imageCropperModalaX, imageCropperModalaY, imageCropperModalbX, imageCropperModalbY) {
// Not Refactored Yet communitiesModuleInst.editCommunity(communityId, communityName, communityDescription, checkedMembership, ensOnlySwitchChecked, communityColor, communityImage, imageCropperModalaX, imageCropperModalaY, imageCropperModalbX, imageCropperModalbY);
// chatsModelInst.communities.editCommunity(communityId, communityName, communityDescription, checkedMembership, ensOnlySwitchChecked, communityColor, communityImage, imageCropperModalaX, imageCropperModalaY, imageCropperModalbX, imageCropperModalbY);
} }
function createCommunityCategory(communityId, categoryName, channels) { function createCommunityCategory(communityId, categoryName, channels) {

View File

@ -46,9 +46,7 @@ Item {
chatInfoButton.image.source: communityData.image chatInfoButton.image.source: communityData.image
chatInfoButton.icon.color: communityData.color chatInfoButton.icon.color: communityData.color
menuButton.visible: { menuButton.visible: communityData.amISectionAdmin && communityData.canManageUsers
return communityData.amISectionAdmin && communityData.canManageUsers
}
// TODO remove dynamic scoping of popup component // TODO remove dynamic scoping of popup component
chatInfoButton.onClicked: Global.openPopup(communityProfilePopup, { chatInfoButton.onClicked: Global.openPopup(communityProfilePopup, {
store: root.store, store: root.store,
@ -182,7 +180,7 @@ Item {
icon.name: "channel" icon.name: "channel"
// Not Refactored Yet // Not Refactored Yet
enabled: communityData.amISectionAdmin enabled: communityData.amISectionAdmin
// onTriggered: Global.openPopup(createChannelPopup, {communityId: root.store.chatsModelInst.communities.activeCommunity.id}) onTriggered: Global.openPopup(createChannelPopup)
} }
StatusMenuItem { StatusMenuItem {
@ -350,7 +348,7 @@ Item {
anchors.topMargin: active ? Style.current.padding : 0 anchors.topMargin: active ? Style.current.padding : 0
sourceComponent: Component { sourceComponent: Component {
CommunityWelcomeBannerPanel { CommunityWelcomeBannerPanel {
activeCommunity: store.activeCommunity activeCommunity: communityData
store: root.store store: root.store
} }
} }
@ -372,7 +370,7 @@ Item {
BackUpCommuntyBannerPanel { BackUpCommuntyBannerPanel {
id: backupBanner id: backupBanner
activeCommunity: store.activeCommunity activeCommunity: communityData
onBackupButtonClicked: { onBackupButtonClicked: {
Global.openPopup(transferOwnershipPopup, { Global.openPopup(transferOwnershipPopup, {
privateKey: root.store.exportCommunity(), privateKey: root.store.exportCommunity(),