fix(userlist): member added to userlist on approve and duplicate member

Fixes #4523 and #4542
This commit is contained in:
Jonathan Rainville 2022-01-24 14:02:10 -05:00 committed by Sale Djenic
parent c20554d987
commit 518b7e455e
3 changed files with 29 additions and 10 deletions

View File

@ -42,7 +42,8 @@ proc newController*(delegate: io_interface.AccessInterface, events: EventEmitter
method delete*(self: Controller) =
discard
method init*(self: Controller) =
method init*(self: Controller) =
# TODO call this function again if isUsersListAvailable changes
if(self.isUsersListAvailable):
self.events.on(SIGNAL_MESSAGES_LOADED) do(e:Args):
let args = MessagesLoadedArgs(e)
@ -52,30 +53,36 @@ method init*(self: Controller) =
self.delegate.newMessagesLoaded(args.messages)
self.events.on(SIGNAL_CONTACT_NICKNAME_CHANGED) do(e: Args):
var args = ContactArgs(e)
let args = ContactArgs(e)
self.delegate.contactNicknameChanged(args.contactId)
self.events.on(SIGNAL_CONTACTS_STATUS_UPDATED) do(e: Args):
var args = ContactsStatusUpdatedArgs(e)
let args = ContactsStatusUpdatedArgs(e)
self.delegate.contactsStatusUpdated(args.statusUpdates)
self.events.on(SIGNAL_CONTACT_UPDATED) do(e: Args):
var args = ContactArgs(e)
let args = ContactArgs(e)
self.delegate.contactUpdated(args.contactId)
self.events.on(SIGNAL_LOGGEDIN_USER_IMAGE_CHANGED) do(e: Args):
self.delegate.loggedInUserImageChanged()
self.events.on(SIGNAL_CHAT_MEMBERS_ADDED) do(e: Args):
var args = ChatMembersAddedArgs(e)
let args = ChatMembersAddedArgs(e)
if (args.chatId == self.chatId):
self.delegate.onChatMembersAdded(args.ids)
self.events.on(SIGNAL_CHAT_MEMBER_REMOVED) do(e: Args):
var args = ChatMemberRemovedArgs(e)
let args = ChatMemberRemovedArgs(e)
if (args.chatId == self.chatId):
self.delegate.onChatMemberRemoved(args.id)
if (self.belongsToCommunity):
self.events.on(SIGNAL_COMMUNITY_MEMBER_APPROVED) do(e: Args):
let args = CommunityMemberArgs(e)
if (args.communityId == self.sectionId):
self.delegate.onChatMembersAdded(@[args.pubKey])
method getMembersPublicKeys*(self: Controller): seq[string] =
# in case of 1:1 chat, there is no a members list
if(not self.belongsToCommunity):

View File

@ -52,6 +52,8 @@ method viewDidLoad*(self: Module) =
# add other memebers
let usersKeys = self.controller.getMembersPublicKeys()
for k in usersKeys:
if (k == singletonInstance.userProfile.getPubKey()):
continue
let (name, image, isIdenticon) = self.controller.getContactNameAndImage(k)
let statusUpdateDto = self.controller.getStatusForContact(k)
let status = statusUpdateDto.statusType.int.OnlineStatus

View File

@ -46,6 +46,10 @@ type
category*: Category
channels*: seq[string]
CommunityMemberArgs* = ref object of Args
communityId*: string
pubKey*: string
# Signals which may be emitted by this service:
const SIGNAL_COMMUNITY_JOINED* = "communityJoined"
const SIGNAL_COMMUNITY_MY_REQUEST_ADDED* = "communityMyRequestAdded"
@ -60,6 +64,7 @@ const SIGNAL_COMMUNITY_CHANNEL_DELETED* = "communityChannelDeleted"
const SIGNAL_COMMUNITY_CATEGORY_CREATED* = "communityCategoryCreated"
const SIGNAL_COMMUNITY_CATEGORY_EDITED* = "communityCategoryEdited"
const SIGNAL_COMMUNITY_CATEGORY_DELETED* = "communityCategoryDeleted"
const SIGNAL_COMMUNITY_MEMBER_APPROVED* = "communityMemberApproved"
QtObject:
type
@ -646,13 +651,14 @@ QtObject:
i.inc()
return -1
proc removeMembershipRequestFromCommunity*(self: Service, communityId: string, requestId: string) =
proc removeMembershipRequestFromCommunityAndGetMemberPubkey*(self: Service, communityId: string, requestId: string): string =
let index = self.getPendingRequestIndex(communityId, requestId)
if (index == -1):
raise newException(RpcException, fmt"Community request not found: {requestId}")
var community = self.joinedCommunities[communityId]
result = community.pendingRequestsToJoin[index].publicKey
community.pendingRequestsToJoin.delete(index)
self.joinedCommunities[communityId] = community
@ -661,9 +667,13 @@ QtObject:
try:
discard status_go.acceptRequestToJoinCommunity(requestId)
self.removeMembershipRequestFromCommunity(communityId, requestId)
let newMemberPubkey = self.removeMembershipRequestFromCommunityAndGetMemberPubkey(communityId, requestId)
self.events.emit(SIGNAL_COMMUNITY_EDITED, CommunityArgs(community: self.joinedCommunities[communityId]))
if (newMemberPubkey == ""):
error "Did not find pubkey in the pending request"
return
self.events.emit(SIGNAL_COMMUNITY_MEMBER_APPROVED, CommunityMemberArgs(communityId: communityId, pubKey: newMemberPubkey))
except Exception as e:
error "Error accepting request to join community", msg = e.msg
@ -671,7 +681,7 @@ QtObject:
try:
discard status_go.declineRequestToJoinCommunity(requestId)
self.removeMembershipRequestFromCommunity(communityId, requestId)
discard self.removeMembershipRequestFromCommunityAndGetMemberPubkey(communityId, requestId)
self.events.emit(SIGNAL_COMMUNITY_EDITED, CommunityArgs(community: self.joinedCommunities[communityId]))
except Exception as e: