fix(communities): enable leaving and then re-joining a community

Fixes #4568
This commit is contained in:
Jonathan Rainville 2022-01-26 13:28:09 -05:00 committed by Sale Djenic
parent 9673c399e5
commit f7694e2915
5 changed files with 20 additions and 29 deletions

View File

@ -36,33 +36,10 @@ method init*(self: Controller) =
let args = CommunityArgs(e)
self.delegate.addCommunity(args.community)
self.events.on(SIGNAL_COMMUNITY_MY_REQUEST_ADDED) do(e:Args):
let args = CommunityRequestArgs(e)
# self.delegate.requestAdded()
self.events.on(SIGNAL_COMMUNITY_CHANNEL_EDITED) do(e:Args):
let args = CommunityChatArgs(e)
# self.delegate.communityChannelEdited()
self.events.on(SIGNAL_COMMUNITY_CHANNEL_REORDERED) do(e:Args):
let args = CommunityChatOrderArgs(e)
# self.delegate.communityChannelReordered()
self.events.on(SIGNAL_COMMUNITY_CHANNEL_DELETED) do(e:Args):
let args = CommunityChatIdArgs(e)
# self.delegate.communityChannelDeleted()
self.events.on(SIGNAL_COMMUNITY_CATEGORY_CREATED) do(e:Args):
let args = CommunityCategoryArgs(e)
# self.delegate.communityCategoryCreated()
self.events.on(SIGNAL_COMMUNITY_CATEGORY_EDITED) do(e:Args):
let args = CommunityCategoryArgs(e)
# self.delegate.communityCategoryEdited()
self.events.on(SIGNAL_COMMUNITY_CATEGORY_DELETED) do(e:Args):
let args = CommunityCategoryArgs(e)
# self.delegate.communityCategoryDeleted()
self.events.on(SIGNAL_COMMUNITIES_UPDATE) do(e:Args):
let args = CommunitiesArgs(e)
for community in args.communities:
self.delegate.communityEdited(community)
method getAllCommunities*(self: Controller): seq[CommunityDto] =
result = self.communityService.getAllCommunities()

View File

@ -4,7 +4,7 @@ import ./io_interface
import ../io_interface as delegate_interface
import ./view, ./controller
import ../../shared_models/section_item
import ../../shared_models/[user_item, user_model]
import ../../shared_models/[user_item, user_model, section_model]
import ../../../global/global_singleton
import ../../../core/eventemitter
import ../../../../app_service/service/community/service as community_service
@ -97,6 +97,9 @@ method addCommunity*(self: Module, community: CommunityDto) =
method joinCommunity*(self: Module, communityId: string): string =
self.controller.joinCommunity(communityId)
method communityEdited*(self: Module, community: CommunityDto) =
self.view.model().editItem(self.getCommunityItem(community))
method requestAdded*(self: Module) =
# TODO to model or view
discard

View File

@ -24,4 +24,7 @@ method communityCategoryEdited*(self: AccessInterface) {.base.} =
raise newException(ValueError, "No implementation available")
method communityCategoryDeleted*(self: AccessInterface) {.base.} =
raise newException(ValueError, "No implementation available")
method communityEdited*(self: AccessInterface, community: CommunityDto) {.base.} =
raise newException(ValueError, "No implementation available")

View File

@ -33,8 +33,11 @@ QtObject:
proc addItem*(self: View, item: SectionItem) =
self.model.addItem(item)
proc model*(self: View): SectionModel =
result = self.model
proc getModel(self: View): QVariant {.slot.} =
return newQVariant(self.modelVariant)
return self.modelVariant
QtProperty[QVariant] model:
read = getModel

View File

@ -364,6 +364,11 @@ QtObject:
error "error: ", methodName="leaveCommunity", errDesription = "result is nil"
return
# Update community so that joined, member list and isMember are updated
let updatedCommunity = response.result["communities"][0].toCommunityDto()
self.allCommunities[communityId] = updatedCommunity
self.events.emit(SIGNAL_COMMUNITIES_UPDATE, CommunitiesArgs(communities: @[updatedCommunity]))
# remove this from the joinedCommunities list
self.joinedCommunities.del(communityId)
self.events.emit(SIGNAL_COMMUNITY_LEFT, CommunityIdArgs(communityId: communityId))