refactor(community): hook leave community

This commit is contained in:
Jonathan Rainville 2022-01-07 09:23:18 -05:00 committed by Sale Djenic
parent 96e50a97ac
commit b7459b331b
10 changed files with 48 additions and 16 deletions

View File

@ -35,10 +35,6 @@ method init*(self: Controller) =
let args = CommunityRequestArgs(e) let args = CommunityRequestArgs(e)
# self.delegate.requestAdded() # self.delegate.requestAdded()
self.events.on(SIGNAL_COMMUNITY_LEFT) do(e:Args):
let args = CommunityIdArgs(e)
# self.delegate.communityLeft(args.communityId)
self.events.on(SIGNAL_COMMUNITY_CHANNEL_EDITED) do(e:Args): self.events.on(SIGNAL_COMMUNITY_CHANNEL_EDITED) do(e:Args):
let args = CommunityChatArgs(e) let args = CommunityChatArgs(e)
# self.delegate.communityChannelEdited() # self.delegate.communityChannelEdited()

View File

@ -103,6 +103,10 @@ method init*(self: Controller) =
self.messageService self.messageService
) )
self.events.on(SIGNAL_COMMUNITY_LEFT) do(e:Args):
let args = CommunityIdArgs(e)
self.delegate.communityLeft(args.communityId)
self.events.on(SIGNAL_COMMUNITY_EDITED) do(e:Args): self.events.on(SIGNAL_COMMUNITY_EDITED) do(e:Args):
let args = CommunityArgs(e) let args = CommunityArgs(e)
self.delegate.communityEdited(args.community) self.delegate.communityEdited(args.community)
@ -139,6 +143,9 @@ method storePassword*(self: Controller, password: string) =
self.keychainService.storePassword(account.name, password) self.keychainService.storePassword(account.name, password)
method getActiveSectionId*(self: Controller): string =
result = self.activeSectionId
method setActiveSection*(self: Controller, sectionId: string, sectionType: SectionType) = method setActiveSection*(self: Controller, sectionId: string, sectionType: SectionType) =
self.activeSectionId = sectionId self.activeSectionId = sectionId

View File

@ -24,6 +24,9 @@ method storePassword*(self: AccessInterface, password: string) {.base.} =
method setActiveSection*(self: AccessInterface, sectionId: string, sectionType: SectionType) {.base.} = method setActiveSection*(self: AccessInterface, sectionId: string, sectionType: SectionType) {.base.} =
raise newException(ValueError, "No implementation available") raise newException(ValueError, "No implementation available")
method getActiveSectionId*(self: AccessInterface): string {.base.} =
raise newException(ValueError, "No implementation available")
method getNumOfNotificaitonsForChat*(self: AccessInterface): tuple[unviewed:int, mentions:int] {.base.} = method getNumOfNotificaitonsForChat*(self: AccessInterface): tuple[unviewed:int, mentions:int] {.base.} =
raise newException(ValueError, "No implementation available") raise newException(ValueError, "No implementation available")

View File

