refactor(community): hook edit community feature
This commit is contained in:
parent
7fbd37a8f7
commit
3678b3af9b
|
@ -90,6 +90,26 @@ method createCommunity*(
|
|||
imageUrl,
|
||||
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*(
|
||||
self: Controller,
|
||||
communityId: string,
|
||||
|
|
|
@ -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.} =
|
||||
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.} =
|
||||
raise newException(ValueError, "No implementation available")
|
||||
|
||||
|
|
|
@ -123,13 +123,15 @@ 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 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,) =
|
||||
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) =
|
||||
let channelsSeq = map(parseJson(channels).getElems(), proc(x:JsonNode):string = x.getStr())
|
||||
self.controller.createCommunityCategory(communityId, name, channelsSeq)
|
||||
|
|
|
@ -103,6 +103,9 @@ method init*(self: Controller) =
|
|||
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):
|
||||
var args = ResolvedContactArgs(e)
|
||||
|
|
|
@ -495,6 +495,11 @@ method communityJoined*[T](
|
|||
self.view.addItem(self.createCommunityItem(community))
|
||||
# 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 =
|
||||
let contact = self.controller.getContact(publicKey)
|
||||
let (name, image, isIdenticon) = self.controller.getContactNameAndImage(contact.id)
|
||||
|
|
|
@ -23,5 +23,8 @@ method communityJoined*(self: AccessInterface, community: CommunityDto, events:
|
|||
messageService: message_service.Service) {.base.} =
|
||||
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.} =
|
||||
raise newException(ValueError, "No implementation available")
|
|
@ -14,6 +14,8 @@ QtObject:
|
|||
activeSectionVariant: QVariant
|
||||
tmpCommunityId: string # shouldn't be used anywhere except in prepareCommunitySectionModuleForCommunityId/getCommunitySectionModule procs
|
||||
|
||||
proc activeSectionChanged*(self:View) {.signal.}
|
||||
|
||||
proc delete*(self: View) =
|
||||
self.model.delete
|
||||
self.modelVariant.delete
|
||||
|
@ -37,6 +39,12 @@ QtObject:
|
|||
proc addItem*(self: View, item: SectionItem) =
|
||||
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 =
|
||||
return self.model
|
||||
|
||||
|
@ -67,8 +75,6 @@ QtObject:
|
|||
proc emitStoringPasswordSuccess*(self: View) =
|
||||
self.storingPasswordSuccess()
|
||||
|
||||
proc activeSectionChanged*(self:View) {.signal.}
|
||||
|
||||
proc getActiveSection(self: View): QVariant {.slot.} =
|
||||
return self.activeSectionVariant
|
||||
|
||||
|
|
|
@ -18,7 +18,7 @@ QtObject:
|
|||
proc setActiveSectionData*(self: ActiveSection, item: SectionItem) =
|
||||
self.item = item
|
||||
|
||||
proc getId(self: ActiveSection): string {.slot.} =
|
||||
proc getId*(self: ActiveSection): string {.slot.} =
|
||||
return self.item.id
|
||||
|
||||
QtProperty[string] id:
|
||||
|
|
|
@ -121,6 +121,29 @@ QtObject:
|
|||
|
||||
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 =
|
||||
for it in self.items:
|
||||
if(it.id == id):
|
||||
|
|
|
@ -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_LEFT* = "SIGNAL_COMMUNITY_LEFT"
|
||||
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_EDITED* = "SIGNAL_COMMUNITY_CHANNEL_EDITED"
|
||||
const SIGNAL_COMMUNITY_CHANNEL_REORDERED* = "SIGNAL_COMMUNITY_CHANNEL_REORDERED"
|
||||
|
@ -261,7 +262,38 @@ QtObject:
|
|||
self.events.emit(SIGNAL_COMMUNITY_CREATED, CommunityArgs(community: community))
|
||||
except Exception as e:
|
||||
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*(
|
||||
self: Service,
|
||||
|
@ -283,7 +315,6 @@ QtObject:
|
|||
)
|
||||
except Exception as e:
|
||||
error "Error creating community channel", msg = e.msg, communityId, name, description
|
||||
raise newException(RpcException, "Error creating community channel: " & e.msg)
|
||||
|
||||
proc editCommunityChannel*(
|
||||
self: Service,
|
||||
|
@ -311,7 +342,6 @@ QtObject:
|
|||
self.events.emit(SIGNAL_COMMUNITY_CHANNEL_EDITED, CommunityChatArgs(chat: chat))
|
||||
except Exception as e:
|
||||
error "Error editing community channel", msg = e.msg, communityId, channelId
|
||||
raise newException(RpcException, "Error editing community channel: " & e.msg)
|
||||
|
||||
proc reorderCommunityChat*(
|
||||
self: Service,
|
||||
|
@ -340,7 +370,6 @@ QtObject:
|
|||
)
|
||||
except Exception as e:
|
||||
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) =
|
||||
try:
|
||||
|
@ -358,7 +387,6 @@ QtObject:
|
|||
)
|
||||
except Exception as e:
|
||||
error "Error deleting community channel", msg = e.msg, communityId, chatId
|
||||
raise newException(RpcException, "Error deleting community channel: " & e.msg)
|
||||
|
||||
proc createCommunityCategory*(
|
||||
self: Service,
|
||||
|
@ -380,7 +408,6 @@ QtObject:
|
|||
|
||||
except Exception as e:
|
||||
error "Error creating community category", msg = e.msg, communityId, name
|
||||
raise newException(RpcException, "Error creating community category: " & e.msg)
|
||||
|
||||
proc editCommunityCategory*(
|
||||
self: Service,
|
||||
|
@ -402,7 +429,6 @@ QtObject:
|
|||
CommunityCategoryArgs(communityId: communityId, category: category, channels: channels))
|
||||
except Exception as e:
|
||||
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) =
|
||||
try:
|
||||
|
@ -420,7 +446,6 @@ QtObject:
|
|||
)
|
||||
except Exception as e:
|
||||
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) =
|
||||
try:
|
||||
|
@ -430,7 +455,6 @@ QtObject:
|
|||
raise newException(RpcException, fmt"Error requesting community info: {error.message}")
|
||||
except Exception as e:
|
||||
error "Error requesting community info", msg = e.msg, communityId
|
||||
raise newException(RpcException, "Error requesting community info: " & e.msg)
|
||||
|
||||
|
||||
proc importCommunity*(self: Service, communityKey: string) =
|
||||
|
@ -441,7 +465,6 @@ QtObject:
|
|||
raise newException(RpcException, fmt"Error importing the community: {error.message}")
|
||||
except Exception as e:
|
||||
error "Error requesting community info", msg = e.msg
|
||||
raise newException(RpcException, "Error requesting community info: " & e.msg)
|
||||
|
||||
proc exportCommunity*(self: Service, communityId: string): string =
|
||||
try:
|
||||
|
@ -450,46 +473,39 @@ QtObject:
|
|||
return response.result.getStr
|
||||
except Exception as e:
|
||||
error "Error exporting community", msg = e.msg
|
||||
raise newException(RpcException, "Error exporting community: " & e.msg)
|
||||
|
||||
proc acceptRequestToJoinCommunity*(self: Service, requestId: string) =
|
||||
try:
|
||||
discard status_go.acceptRequestToJoinCommunity(requestId)
|
||||
except Exception as e:
|
||||
error "Error exporting community", msg = e.msg
|
||||
raise newException(RpcException, "Error exporting community: " & e.msg)
|
||||
|
||||
proc declineRequestToJoinCommunity*(self: Service, requestId: string) =
|
||||
try:
|
||||
discard status_go.declineRequestToJoinCommunity(requestId)
|
||||
except Exception as e:
|
||||
error "Error exporting community", msg = e.msg
|
||||
raise newException(RpcException, "Error exporting community: " & e.msg)
|
||||
|
||||
# proc inviteUsersToCommunityById*(self: Service, communityId: string, pubKeys: string) =
|
||||
# try:
|
||||
# discard status_go.inviteUsersToCommunityById(communityId, pubKeys)
|
||||
# except Exception as e:
|
||||
# error "Error exporting community", msg = e.msg
|
||||
# raise newException(RpcException, "Error exporting community: " & e.msg)
|
||||
|
||||
proc removeUserFromCommunity*(self: Service, communityId: string, pubKeys: string) =
|
||||
try:
|
||||
discard status_go.removeUserFromCommunity(communityId, pubKeys)
|
||||
except Exception as e:
|
||||
error "Error exporting community", msg = e.msg
|
||||
raise newException(RpcException, "Error exporting community: " & e.msg)
|
||||
|
||||
proc banUserFromCommunity*(self: Service, communityId: string, pubKey: string) =
|
||||
try:
|
||||
discard status_go.banUserFromCommunity(communityId, pubKey)
|
||||
except Exception as e:
|
||||
error "Error exporting community", msg = e.msg
|
||||
raise newException(RpcException, "Error exporting community: " & e.msg)
|
||||
|
||||
proc setCommunityMuted*(self: Service, communityId: string, muted: bool) =
|
||||
try:
|
||||
discard status_go.setCommunityMuted(communityId, muted)
|
||||
except Exception as e:
|
||||
error "Error exporting community", msg = e.msg
|
||||
raise newException(RpcException, "Error exporting community: " & e.msg)
|
||||
|
|
|
@ -138,8 +138,7 @@ QtObject {
|
|||
}
|
||||
|
||||
function editCommunity(communityId, communityName, communityDescription, checkedMembership, ensOnlySwitchChecked, communityColor, communityImage, imageCropperModalaX, imageCropperModalaY, imageCropperModalbX, imageCropperModalbY) {
|
||||
// Not Refactored Yet
|
||||
// chatsModelInst.communities.editCommunity(communityId, communityName, communityDescription, checkedMembership, ensOnlySwitchChecked, communityColor, communityImage, imageCropperModalaX, imageCropperModalaY, imageCropperModalbX, imageCropperModalbY);
|
||||
communitiesModuleInst.editCommunity(communityId, communityName, communityDescription, checkedMembership, ensOnlySwitchChecked, communityColor, communityImage, imageCropperModalaX, imageCropperModalaY, imageCropperModalbX, imageCropperModalbY);
|
||||
}
|
||||
|
||||
function createCommunityCategory(communityId, categoryName, channels) {
|
||||
|
|
|
@ -46,9 +46,7 @@ Item {
|
|||
|
||||
chatInfoButton.image.source: communityData.image
|
||||
chatInfoButton.icon.color: communityData.color
|
||||
menuButton.visible: {
|
||||
return communityData.amISectionAdmin && communityData.canManageUsers
|
||||
}
|
||||
menuButton.visible: communityData.amISectionAdmin && communityData.canManageUsers
|
||||
// TODO remove dynamic scoping of popup component
|
||||
chatInfoButton.onClicked: Global.openPopup(communityProfilePopup, {
|
||||
store: root.store,
|
||||
|
@ -182,7 +180,7 @@ Item {
|
|||
icon.name: "channel"
|
||||
// Not Refactored Yet
|
||||
enabled: communityData.amISectionAdmin
|
||||
// onTriggered: Global.openPopup(createChannelPopup, {communityId: root.store.chatsModelInst.communities.activeCommunity.id})
|
||||
onTriggered: Global.openPopup(createChannelPopup)
|
||||
}
|
||||
|
||||
StatusMenuItem {
|
||||
|
@ -350,7 +348,7 @@ Item {
|
|||
anchors.topMargin: active ? Style.current.padding : 0
|
||||
sourceComponent: Component {
|
||||
CommunityWelcomeBannerPanel {
|
||||
activeCommunity: store.activeCommunity
|
||||
activeCommunity: communityData
|
||||
store: root.store
|
||||
}
|
||||
}
|
||||
|
@ -372,7 +370,7 @@ Item {
|
|||
|
||||
BackUpCommuntyBannerPanel {
|
||||
id: backupBanner
|
||||
activeCommunity: store.activeCommunity
|
||||
activeCommunity: communityData
|
||||
onBackupButtonClicked: {
|
||||
Global.openPopup(transferOwnershipPopup, {
|
||||
privateKey: root.store.exportCommunity(),
|
||||
|
|
Loading…
Reference in New Issue