Revision 80684e32 ChatSecure/Classes/Controllers/XMPP/OTRXMPPRoomManager.m
ChatSecure/Classes/Controllers/XMPP/OTRXMPPRoomManager.m | ||
---|---|---|
80 | 80 |
NSString* accountId = self.xmppStream.tag; |
81 | 81 |
NSString *databaseRoomKey = [OTRXMPPRoom createUniqueId:accountId jid:jid.bare]; |
82 | 82 |
__block NSString *nickname = name; |
83 |
|
|
84 |
// Already joined? Can happen if we have auto-join bookmarks. |
|
85 |
if (room && room.isJoined) { |
|
86 |
return databaseRoomKey; |
|
87 |
} |
|
88 | 83 |
|
89 | 84 |
if (!room) { |
90 | 85 |
OTRXMPPRoomYapStorage *storage = [[OTRXMPPRoomYapStorage alloc] initWithDatabaseConnection:self.databaseConnection]; |
... | ... | |
361 | 356 |
|
362 | 357 |
- (void) xmppRoom:(XMPPRoom *)room didFetchMembersList:(NSArray<NSXMLElement*> *)items { |
363 | 358 |
DDLogInfo(@"Fetched members list: %@", items); |
364 |
[self xmppRoom:room addOccupantItems:items]; |
|
365 |
} |
|
366 |
|
|
367 |
- (void)xmppRoom:(XMPPRoom *)room didFetchModeratorsList:(NSArray *)items { |
|
368 |
DDLogInfo(@"Fetched moderators list: %@", items); |
|
369 |
[self xmppRoom:room addOccupantItems:items]; |
|
370 |
} |
|
371 |
|
|
372 |
- (void) xmppRoom:(XMPPRoom *)room addOccupantItems:(NSArray<NSXMLElement*> *)items { |
|
373 | 359 |
NSString *accountId = room.xmppStream.tag; |
374 | 360 |
[self.databaseConnection asyncReadWriteWithBlock:^(YapDatabaseReadWriteTransaction * _Nonnull transaction) { |
375 | 361 |
[items enumerateObjectsUsingBlock:^(NSXMLElement *item, NSUInteger idx, BOOL * _Nonnull stop) { |
376 | 362 |
NSString *jidString = [item attributeStringValueForName:@"jid"]; |
377 | 363 |
XMPPJID *jid = [XMPPJID jidWithString:jidString]; |
378 |
NSString *affiliation = [item attributeStringValueForName:@"affiliation"]; |
|
379 |
|
|
380 |
// jid and affiliation MUST be included |
|
381 |
if (!jid || !affiliation) { return; } |
|
382 |
|
|
364 |
if (!jid) { return; } |
|
383 | 365 |
// Make sure occupant object exists/is created |
384 | 366 |
OTRXMPPRoomOccupant *occupant = [OTRXMPPRoomOccupant occupantWithJid:jid realJID:jid roomJID:room.roomJID accountId:accountId createIfNeeded:YES transaction:transaction]; |
385 |
occupant.affiliation = [RoomOccupantAffiliationHelper affiliationWithString:affiliation]; |
|
386 |
|
|
387 |
// Role MAY be included, so get that if it's there |
|
388 |
NSString *role = [item attributeStringValueForName:@"role"]; |
|
389 |
if (role) { |
|
390 |
occupant.role = [RoomOccupantRoleHelper roleWithString:role]; |
|
391 |
} |
|
392 |
|
|
393 | 367 |
[occupant saveWithTransaction:transaction]; |
394 | 368 |
}]; |
395 | 369 |
}]; |
396 | 370 |
} |
397 | 371 |
|
398 |
- (void)xmppRoomDidCreate:(XMPPRoom *)sender { |
|
399 |
[self.roomsToConfigure removeObject:sender.roomJID.bare]; |
|
400 |
[sender fetchConfigurationForm]; |
|
401 |
} |
|
402 |
|
|
403 |
- (void)xmppRoom:(XMPPRoom *)sender didFetchConfigurationForm:(DDXMLElement *)configForm { |
|
404 |
[sender configureRoomUsingOptions:[[self class] defaultRoomConfiguration]]; |
|
405 |
} |
|
406 |
|
|
407 |
- (void)xmppRoom:(XMPPRoom *)sender didConfigure:(XMPPIQ *)iqResult { |
|
408 |
//Set Room Subject |
|
409 |
NSString *subject = [self.tempRoomSubject objectForKey:sender.roomJID.bare]; |
|
410 |
if (subject) { |
|
411 |
[self.tempRoomSubject removeObjectForKey:sender.roomJID.bare]; |
|
412 |
[sender changeRoomSubject:subject]; |
|
413 |
} |
|
414 |
|
|
415 |
//Invite buddies |
|
416 |
NSArray<NSString*> *buddyUniqueIds = [self.inviteDictionary objectForKey:sender.roomJID.bare]; |
|
417 |
if (buddyUniqueIds) { |
|
418 |
[self.inviteDictionary removeObjectForKey:sender.roomJID.bare]; |
|
419 |
[self inviteBuddies:buddyUniqueIds toRoom:sender]; |
|
420 |
} |
|
421 |
|
|
422 |
// Fetch member list. Ideally this would be done after the invites above have been sent to the network, but the messages pass all kinds of async delegates before they are actually sent, so unfortunately we can't wait for that. |
|
423 |
[self performBlockAsync:^{ |
|
424 |
[sender fetchMembersList]; |
|
425 |
[sender fetchModeratorsList]; |
|
426 |
}]; |
|
427 |
} |
|
428 |
|
|
429 | 372 |
- (void)xmppRoomDidJoin:(XMPPRoom *)sender |
430 | 373 |
{ |
431 |
// Older prosody servers have a bug where they consider all room as already |
|
432 |
// existing, so the status 201 is never sent. |
|
433 |
if ([self.roomsToConfigure containsObject:sender.roomJID.bare]) { |
|
434 |
[self xmppRoomDidCreate:sender]; |
|
435 |
} else { |
|
436 |
// Fetch member list |
|
437 |
[self performBlockAsync:^{ |
|
438 |
[sender fetchMembersList]; |
|
439 |
[sender fetchModeratorsList]; |
|
440 |
}]; |
|
441 |
} |
|
374 |
[self performBlockAsync:^{ |
|
375 |
//Configure room if we are the creator |
|
376 |
if ([self.roomsToConfigure containsObject:sender.roomJID.bare]) { |
|
377 |
[self.roomsToConfigure removeObject:sender.roomJID.bare]; |
|
378 |
[sender configureRoomUsingOptions:[[self class] defaultRoomConfiguration]]; |
|
379 |
|
|
380 |
//Set Room Subject |
|
381 |
NSString *subject = [self.tempRoomSubject objectForKey:sender.roomJID.bare]; |
|
382 |
if (subject) { |
|
383 |
[self.tempRoomSubject removeObjectForKey:sender.roomJID.bare]; |
|
384 |
[sender changeRoomSubject:subject]; |
|
385 |
} |
|
386 |
} |
|
387 |
|
|
388 |
//Invite buddies |
|
389 |
NSArray<NSString*> *buddyUniqueIds = [self.inviteDictionary objectForKey:sender.roomJID.bare]; |
|
390 |
if (buddyUniqueIds) { |
|
391 |
[self.inviteDictionary removeObjectForKey:sender.roomJID.bare]; |
|
392 |
[self inviteBuddies:buddyUniqueIds toRoom:sender]; |
|
393 |
} |
|
394 |
|
|
395 |
//Fetch member list |
|
396 |
[sender fetchMembersList]; |
|
397 |
}]; |
|
442 | 398 |
} |
443 | 399 |
|
444 | 400 |
- (void)xmppRoomDidLeave:(XMPPRoom *)sender { |
Also available in: Unified diff