fix(@desktop/community): do not create a separate community module after we join opened spectated community

This commit is contained in:
mprakhov 2023-01-31 17:24:06 +02:00 committed by Mykhailo Prakhov
parent b7c4c7b582
commit c2c9ede0f3
6 changed files with 37 additions and 15 deletions

View File

@ -57,3 +57,6 @@ method addGroupMembers*(self: AccessInterface, pubKeys: seq[string]) {.base.} =
method removeGroupMembers*(self: AccessInterface, pubKeys: seq[string]) {.base.} =
raise newException(ValueError, "No implementation available")
method updateMembersList*(self: AccessInterface) =
raise newException(ValueError, "No implementation available")

View File

@ -53,10 +53,7 @@ method isLoaded*(self: Module): bool =
return self.moduleLoaded
method viewDidLoad*(self: Module) =
let members = self.controller.getChatMembers()
for member in members:
self.addChatMember(member)
self.updateMembersList()
self.moduleLoaded = true
method getModuleAsVariant*(self: Module): QVariant =
@ -176,3 +173,8 @@ method addGroupMembers*(self: Module, pubKeys: seq[string]) =
method removeGroupMembers*(self: Module, pubKeys: seq[string]) =
self.controller.removeGroupMembers(pubKeys)
method updateMembersList*(self: Module) =
let members = self.controller.getChatMembers()
for member in members:
self.addChatMember(member)

View File

@ -325,3 +325,6 @@ method contactsStatusUpdated*(self: AccessInterface, statusUpdates: seq[StatusUp
method switchToChannel*(self: AccessInterface, channelName: string) =
raise newException(ValueError, "No implementation available")
method joinSpectatedCommunity*(self: AccessInterface) =
raise newException(ValueError, "No implementation available")

View File

@ -1017,3 +1017,7 @@ method contactsStatusUpdated*(self: Module, statusUpdates: seq[StatusUpdateDto])
for s in statusUpdates:
let status = toOnlineStatus(s.statusType)
self.view.chatsModel().updateItemOnlineStatusById(s.publicKey, status)
method joinSpectatedCommunity*(self: Module) =
if self.usersModule != nil:
self.usersModule.updateMembersList()

View File

@ -1,4 +1,4 @@
import NimQml, tables, json, sugar, sequtils, strformat, marshal, times
import NimQml, tables, json, sugar, sequtils, strformat, marshal, times, chronicles
import io_interface, view, controller, chat_search_item, chat_search_model
import ephemeral_notification_item, ephemeral_notification_model
@ -709,6 +709,24 @@ method communityJoined*[T](
var firstCommunityJoined = false
if (self.channelGroupModules.len == 1): # First one is personal chat section
firstCommunityJoined = true
if(community.permissions.access == COMMUNITY_PERMISSION_ACCESS_ON_REQUEST and
community.requestedToJoinAt > 0 and
community.joined):
singletonInstance.globalEvents.myRequestToJoinCommunityAcccepted("Community Request Accepted",
fmt "Your request to join community {community.name} is accepted", community.id)
self.displayEphemeralNotification(fmt "{community.name} membership approved ", "", conf.COMMUNITIESPORTAL_SECTION_ICON, false, EphemeralNotificationType.Success.int, "")
# if we are joining spectated community
if self.channelGroupModules.hasKey(community.id):
let communityModule = self.channelGroupModules[community.id]
# Must never happen
if not communityModule.isLoaded():
error "Community module was not loaded in spectated mode", communityId=community.id
communityModule.joinSpectatedCommunity()
return
self.channelGroupModules[community.id] = chat_section_module.newModule(
self,
events,
@ -735,13 +753,6 @@ method communityJoined*[T](
else:
self.view.model().addItem(communitySectionItem)
if(community.permissions.access == COMMUNITY_PERMISSION_ACCESS_ON_REQUEST and
community.requestedToJoinAt > 0 and
community.joined):
singletonInstance.globalEvents.myRequestToJoinCommunityAcccepted("Community Request Accepted",
fmt "Your request to join community {community.name} is accepted", community.id)
self.displayEphemeralNotification(fmt "{community.name} membership approved ", "", conf.COMMUNITIESPORTAL_SECTION_ICON, false, EphemeralNotificationType.Success.int, "")
if setActive:
self.setActiveSection(communitySectionItem)
if(channelGroup.chats.len > 0):

View File

@ -70,7 +70,6 @@ type
CommunityMembersArgs* = ref object of Args
communityId*: string
members*: seq[ChatMember]
isMember*: bool
CommunityMutedArgs* = ref object of Args
communityId*: string
@ -454,9 +453,9 @@ QtObject:
self.events.emit(SIGNAL_COMMUNITY_CHANNEL_EDITED, data)
# members list was changed
if community.members != prev_community.members:
if community.isMember and community.members != prev_community.members:
self.events.emit(SIGNAL_COMMUNITY_MEMBERS_CHANGED,
CommunityMembersArgs(communityId: community.id, members: community.members, isMember: community.isMember))
CommunityMembersArgs(communityId: community.id, members: community.members))
self.allCommunities[community.id] = community
self.events.emit(SIGNAL_COMMUNITIES_UPDATE, CommunitiesArgs(communities: @[community]))