Skip to content

Commit

Permalink
WIP: fix muc handling on join
Browse files Browse the repository at this point in the history
  • Loading branch information
tmolitor-stud-tu committed Dec 14, 2023
1 parent 0c1bd76 commit 061d101
Showing 1 changed file with 30 additions and 18 deletions.
48 changes: 30 additions & 18 deletions Monal/Classes/MLMucProcessor.m
Original file line number Diff line number Diff line change
Expand Up @@ -388,6 +388,7 @@ -(void) handleStatusCodes:(XMPPStanza*) node
}
else
; //ignore other non-joining self-presences for now
break;
}
break;
}
Expand Down Expand Up @@ -471,14 +472,15 @@ -(void) handleStatusCodes:(XMPPStanza*) node
[_noUpdateBookmarks removeObject:node.fromUser];
}

if([[[DataLayer sharedInstance] getMucTypeOfRoom:node.fromUser andAccount:_account.accountNo] isEqualToString:@"group"])
DDLogInfo(@"Recorded members and participants of group %@: %@", node.fromUser, [[DataLayer sharedInstance] getMembersAndParticipantsOfMuc:node.fromUser forAccountId:_account.accountNo]);
else
[self logMembersOfMuc:node.fromUser];

//load members/admins/owners list (this has to be done *after* joining the muc to not get auth errors)
DDLogInfo(@"Querying member/admin/owner lists for muc %@...", node.fromUser);
for(NSString* type in @[@"member", @"admin", @"owner"])
{
//these lists can potentially get really long for public channels --> restrict logging them to alpha builds
#ifdef IS_ALPHA
DDLogInfo(@"Recorded members and participants of channel %@: %@", node.fromUser, [[DataLayer sharedInstance] getMembersAndParticipantsOfMuc:node.fromUser forAccountId:_account.accountNo]);
#endif
XMPPIQ* discoInfo = [[XMPPIQ alloc] initWithType:kiqGetType to:node.fromUser];
[discoInfo setMucListQueryFor:type];
[_account sendIq:discoInfo withHandler:$newHandler(self, handleMembersList, $ID(type))];
}

monal_id_block_t uiHandler = [self getUIHandlerForMuc:node.fromUser];
Expand Down Expand Up @@ -819,8 +821,13 @@ -(void) publishAvatar:(UIImage*) image forMuc:(NSString*) room
if(![[DataLayer sharedInstance] isBuddyMuc:iqNode.fromUser forAccount:_account.accountNo])
{
//remove old non-muc contact from contactlist (we don't want mucs as normal contacts on our (server) roster and shadowed in monal by the real muc contact)
if([[DataLayer sharedInstance] contactDictionaryForUsername:iqNode.fromUser forAccount:_account.accountNo] != nil)
[_account removeFromRoster:[MLContact createContactFromJid:iqNode.fromUser andAccountNo:_account.accountNo]];
NSDictionary* existingContactDict = [[DataLayer sharedInstance] contactDictionaryForUsername:iqNode.fromUser forAccount:_account.accountNo];
if(existingContactDict != nil)
{
MLContact* existingContact = [MLContact createContactFromJid:iqNode.fromUser andAccountNo:_account.accountNo];
DDLogVerbose(@"Removing already existing contact (%@) having raw db dict: %@", existingContact, existingContactDict);
[_account removeFromRoster:existingContact];
}
//add new muc buddy (potentially deleting a non-muc buddy having the same jid)
NSString* nick = [self calculateNickForMuc:iqNode.fromUser];
DDLogInfo(@"Adding new muc %@ using nick '%@' to buddylist...", iqNode.fromUser, nick);
Expand Down Expand Up @@ -869,15 +876,6 @@ -(void) publishAvatar:(UIImage*) image forMuc:(NSString*) room

//now try to join this room if requested
[self sendJoinPresenceFor:iqNode.fromUser];

//load members/admins/owners list (this has to be done *after* joining the muc to not get auth errors)
DDLogInfo(@"Querying members/admin/owner lists for muc %@...", iqNode.fromUser);
for(NSString* type in @[@"member", @"admin", @"owner"])
{
XMPPIQ* discoInfo = [[XMPPIQ alloc] initWithType:kiqGetType to:iqNode.fromUser];
[discoInfo setMucListQueryFor:type];
[_account sendIq:discoInfo withHandler:$newHandler(self, handleMembersList, $ID(type))];
}
}
$$

Expand Down Expand Up @@ -908,6 +906,7 @@ -(void) sendJoinPresenceFor:(NSString*) room
$$instance_handler(handleMembersList, account.mucProcessor, $$ID(xmpp*, account), $$ID(XMPPIQ*, iqNode), $$ID(NSString*, type))
DDLogInfo(@"Got %@s list from %@...", type, iqNode.fromUser);
[self handleMembersListUpdate:iqNode];
[self logMembersOfMuc:iqNode.fromUser];
$$

$$instance_handler(handleMamResponseWithLatestId, account.mucProcessor, $$ID(xmpp*, account), $$ID(XMPPIQ*, iqNode))
Expand Down Expand Up @@ -1148,4 +1147,17 @@ -(void) removeRoomFromJoining:(NSString*) room
}
}

-(void) logMembersOfMuc:(NSString*) jid
{
if([[[DataLayer sharedInstance] getMucTypeOfRoom:jid andAccount:_account.accountNo] isEqualToString:@"group"])
DDLogInfo(@"Currently recorded members and participants of group %@: %@", jid, [[DataLayer sharedInstance] getMembersAndParticipantsOfMuc:jid forAccountId:_account.accountNo]);
else
{
//these lists can potentially get really long for public channels --> restrict logging them to alpha builds
#ifdef IS_ALPHA
DDLogInfo(@"Currently recorded members and participants of channel %@: %@", jid, [[DataLayer sharedInstance] getMembersAndParticipantsOfMuc:jid forAccountId:_account.accountNo]);
#endif
}
}

@end

0 comments on commit 061d101

Please sign in to comment.