diff --git a/Vector/ViewController/RoomParticipantsViewController.m b/Vector/ViewController/RoomParticipantsViewController.m index 9463cb01d..7d5a6d19a 100644 --- a/Vector/ViewController/RoomParticipantsViewController.m +++ b/Vector/ViewController/RoomParticipantsViewController.m @@ -323,14 +323,12 @@ - (void)addRoomMemberToParticipants:(MXRoomMember*)mxMember { // Remove previous occurrence of this member (if any) - if (mutableParticipants.count) + [self removeParticipantByKey:mxMember.userId]; + + // If any, remove 3pid invite corresponding to this room member + if (mxMember.thirdPartyInviteToken) { - NSUInteger index = [mutableParticipants indexOfObject:mxMember.userId]; - if (index != NSNotFound) - { - [mxkContactsById removeObjectForKey:mxMember.userId]; - [mutableParticipants removeObjectAtIndex:index]; - } + [self removeParticipantByKey:mxMember.thirdPartyInviteToken]; } // Add this member after checking his status @@ -370,10 +368,14 @@ - (void)addRoomRoomThirdPartyInviteToParticipants:(MXRoomThirdPartyInvite*)roomThirdPartyInvite { - Contact *contact = [[Contact alloc] initMatrixContactWithDisplayName:roomThirdPartyInvite.displayname andMatrixID:nil]; - mxkContactsById[roomThirdPartyInvite.token] = contact; + // If the homeserver has converted the 3pid invite into a room member, do no show it + if (![self.mxRoom.state memberWithThirdPartyInviteToken:roomThirdPartyInvite.token]) + { + Contact *contact = [[Contact alloc] initMatrixContactWithDisplayName:roomThirdPartyInvite.displayname andMatrixID:nil]; + mxkContactsById[roomThirdPartyInvite.token] = contact; - [self addContactToParticipants:contact withKey:roomThirdPartyInvite.token isAdmin:NO]; + [self addContactToParticipants:contact withKey:roomThirdPartyInvite.token isAdmin:NO]; + } } - (void)addContactToParticipants:(Contact*)theContact withKey:(NSString*)key isAdmin:(BOOL)isAdmin @@ -445,6 +447,20 @@ [mutableParticipants insertObject:key atIndex:index]; } +// key is a room member user id or a room 3pid invite token +- (void)removeParticipantByKey:(NSString*)key +{ + if (mutableParticipants.count) + { + NSUInteger index = [mutableParticipants indexOfObject:key]; + if (index != NSNotFound) + { + [mxkContactsById removeObjectForKey:key]; + [mutableParticipants removeObjectAtIndex:index]; + } + } +} + - (void)addPendingActionMask { // Add a spinner above the tableview to avoid that the user tap on any other button