fix(communities): fix invite link enabling joining twice

Fixes #4801
This commit is contained in:
Jonathan Rainville 2022-02-15 15:44:52 -05:00
parent 46467546a8
commit f27fd6ea61
1 changed files with 18 additions and 5 deletions

View File

@ -354,11 +354,23 @@ QtObject:
try:
if (not self.userCanJoin(communityId) or self.isUserMemberOfCommunity(communityId)):
return
discard status_go.joinCommunity(communityId)
var community = self.allCommunities[communityId]
self.joinedCommunities[communityId] = community
for k, chat in community.chats:
let response = status_go.joinCommunity(communityId)
if response.error != nil:
let error = Json.decode($response.error, RpcError)
raise newException(RpcException, "Error joining community: " & error.message)
if response.result == nil or response.result.kind == JNull:
error "error: ", methodName="joinCommunity", errDesription = "result is nil"
return
let updatedCommunity = response.result["communities"][0].toCommunityDto()
self.allCommunities[communityId] = updatedCommunity
self.joinedCommunities[communityId] = updatedCommunity
for k, chat in updatedCommunity.chats:
let fullChatId = communityId & chat.id
let currentChat = self.chatService.getChatById(fullChatId, showWarning = false)
echo currentChat
@ -370,7 +382,8 @@ QtObject:
# TODO find a way to populate missing infos like the color
self.chatService.updateOrAddChat(chatDto)
self.events.emit(SIGNAL_COMMUNITY_JOINED, CommunityArgs(community: community))
self.events.emit(SIGNAL_COMMUNITIES_UPDATE, CommunitiesArgs(communities: @[updatedCommunity]))
self.events.emit(SIGNAL_COMMUNITY_JOINED, CommunityArgs(community: updatedCommunity))
except Exception as e:
error "Error joining the community", msg = e.msg
result = fmt"Error joining the community: {e.msg}"