@ -1,4 +1,4 @@
import NimQml, Tables, json, sugar, sequtils import NimQml, tables, json, sugar, sequtils
import io_interface, view, controller, ../shared_models/section_item, ../shared_models/section_model import io_interface, view, controller, ../shared_models/section_item, ../shared_models/section_model
import ../shared_models/member_item import ../shared_models/member_item
@ -494,9 +494,22 @@ method communityJoined*[T](
self.communitySectionsModule[community.id].load(events, settingsService, contactsService, chatService, communityService, messageService) self.communitySectionsModule[community.id].load(events, settingsService, contactsService, chatService, communityService, messageService)
let communitySectionItem = self.createCommunityItem(community) let communitySectionItem = self.createCommunityItem(community)
self.view.addItem(self.createCommunityItem(community)) self.view.addItem(communitySectionItem)
self.setActiveSection(communitySectionItem) self.setActiveSection(communitySectionItem)
method communityLeft*[T](self: Module[T], communityId: string) =
if(not self.communitySectionsModule.contains(communityId)):
echo "main-module, unexisting community key to leave: ", communityId
return
self.communitySectionsModule.del(communityId)
self.view.model().removeItem(communityId)
if (self.controller.getActiveSectionId() == communityId):
let item = self.view.model().getItemById(conf.CHAT_SECTION_ID)
self.setActiveSection(item)
method communityEdited*[T]( method communityEdited*[T](
self: Module[T], self: Module[T],
community: CommunityDto) = community: CommunityDto) =

View File

@ -26,5 +26,8 @@ method communityJoined*(self: AccessInterface, community: CommunityDto, events:
method communityEdited*(self: AccessInterface, community: CommunityDto) {.base.} = method communityEdited*(self: AccessInterface, community: CommunityDto) {.base.} =
raise newException(ValueError, "No implementation available") raise newException(ValueError, "No implementation available")
method communityLeft*(self: AccessInterface, communityId: string) {.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

@ -129,6 +129,20 @@ QtObject:
i.inc() i.inc()
return -1 return -1
proc removeItem*(self: SectionModel, itemId: string) =
let index = self.getItemIndex(itemId)
if (index == -1):
return
let parentModelIndex = newQModelIndex()
defer: parentModelIndex.delete
self.beginRemoveRows(parentModelIndex, index, index)
self.items.delete(index)
self.endRemoveRows()
self.countChanged()
proc editItem*(self: SectionModel, item: SectionItem) = proc editItem*(self: SectionModel, item: SectionItem) =
let index = self.getItemIndex(item.id) let index = self.getItemIndex(item.id)
if (index == -1): if (index == -1):

View File

@ -63,7 +63,7 @@ StatusModal {
onNotificationsButtonClicked: { onNotificationsButtonClicked: {
root.store.setCommunityMuted(root.community.id, checked); root.store.setCommunityMuted(root.community.id, checked);
} }
onEditButtonClicked: Global.openPopup(editCommunityPopup, { onEditButtonClicked: Global.openPopup(editCommunityroot, {
store: root.store, store: root.store,
community: root.community, community: root.community,
onSave: root.close onSave: root.close

View File

@ -157,8 +157,7 @@ QtObject {
} }
function leaveCommunity(communityId) { function leaveCommunity(communityId) {
// Not Refactored Yet communitiesModuleInst.leaveCommunity(communityId);
// chatsModelInst.communities.leaveCommunity(communityId);
} }
function setCommunityMuted(communityId, checked) { function setCommunityMuted(communityId, checked) {

View File

@ -42,17 +42,15 @@ QtObject {
} }
function leaveCommunity(communityId) { function leaveCommunity(communityId) {
// Not Refactored Yet communitiesModuleInst.leaveCommunity(communityId);
// chatsModelInst.communities.leaveCommunity(communityId);
} }
function createCommunity(communityName, communityDescription, checkedMembership, ensOnlySwitchChecked, communityColor, communityImage, imageCropperModalaX, imageCropperModalaY, imageCropperModalbX, imageCropperModalbY) { function createCommunity(communityName, communityDescription, checkedMembership, ensOnlySwitchChecked, communityColor, communityImage, imageCropperModalaX, imageCropperModalaY, imageCropperModalbX, imageCropperModalbY) {
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 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 copyToClipboard(text) { function copyToClipboard(text) {

View File

@ -286,8 +286,7 @@ Item {
icon.width: 14 icon.width: 14
iconRotation: 180 iconRotation: 180
type: StatusMenuItem.Type.Danger type: StatusMenuItem.Type.Danger
// Not Refactored Yet onTriggered: appMain.rootStore.leaveCommunity(model.id)
// onTriggered: chatsModel.communities.leaveCommunity(model.id)
} }
} }
} }