2020-10-14 17:18:58 +03:00
|
|
|
/**
|
|
|
|
* @copyright Copyright (c) 2020 Ivan Sein <ivan@nextcloud.com>
|
|
|
|
*
|
|
|
|
* @author Ivan Sein <ivan@nextcloud.com>
|
|
|
|
*
|
|
|
|
* @license GNU GPL version 3 or any later version
|
|
|
|
*
|
|
|
|
* This program is free software: you can redistribute it and/or modify
|
|
|
|
* it under the terms of the GNU General Public License as published by
|
|
|
|
* the Free Software Foundation, either version 3 of the License, or
|
|
|
|
* (at your option) any later version.
|
|
|
|
*
|
|
|
|
* This program is distributed in the hope that it will be useful,
|
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
* GNU General Public License for more details.
|
|
|
|
*
|
|
|
|
* You should have received a copy of the GNU General Public License
|
|
|
|
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
|
|
|
*
|
|
|
|
*/
|
2018-05-14 17:59:27 +03:00
|
|
|
|
|
|
|
#import "NCRoomsManager.h"
|
|
|
|
|
2020-02-17 18:27:14 +03:00
|
|
|
#import <Realm/Realm.h>
|
|
|
|
|
2018-05-23 19:53:43 +03:00
|
|
|
#import "NCChatViewController.h"
|
2018-11-29 23:48:06 +03:00
|
|
|
#import "NewRoomTableViewController.h"
|
2018-06-20 13:55:49 +03:00
|
|
|
#import "RoomCreation2TableViewController.h"
|
2018-05-14 17:59:27 +03:00
|
|
|
#import "NCAPIController.h"
|
2019-06-16 21:21:50 +03:00
|
|
|
#import "NCDatabaseManager.h"
|
2018-05-14 17:59:27 +03:00
|
|
|
#import "NCChatMessage.h"
|
2018-09-13 17:12:01 +03:00
|
|
|
#import "NCExternalSignalingController.h"
|
2020-03-09 23:51:48 +03:00
|
|
|
#import "NCChatController.h"
|
2018-05-14 17:59:27 +03:00
|
|
|
#import "NCSettingsController.h"
|
|
|
|
#import "NCUserInterfaceController.h"
|
2019-01-18 18:10:31 +03:00
|
|
|
#import "CallKitManager.h"
|
2018-05-14 17:59:27 +03:00
|
|
|
|
|
|
|
NSString * const NCRoomsManagerDidJoinRoomNotification = @"NCRoomsManagerDidJoinRoomNotification";
|
|
|
|
NSString * const NCRoomsManagerDidLeaveRoomNotification = @"NCRoomsManagerDidLeaveRoomNotification";
|
2018-05-23 19:53:43 +03:00
|
|
|
NSString * const NCRoomsManagerDidUpdateRoomsNotification = @"NCRoomsManagerDidUpdateRoomsNotification";
|
2018-07-30 12:54:05 +03:00
|
|
|
NSString * const NCRoomsManagerDidUpdateRoomNotification = @"NCRoomsManagerDidUpdateRoomNotification";
|
2018-05-14 17:59:27 +03:00
|
|
|
NSString * const NCRoomsManagerDidStartCallNotification = @"NCRoomsManagerDidStartCallNotification";
|
|
|
|
NSString * const NCRoomsManagerDidReceiveChatMessagesNotification = @"ChatMessagesReceivedNotification";
|
|
|
|
|
2018-05-24 17:19:04 +03:00
|
|
|
@interface NCRoomsManager () <CallViewControllerDelegate>
|
2018-05-14 17:59:27 +03:00
|
|
|
|
2018-05-23 19:53:43 +03:00
|
|
|
@property (nonatomic, strong) NSMutableDictionary *activeRooms; //roomToken -> roomController
|
2018-08-14 17:25:48 +03:00
|
|
|
@property (nonatomic, strong) NSString *joiningRoom;
|
|
|
|
@property (nonatomic, strong) NSURLSessionTask *joinRoomTask;
|
2020-07-14 20:34:26 +03:00
|
|
|
@property (nonatomic, strong) NSURLSessionTask *leaveRoomTask;
|
2019-07-10 19:17:22 +03:00
|
|
|
@property (nonatomic, strong) NSMutableDictionary *joinRoomAttempts; //roomToken -> attempts
|
2019-05-20 14:12:06 +03:00
|
|
|
@property (nonatomic, strong) NSString *upgradeCallToken;
|
2020-07-14 20:34:26 +03:00
|
|
|
@property (nonatomic, strong) NSString *pendingToStartCallToken;
|
2018-05-14 17:59:27 +03:00
|
|
|
|
|
|
|
@end
|
|
|
|
|
2020-03-09 23:51:48 +03:00
|
|
|
@implementation NCRoomController
|
|
|
|
@end
|
|
|
|
|
2018-05-14 17:59:27 +03:00
|
|
|
@implementation NCRoomsManager
|
|
|
|
|
|
|
|
+ (NCRoomsManager *)sharedInstance
|
|
|
|
{
|
|
|
|
static dispatch_once_t once;
|
|
|
|
static NCRoomsManager *sharedInstance;
|
|
|
|
dispatch_once(&once, ^{
|
|
|
|
sharedInstance = [[self alloc] init];
|
|
|
|
});
|
|
|
|
return sharedInstance;
|
|
|
|
}
|
|
|
|
|
|
|
|
- (id)init
|
|
|
|
{
|
|
|
|
self = [super init];
|
|
|
|
if (self) {
|
2018-05-23 19:53:43 +03:00
|
|
|
_activeRooms = [[NSMutableDictionary alloc] init];
|
2019-07-10 19:17:22 +03:00
|
|
|
_joinRoomAttempts = [[NSMutableDictionary alloc] init];
|
2018-05-23 19:53:43 +03:00
|
|
|
|
2019-02-08 16:17:34 +03:00
|
|
|
[[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(joinChatWithLocalNotification:) name:NCLocalNotificationJoinChatNotification object:nil];
|
2018-05-24 15:27:12 +03:00
|
|
|
[[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(joinChat:) name:NCPushNotificationJoinChatNotification object:nil];
|
2018-05-23 19:53:43 +03:00
|
|
|
[[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(joinAudioCallAccepted:) name:NCPushNotificationJoinAudioCallAcceptedNotification object:nil];
|
|
|
|
[[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(joinVideoCallAccepted:) name:NCPushNotificationJoinVideoCallAcceptedNotification object:nil];
|
|
|
|
[[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(userSelectedContactForChat:) name:NCSelectedContactForChatNotification object:nil];
|
2018-06-20 13:55:49 +03:00
|
|
|
[[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(roomCreated:) name:NCRoomCreatedNotification object:nil];
|
2019-01-18 18:10:31 +03:00
|
|
|
[[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(acceptCallForRoom:) name:CallKitManagerDidAnswerCallNotification object:nil];
|
2019-02-01 17:01:02 +03:00
|
|
|
[[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(startCallForRoom:) name:CallKitManagerDidStartCallNotification object:nil];
|
2019-05-20 14:12:06 +03:00
|
|
|
[[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(checkForCallUpgrades:) name:CallKitManagerDidEndCallNotification object:nil];
|
2018-05-14 17:59:27 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
return self;
|
|
|
|
}
|
|
|
|
|
2018-05-23 19:53:43 +03:00
|
|
|
- (void)dealloc
|
|
|
|
{
|
|
|
|
[[NSNotificationCenter defaultCenter] removeObserver:self];
|
|
|
|
}
|
|
|
|
|
|
|
|
#pragma mark - Room
|
|
|
|
|
2019-04-11 16:34:20 +03:00
|
|
|
- (void)joinRoom:(NSString *)token forCall:(BOOL)call
|
2018-05-14 17:59:27 +03:00
|
|
|
{
|
2018-05-24 11:56:16 +03:00
|
|
|
NSMutableDictionary *userInfo = [NSMutableDictionary new];
|
2019-04-11 16:34:20 +03:00
|
|
|
NCRoomController *roomController = [_activeRooms objectForKey:token];
|
2020-03-06 21:39:59 +03:00
|
|
|
TalkAccount *activeAccount = [[NCDatabaseManager sharedInstance] activeAccount];
|
2018-05-23 19:53:43 +03:00
|
|
|
if (!roomController) {
|
2019-04-11 16:34:20 +03:00
|
|
|
_joiningRoom = token;
|
2020-03-06 21:39:59 +03:00
|
|
|
_joinRoomTask = [[NCAPIController sharedInstance] joinRoom:token forAccount:activeAccount withCompletionBlock:^(NSString *sessionId, NSError *error, NSInteger statusCode) {
|
2019-09-17 19:16:35 +03:00
|
|
|
if (!_joiningRoom) {
|
|
|
|
NSLog(@"Not joining the room any more. Ignore response.");
|
|
|
|
return;
|
|
|
|
}
|
2018-05-23 19:53:43 +03:00
|
|
|
if (!error) {
|
2020-03-09 23:51:48 +03:00
|
|
|
NCRoomController *controller = [[NCRoomController alloc] init];
|
2020-03-17 14:08:03 +03:00
|
|
|
controller.userSessionId = sessionId;
|
2018-05-25 13:41:46 +03:00
|
|
|
controller.inChat = !call;
|
|
|
|
controller.inCall = call;
|
2019-04-11 16:34:20 +03:00
|
|
|
[_activeRooms setObject:controller forKey:token];
|
2019-07-10 19:17:22 +03:00
|
|
|
[_joinRoomAttempts removeObjectForKey:token];
|
2018-05-24 11:56:16 +03:00
|
|
|
[userInfo setObject:controller forKey:@"roomController"];
|
2020-02-28 19:21:58 +03:00
|
|
|
NCExternalSignalingController *extSignalingController = [[NCSettingsController sharedInstance] externalSignalingControllerForAccountId:activeAccount.accountId];
|
2019-11-14 12:24:21 +03:00
|
|
|
if ([extSignalingController isEnabled]) {
|
|
|
|
[extSignalingController joinRoom:token withSessionId:sessionId];
|
2018-09-13 17:12:01 +03:00
|
|
|
}
|
2018-05-23 19:53:43 +03:00
|
|
|
} else {
|
2019-07-10 19:17:22 +03:00
|
|
|
NSInteger joinAttempts = [[_joinRoomAttempts objectForKey:token] integerValue];
|
|
|
|
if (joinAttempts < 3) {
|
|
|
|
NSLog(@"Error joining room, retrying. %ld", (long)joinAttempts);
|
|
|
|
joinAttempts += 1;
|
|
|
|
[_joinRoomAttempts setObject:@(joinAttempts) forKey:token];
|
|
|
|
[self joinRoom:token forCall:call];
|
|
|
|
return;
|
|
|
|
}
|
2018-05-23 19:53:43 +03:00
|
|
|
[userInfo setObject:error forKey:@"error"];
|
2019-07-05 15:37:59 +03:00
|
|
|
[userInfo setObject:@(statusCode) forKey:@"statusCode"];
|
|
|
|
NSLog(@"Could not join room. Status code: %ld. Error: %@", (long)statusCode, error.description);
|
2018-05-23 19:53:43 +03:00
|
|
|
}
|
2018-08-14 17:25:48 +03:00
|
|
|
_joiningRoom = nil;
|
2019-07-10 19:17:22 +03:00
|
|
|
[userInfo setObject:token forKey:@"token"];
|
2018-05-23 19:53:43 +03:00
|
|
|
[[NSNotificationCenter defaultCenter] postNotificationName:NCRoomsManagerDidJoinRoomNotification
|
|
|
|
object:self
|
|
|
|
userInfo:userInfo];
|
|
|
|
}];
|
2018-05-24 11:56:16 +03:00
|
|
|
} else {
|
2018-05-25 13:41:46 +03:00
|
|
|
if (call) {
|
|
|
|
roomController.inCall = YES;
|
|
|
|
} else {
|
|
|
|
roomController.inChat = YES;
|
|
|
|
}
|
2019-07-11 12:10:47 +03:00
|
|
|
[userInfo setObject:token forKey:@"token"];
|
2018-05-24 11:56:16 +03:00
|
|
|
[userInfo setObject:roomController forKey:@"roomController"];
|
|
|
|
[[NSNotificationCenter defaultCenter] postNotificationName:NCRoomsManagerDidJoinRoomNotification
|
|
|
|
object:self
|
|
|
|
userInfo:userInfo];
|
2018-05-23 19:53:43 +03:00
|
|
|
}
|
2018-05-14 17:59:27 +03:00
|
|
|
}
|
|
|
|
|
2019-04-11 16:34:20 +03:00
|
|
|
- (void)joinRoom:(NSString *)token
|
|
|
|
{
|
|
|
|
[self joinRoom:token forCall:NO];
|
|
|
|
}
|
|
|
|
|
2019-01-31 16:18:11 +03:00
|
|
|
- (void)rejoinRoom:(NSString *)token
|
|
|
|
{
|
|
|
|
NCRoomController *roomController = [_activeRooms objectForKey:token];
|
2020-03-09 23:51:48 +03:00
|
|
|
TalkAccount *activeAccount = [[NCDatabaseManager sharedInstance] activeAccount];
|
2019-01-31 16:18:11 +03:00
|
|
|
if (roomController) {
|
|
|
|
_joiningRoom = [token copy];
|
2020-03-09 23:51:48 +03:00
|
|
|
_joinRoomTask = [[NCAPIController sharedInstance] joinRoom:token forAccount:activeAccount withCompletionBlock:^(NSString *sessionId, NSError *error, NSInteger statusCode) {
|
2019-01-31 16:18:11 +03:00
|
|
|
if (!error) {
|
|
|
|
roomController.userSessionId = sessionId;
|
|
|
|
roomController.inChat = YES;
|
2020-02-28 19:21:58 +03:00
|
|
|
NCExternalSignalingController *extSignalingController = [[NCSettingsController sharedInstance] externalSignalingControllerForAccountId:activeAccount.accountId];
|
2019-11-14 12:24:21 +03:00
|
|
|
if ([extSignalingController isEnabled]) {
|
|
|
|
[extSignalingController joinRoom:token withSessionId:sessionId];
|
2019-01-31 16:18:11 +03:00
|
|
|
}
|
|
|
|
} else {
|
2019-07-05 15:37:59 +03:00
|
|
|
NSLog(@"Could not re-join room. Status code: %ld. Error: %@", (long)statusCode, error.description);
|
2019-01-31 16:18:11 +03:00
|
|
|
}
|
|
|
|
_joiningRoom = nil;
|
|
|
|
}];
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2018-10-12 20:33:14 +03:00
|
|
|
- (void)leaveRoom:(NSString *)token
|
2018-05-14 17:59:27 +03:00
|
|
|
{
|
2018-08-14 17:25:48 +03:00
|
|
|
// Check if leaving the room we are joining
|
2018-10-12 20:33:14 +03:00
|
|
|
if ([_joiningRoom isEqualToString:token]) {
|
2018-08-14 17:25:48 +03:00
|
|
|
_joiningRoom = nil;
|
|
|
|
[_joinRoomTask cancel];
|
|
|
|
}
|
|
|
|
|
2020-03-09 23:51:48 +03:00
|
|
|
TalkAccount *activeAccount = [[NCDatabaseManager sharedInstance] activeAccount];
|
2020-03-12 20:58:22 +03:00
|
|
|
// Remove room controller and exit room
|
2018-10-12 20:33:14 +03:00
|
|
|
NCRoomController *roomController = [_activeRooms objectForKey:token];
|
2018-05-25 13:41:46 +03:00
|
|
|
if (roomController && !roomController.inCall && !roomController.inChat) {
|
2018-10-12 20:33:14 +03:00
|
|
|
[_activeRooms removeObjectForKey:token];
|
2020-07-14 20:34:26 +03:00
|
|
|
_leaveRoomTask = [[NCAPIController sharedInstance] exitRoom:token forAccount:activeAccount withCompletionBlock:^(NSError *error) {
|
2018-06-07 15:57:27 +03:00
|
|
|
NSMutableDictionary *userInfo = [NSMutableDictionary new];
|
2018-09-13 17:12:01 +03:00
|
|
|
if (!error) {
|
2020-02-28 19:21:58 +03:00
|
|
|
NCExternalSignalingController *extSignalingController = [[NCSettingsController sharedInstance] externalSignalingControllerForAccountId:activeAccount.accountId];
|
2019-11-14 12:24:21 +03:00
|
|
|
if ([extSignalingController isEnabled]) {
|
|
|
|
[extSignalingController leaveRoom:token];
|
2018-09-13 17:12:01 +03:00
|
|
|
}
|
|
|
|
} else {
|
2018-06-07 15:57:27 +03:00
|
|
|
[userInfo setObject:error forKey:@"error"];
|
|
|
|
NSLog(@"Could not exit room. Error: %@", error.description);
|
|
|
|
}
|
2020-07-14 20:34:26 +03:00
|
|
|
_leaveRoomTask = nil;
|
|
|
|
[self checkForPendingToStartCalls];
|
2018-06-07 15:57:27 +03:00
|
|
|
[[NSNotificationCenter defaultCenter] postNotificationName:NCRoomsManagerDidLeaveRoomNotification
|
|
|
|
object:self
|
|
|
|
userInfo:userInfo];
|
|
|
|
}];
|
2020-07-14 20:34:26 +03:00
|
|
|
} else {
|
|
|
|
[self checkForPendingToStartCalls];
|
2018-05-23 19:53:43 +03:00
|
|
|
}
|
2018-05-14 17:59:27 +03:00
|
|
|
}
|
|
|
|
|
2020-07-21 18:53:17 +03:00
|
|
|
- (NSArray *)roomsForAccountId:(NSString *)accountId witRealm:(RLMRealm *)realm
|
2020-02-17 18:27:14 +03:00
|
|
|
{
|
|
|
|
NSPredicate *query = [NSPredicate predicateWithFormat:@"accountId = %@", accountId];
|
2020-07-21 18:53:17 +03:00
|
|
|
RLMResults *managedRooms = nil;
|
|
|
|
if (realm) {
|
|
|
|
managedRooms = [NCRoom objectsInRealm:realm withPredicate:query];
|
|
|
|
} else {
|
|
|
|
managedRooms = [NCRoom objectsWithPredicate:query];
|
|
|
|
}
|
2020-02-27 18:33:50 +03:00
|
|
|
// Create an unmanaged copy of the rooms
|
|
|
|
NSMutableArray *unmanagedRooms = [NSMutableArray new];
|
|
|
|
for (NCRoom *managedRoom in managedRooms) {
|
2020-03-04 18:41:29 +03:00
|
|
|
NCRoom *unmanagedRoom = [[NCRoom alloc] initWithValue:managedRoom];
|
2020-02-27 18:33:50 +03:00
|
|
|
[unmanagedRooms addObject:unmanagedRoom];
|
2020-02-17 18:27:14 +03:00
|
|
|
}
|
|
|
|
// Sort by favorites
|
|
|
|
NSSortDescriptor *favoriteSorting = [NSSortDescriptor sortDescriptorWithKey:@"" ascending:YES comparator:^NSComparisonResult(id _Nonnull obj1, id _Nonnull obj2) {
|
|
|
|
NCRoom *first = (NCRoom*)obj1;
|
|
|
|
NCRoom *second = (NCRoom*)obj2;
|
|
|
|
BOOL favorite1 = first.isFavorite;
|
|
|
|
BOOL favorite2 = second.isFavorite;
|
|
|
|
if (favorite1 != favorite2) {
|
|
|
|
return favorite2 - favorite1;
|
|
|
|
}
|
|
|
|
return NSOrderedSame;
|
|
|
|
}];
|
|
|
|
// Sort by lastActivity
|
|
|
|
NSSortDescriptor *valueDescriptor = [[NSSortDescriptor alloc] initWithKey:@"lastActivity" ascending:NO];
|
|
|
|
NSArray *descriptors = [NSArray arrayWithObjects:favoriteSorting, valueDescriptor, nil];
|
2020-02-27 18:33:50 +03:00
|
|
|
[unmanagedRooms sortUsingDescriptors:descriptors];
|
2020-02-20 19:24:33 +03:00
|
|
|
|
|
|
|
return unmanagedRooms;
|
|
|
|
}
|
|
|
|
|
2020-02-19 13:32:26 +03:00
|
|
|
- (NCRoom *)roomWithToken:(NSString *)token forAccountId:(NSString *)accountId
|
|
|
|
{
|
2020-03-04 18:41:29 +03:00
|
|
|
NCRoom *unmanagedRoom = nil;
|
2020-02-27 18:33:50 +03:00
|
|
|
NSPredicate *query = [NSPredicate predicateWithFormat:@"token = %@ AND accountId = %@", token, accountId];
|
|
|
|
NCRoom *managedRoom = [NCRoom objectsWithPredicate:query].firstObject;
|
2020-03-04 18:41:29 +03:00
|
|
|
if (managedRoom) {
|
|
|
|
unmanagedRoom = [[NCRoom alloc] initWithValue:managedRoom];
|
|
|
|
}
|
|
|
|
return unmanagedRoom;
|
2020-02-19 13:32:26 +03:00
|
|
|
}
|
|
|
|
|
2020-09-30 12:12:31 +03:00
|
|
|
- (void)updateRoomsUpdatingUserStatus:(BOOL)updateStatus
|
2018-05-14 17:59:27 +03:00
|
|
|
{
|
2020-03-03 12:55:08 +03:00
|
|
|
TalkAccount *activeAccount = [[NCDatabaseManager sharedInstance] activeAccount];
|
2020-09-30 12:12:31 +03:00
|
|
|
[[NCAPIController sharedInstance] getRoomsForAccount:activeAccount updateStatus:updateStatus withCompletionBlock:^(NSArray *rooms, NSError *error, NSInteger statusCode) {
|
2018-05-23 19:53:43 +03:00
|
|
|
NSMutableDictionary *userInfo = [NSMutableDictionary new];
|
|
|
|
if (!error) {
|
2020-02-17 18:27:14 +03:00
|
|
|
RLMRealm *realm = [RLMRealm defaultRealm];
|
|
|
|
[realm transactionWithBlock:^{
|
2020-03-03 12:55:08 +03:00
|
|
|
// Add or update rooms
|
|
|
|
NSInteger updateTimestamp = [[NSDate date] timeIntervalSince1970];
|
2020-02-17 18:27:14 +03:00
|
|
|
for (NSDictionary *roomDict in rooms) {
|
2020-03-03 12:55:08 +03:00
|
|
|
NCRoom *room = [NCRoom roomWithDictionary:roomDict andAccountId:activeAccount.accountId];
|
2020-03-04 19:52:02 +03:00
|
|
|
NCChatMessage *lastMessage = [NCChatMessage messageWithDictionary:[roomDict objectForKey:@"lastMessage"] andAccountId:activeAccount.accountId];
|
2020-03-03 12:55:08 +03:00
|
|
|
room.lastUpdate = updateTimestamp;
|
2020-03-04 19:52:02 +03:00
|
|
|
room.lastMessageId = lastMessage.internalId;
|
|
|
|
|
2020-03-03 14:33:57 +03:00
|
|
|
NCRoom *managedRoom = [NCRoom objectsWhere:@"internalId = %@", room.internalId].firstObject;
|
|
|
|
if (managedRoom) {
|
2020-03-04 18:50:29 +03:00
|
|
|
[NCRoom updateRoom:managedRoom withRoom:room];
|
2020-03-04 18:41:29 +03:00
|
|
|
} else if (room) {
|
2020-03-03 14:33:57 +03:00
|
|
|
[realm addObject:room];
|
2020-02-17 18:27:14 +03:00
|
|
|
}
|
2020-03-04 19:52:02 +03:00
|
|
|
|
2020-03-04 18:41:29 +03:00
|
|
|
NCChatMessage *managedLastMessage = [NCChatMessage objectsWhere:@"internalId = %@", lastMessage.internalId].firstObject;
|
|
|
|
if (managedLastMessage) {
|
2020-03-04 18:50:29 +03:00
|
|
|
[NCChatMessage updateChatMessage:managedLastMessage withChatMessage:lastMessage];
|
2020-03-04 18:41:29 +03:00
|
|
|
} else if (lastMessage) {
|
|
|
|
[realm addObject:lastMessage];
|
2020-02-17 18:27:14 +03:00
|
|
|
}
|
|
|
|
}
|
2020-03-03 12:55:08 +03:00
|
|
|
// Delete old rooms
|
|
|
|
NSPredicate *query = [NSPredicate predicateWithFormat:@"accountId = %@ AND lastUpdate != %ld", activeAccount.accountId, (long)updateTimestamp];
|
2020-05-06 19:00:54 +03:00
|
|
|
RLMResults *managedRoomsToBeDeleted = [NCRoom objectsWithPredicate:query];
|
|
|
|
// Delete messages and chat blocks from old rooms
|
|
|
|
for (NCRoom *managedRoom in managedRoomsToBeDeleted) {
|
|
|
|
NSPredicate *query2 = [NSPredicate predicateWithFormat:@"accountId = %@ AND token = %@", activeAccount.accountId, managedRoom.token];
|
|
|
|
[realm deleteObjects:[NCChatMessage objectsWithPredicate:query2]];
|
|
|
|
[realm deleteObjects:[NCChatBlock objectsWithPredicate:query2]];
|
|
|
|
}
|
|
|
|
[realm deleteObjects:managedRoomsToBeDeleted];
|
2020-02-21 21:08:07 +03:00
|
|
|
NSLog(@"Rooms updated");
|
2020-02-17 18:27:14 +03:00
|
|
|
}];
|
2018-05-23 19:53:43 +03:00
|
|
|
} else {
|
|
|
|
[userInfo setObject:error forKey:@"error"];
|
|
|
|
NSLog(@"Could not update rooms. Error: %@", error.description);
|
|
|
|
}
|
|
|
|
[[NSNotificationCenter defaultCenter] postNotificationName:NCRoomsManagerDidUpdateRoomsNotification
|
|
|
|
object:self
|
|
|
|
userInfo:userInfo];
|
2018-05-14 17:59:27 +03:00
|
|
|
}];
|
|
|
|
}
|
|
|
|
|
2018-07-30 12:54:05 +03:00
|
|
|
- (void)updateRoom:(NSString *)token
|
|
|
|
{
|
2020-03-03 12:55:08 +03:00
|
|
|
TalkAccount *activeAccount = [[NCDatabaseManager sharedInstance] activeAccount];
|
|
|
|
[[NCAPIController sharedInstance] getRoomForAccount:activeAccount withToken:token withCompletionBlock:^(NSDictionary *roomDict, NSError *error) {
|
2018-07-30 12:54:05 +03:00
|
|
|
NSMutableDictionary *userInfo = [NSMutableDictionary new];
|
|
|
|
if (!error) {
|
2020-02-20 20:27:00 +03:00
|
|
|
RLMRealm *realm = [RLMRealm defaultRealm];
|
|
|
|
[realm transactionWithBlock:^{
|
2020-03-03 12:55:08 +03:00
|
|
|
NCRoom *room = [NCRoom roomWithDictionary:roomDict andAccountId:activeAccount.accountId];
|
2020-03-04 19:52:02 +03:00
|
|
|
NCChatMessage *lastMessage = [NCChatMessage messageWithDictionary:[roomDict objectForKey:@"lastMessage"] andAccountId:activeAccount.accountId];
|
2020-03-03 12:55:08 +03:00
|
|
|
room.lastUpdate = [[NSDate date] timeIntervalSince1970];
|
2020-03-04 19:52:02 +03:00
|
|
|
room.lastMessageId = lastMessage.internalId;
|
|
|
|
|
2020-03-03 14:33:57 +03:00
|
|
|
NCRoom *managedRoom = [NCRoom objectsWhere:@"internalId = %@", room.internalId].firstObject;
|
|
|
|
if (managedRoom) {
|
2020-03-04 18:50:29 +03:00
|
|
|
[NCRoom updateRoom:managedRoom withRoom:room];
|
2020-03-04 18:41:29 +03:00
|
|
|
} else if (room) {
|
2020-03-03 14:33:57 +03:00
|
|
|
[realm addObject:room];
|
2020-02-20 20:27:00 +03:00
|
|
|
}
|
2020-03-04 19:52:02 +03:00
|
|
|
|
2020-03-04 18:41:29 +03:00
|
|
|
NCChatMessage *managedLastMessage = [NCChatMessage objectsWhere:@"internalId = %@", lastMessage.internalId].firstObject;
|
|
|
|
if (managedLastMessage) {
|
2020-03-04 18:50:29 +03:00
|
|
|
[NCChatMessage updateChatMessage:managedLastMessage withChatMessage:lastMessage];
|
2020-03-04 18:41:29 +03:00
|
|
|
} else if (lastMessage) {
|
|
|
|
[realm addObject:lastMessage];
|
2020-02-20 20:27:00 +03:00
|
|
|
}
|
2020-02-21 21:08:07 +03:00
|
|
|
NSLog(@"Room updated");
|
2020-02-20 20:27:00 +03:00
|
|
|
}];
|
2020-03-12 18:57:17 +03:00
|
|
|
NCRoom *updatedRoom = [self roomWithToken:token forAccountId:activeAccount.accountId];
|
|
|
|
[userInfo setObject:updatedRoom forKey:@"room"];
|
2018-07-30 12:54:05 +03:00
|
|
|
} else {
|
|
|
|
[userInfo setObject:error forKey:@"error"];
|
|
|
|
NSLog(@"Could not update rooms. Error: %@", error.description);
|
|
|
|
}
|
|
|
|
[[NSNotificationCenter defaultCenter] postNotificationName:NCRoomsManagerDidUpdateRoomNotification
|
|
|
|
object:self
|
|
|
|
userInfo:userInfo];
|
|
|
|
}];
|
|
|
|
}
|
|
|
|
|
2020-11-01 17:04:47 +03:00
|
|
|
- (void)updateRoomLocal:(NCRoom *)room
|
|
|
|
{
|
|
|
|
RLMRealm *realm = [RLMRealm defaultRealm];
|
|
|
|
[realm transactionWithBlock:^{
|
|
|
|
NCRoom *managedRoom = [NCRoom objectsWhere:@"internalId = %@", room.internalId].firstObject;
|
|
|
|
if (managedRoom) {
|
|
|
|
[NCRoom updateRoom:managedRoom withRoom:room];
|
|
|
|
}
|
|
|
|
}];
|
|
|
|
}
|
|
|
|
|
2018-05-14 17:59:27 +03:00
|
|
|
#pragma mark - Chat
|
|
|
|
|
2018-05-23 19:53:43 +03:00
|
|
|
- (void)startChatInRoom:(NCRoom *)room
|
2018-05-14 17:59:27 +03:00
|
|
|
{
|
2018-06-05 17:15:15 +03:00
|
|
|
if (_callViewController) {
|
|
|
|
NSLog(@"Not starting chat due to in a call.");
|
|
|
|
return;
|
|
|
|
}
|
2018-05-24 11:56:16 +03:00
|
|
|
|
2018-06-05 17:15:15 +03:00
|
|
|
NCRoomController *roomController = [_activeRooms objectForKey:room.token];
|
2019-09-23 19:45:07 +03:00
|
|
|
if (!roomController) {
|
2018-10-12 20:33:14 +03:00
|
|
|
// Workaround until external signaling supports multi-room
|
2019-11-14 12:24:21 +03:00
|
|
|
TalkAccount *activeAccount = [[NCDatabaseManager sharedInstance] activeAccount];
|
2020-02-28 19:21:58 +03:00
|
|
|
NCExternalSignalingController *extSignalingController = [[NCSettingsController sharedInstance] externalSignalingControllerForAccountId:activeAccount.accountId];
|
2019-11-14 12:24:21 +03:00
|
|
|
if ([extSignalingController isEnabled]) {
|
|
|
|
NSString *currentRoom = extSignalingController.currentRoom;
|
2018-10-12 20:33:14 +03:00
|
|
|
if (![currentRoom isEqualToString:room.token]) {
|
2019-11-14 12:24:21 +03:00
|
|
|
extSignalingController.currentRoom = nil;
|
2018-10-12 20:33:14 +03:00
|
|
|
}
|
|
|
|
}
|
2019-09-23 19:45:07 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
if (!_chatViewController || ![_chatViewController.room.token isEqualToString:room.token]) {
|
|
|
|
_chatViewController = [[NCChatViewController alloc] initForRoom:room];
|
|
|
|
[[NCUserInterfaceController sharedInstance] presentChatViewController:_chatViewController];
|
2020-11-01 23:55:32 +03:00
|
|
|
} else {
|
|
|
|
NSLog(@"Not starting chat: chatViewController for room %@ does already exist.", room.token);
|
2018-06-05 17:15:15 +03:00
|
|
|
}
|
2018-05-23 19:53:43 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
- (void)startChatWithRoomToken:(NSString *)token
|
2018-05-14 17:59:27 +03:00
|
|
|
{
|
2020-05-25 17:59:52 +03:00
|
|
|
TalkAccount *activeAccount = [[NCDatabaseManager sharedInstance] activeAccount];
|
|
|
|
NCRoom *room = [self roomWithToken:token forAccountId:activeAccount.accountId];
|
2018-05-23 19:53:43 +03:00
|
|
|
if (room) {
|
|
|
|
[self startChatInRoom:room];
|
|
|
|
} else {
|
|
|
|
//TODO: Show spinner?
|
2020-05-05 12:17:33 +03:00
|
|
|
[[NCAPIController sharedInstance] getRoomForAccount:activeAccount withToken:token withCompletionBlock:^(NSDictionary *roomDict, NSError *error) {
|
2018-05-23 19:53:43 +03:00
|
|
|
if (!error) {
|
2020-05-05 12:17:33 +03:00
|
|
|
NCRoom *room = [NCRoom roomWithDictionary:roomDict andAccountId:activeAccount.accountId];
|
2018-05-23 19:53:43 +03:00
|
|
|
[self startChatInRoom:room];
|
|
|
|
}
|
|
|
|
}];
|
|
|
|
}
|
2018-05-14 17:59:27 +03:00
|
|
|
}
|
|
|
|
|
2018-10-12 20:33:14 +03:00
|
|
|
- (void)leaveChatInRoom:(NSString *)token;
|
2018-05-25 13:41:46 +03:00
|
|
|
{
|
2018-10-12 20:33:14 +03:00
|
|
|
NCRoomController *roomController = [_activeRooms objectForKey:token];
|
2018-05-25 13:41:46 +03:00
|
|
|
if (roomController) {
|
|
|
|
roomController.inChat = NO;
|
|
|
|
}
|
2020-05-07 14:50:48 +03:00
|
|
|
|
2018-10-12 20:33:14 +03:00
|
|
|
[self leaveRoom:token];
|
2018-05-25 13:41:46 +03:00
|
|
|
}
|
|
|
|
|
2018-05-23 19:53:43 +03:00
|
|
|
#pragma mark - Call
|
|
|
|
|
2018-05-14 17:59:27 +03:00
|
|
|
- (void)startCall:(BOOL)video inRoom:(NCRoom *)room
|
|
|
|
{
|
2018-06-05 17:15:15 +03:00
|
|
|
if (!_callViewController) {
|
2019-06-16 21:21:50 +03:00
|
|
|
TalkAccount *activeAccount = [[NCDatabaseManager sharedInstance] activeAccount];
|
|
|
|
_callViewController = [[CallViewController alloc] initCallInRoom:room asUser:activeAccount.userDisplayName audioOnly:!video];
|
2019-02-05 19:52:45 +03:00
|
|
|
[_callViewController setModalTransitionStyle:UIModalTransitionStyleCrossDissolve];
|
2018-06-05 17:15:15 +03:00
|
|
|
_callViewController.delegate = self;
|
2018-10-12 20:33:14 +03:00
|
|
|
// Workaround until external signaling supports multi-room
|
2020-02-28 19:21:58 +03:00
|
|
|
NCExternalSignalingController *extSignalingController = [[NCSettingsController sharedInstance] externalSignalingControllerForAccountId:activeAccount.accountId];
|
2019-11-14 12:24:21 +03:00
|
|
|
if ([extSignalingController isEnabled]) {
|
|
|
|
NSString *currentRoom = extSignalingController.currentRoom;
|
2020-11-04 19:51:08 +03:00
|
|
|
if (![currentRoom isEqualToString:room.token] && [_chatViewController.room.token isEqualToString:currentRoom]) {
|
2019-11-14 12:24:21 +03:00
|
|
|
extSignalingController.currentRoom = nil;
|
2020-11-04 19:51:08 +03:00
|
|
|
[_chatViewController leaveChat];
|
|
|
|
[[NCUserInterfaceController sharedInstance] presentConversationsList];
|
2018-10-12 20:33:14 +03:00
|
|
|
}
|
|
|
|
}
|
2020-05-25 15:57:22 +03:00
|
|
|
if ([_chatViewController.room.token isEqualToString:room.token]) {
|
|
|
|
[_chatViewController stopChat];
|
|
|
|
}
|
2018-06-05 17:15:15 +03:00
|
|
|
[[NCUserInterfaceController sharedInstance] presentCallViewController:_callViewController];
|
2019-04-11 16:34:20 +03:00
|
|
|
[self joinRoom:room.token forCall:YES];
|
2018-06-05 17:15:15 +03:00
|
|
|
} else {
|
|
|
|
NSLog(@"Not starting call due to in another call.");
|
|
|
|
}
|
2018-05-23 19:53:43 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
- (void)joinCallWithCallToken:(NSString *)token withVideo:(BOOL)video
|
2019-02-01 17:01:02 +03:00
|
|
|
{
|
2020-05-25 17:59:52 +03:00
|
|
|
TalkAccount *activeAccount = [[NCDatabaseManager sharedInstance] activeAccount];
|
|
|
|
NCRoom *room = [self roomWithToken:token forAccountId:activeAccount.accountId];
|
2019-02-01 17:01:02 +03:00
|
|
|
if (room) {
|
2020-07-09 18:21:23 +03:00
|
|
|
[[CallKitManager sharedInstance] startCall:room.token withVideoEnabled:video andDisplayName:room.displayName withAccountId:activeAccount.accountId];
|
2019-02-01 17:01:02 +03:00
|
|
|
} else {
|
|
|
|
//TODO: Show spinner?
|
2020-05-05 12:24:36 +03:00
|
|
|
[[NCAPIController sharedInstance] getRoomForAccount:activeAccount withToken:token withCompletionBlock:^(NSDictionary *roomDict, NSError *error) {
|
2019-02-01 17:01:02 +03:00
|
|
|
if (!error) {
|
2020-05-05 12:24:36 +03:00
|
|
|
NCRoom *room = [NCRoom roomWithDictionary:roomDict andAccountId:activeAccount.accountId];
|
2020-07-09 18:21:23 +03:00
|
|
|
[[CallKitManager sharedInstance] startCall:room.token withVideoEnabled:video andDisplayName:room.displayName withAccountId:activeAccount.accountId];
|
2019-02-01 17:01:02 +03:00
|
|
|
}
|
|
|
|
}];
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
- (void)startCallWithCallToken:(NSString *)token withVideo:(BOOL)video
|
2018-05-23 19:53:43 +03:00
|
|
|
{
|
2020-05-25 17:59:52 +03:00
|
|
|
TalkAccount *activeAccount = [[NCDatabaseManager sharedInstance] activeAccount];
|
|
|
|
NCRoom *room = [self roomWithToken:token forAccountId:activeAccount.accountId];
|
2018-05-23 19:53:43 +03:00
|
|
|
if (room) {
|
|
|
|
[self startCall:video inRoom:room];
|
|
|
|
} else {
|
|
|
|
//TODO: Show spinner?
|
2020-05-05 12:24:36 +03:00
|
|
|
[[NCAPIController sharedInstance] getRoomForAccount:activeAccount withToken:token withCompletionBlock:^(NSDictionary *roomDict, NSError *error) {
|
2018-05-23 19:53:43 +03:00
|
|
|
if (!error) {
|
2020-05-05 12:24:36 +03:00
|
|
|
NCRoom *room = [NCRoom roomWithDictionary:roomDict andAccountId:activeAccount.accountId];
|
2018-05-23 19:53:43 +03:00
|
|
|
[self startCall:video inRoom:room];
|
|
|
|
}
|
|
|
|
}];
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2020-07-14 20:34:26 +03:00
|
|
|
- (void)checkForPendingToStartCalls
|
|
|
|
{
|
|
|
|
if (_pendingToStartCallToken) {
|
|
|
|
[self startCallWithCallToken:_pendingToStartCallToken withVideo:NO];
|
|
|
|
_pendingToStartCallToken = nil;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
- (BOOL)areThereActiveCalls
|
|
|
|
{
|
|
|
|
for (NCRoomController *roomController in [_activeRooms allValues]) {
|
|
|
|
if (roomController.inCall) {
|
|
|
|
return YES;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return NO;
|
|
|
|
}
|
|
|
|
|
2019-02-11 13:37:54 +03:00
|
|
|
- (void)upgradeCallToVideoCall:(NCRoom *)room
|
|
|
|
{
|
|
|
|
NCRoomController *roomController = [_activeRooms objectForKey:room.token];
|
|
|
|
if (roomController) {
|
|
|
|
roomController.inCall = NO;
|
|
|
|
}
|
2019-05-20 14:12:06 +03:00
|
|
|
_upgradeCallToken = room.token;
|
2020-07-09 18:21:23 +03:00
|
|
|
[[CallKitManager sharedInstance] endCall:room.token];
|
2019-02-11 13:37:54 +03:00
|
|
|
}
|
|
|
|
|
2020-07-14 20:34:26 +03:00
|
|
|
- (void)callDidEndInRoomWithToken:(NSString *)token
|
2018-05-25 13:41:46 +03:00
|
|
|
{
|
2020-07-14 20:34:26 +03:00
|
|
|
NCRoomController *roomController = [_activeRooms objectForKey:token];
|
2018-05-25 13:41:46 +03:00
|
|
|
if (roomController) {
|
|
|
|
roomController.inCall = NO;
|
|
|
|
}
|
2020-07-14 20:34:26 +03:00
|
|
|
[[CallKitManager sharedInstance] endCall:token];
|
|
|
|
[self leaveRoom:token];
|
2020-05-25 15:57:22 +03:00
|
|
|
|
2020-07-14 20:34:26 +03:00
|
|
|
if ([_chatViewController.room.token isEqualToString:token]) {
|
2020-05-25 15:57:22 +03:00
|
|
|
[_chatViewController resumeChat];
|
|
|
|
}
|
2018-05-25 13:41:46 +03:00
|
|
|
}
|
|
|
|
|
2018-05-24 17:19:04 +03:00
|
|
|
#pragma mark - CallViewControllerDelegate
|
|
|
|
|
|
|
|
- (void)callViewControllerWantsToBeDismissed:(CallViewController *)viewController
|
|
|
|
{
|
|
|
|
if (_callViewController == viewController && ![viewController isBeingDismissed]) {
|
|
|
|
[viewController dismissViewControllerAnimated:YES completion:nil];
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2019-02-11 13:37:54 +03:00
|
|
|
- (void)callViewControllerWantsVideoCallUpgrade:(CallViewController *)viewController
|
|
|
|
{
|
|
|
|
NCRoom *room = _callViewController.room;
|
|
|
|
if (_callViewController == viewController) {
|
|
|
|
_callViewController = nil;
|
|
|
|
[self upgradeCallToVideoCall:room];
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2018-05-24 17:19:04 +03:00
|
|
|
- (void)callViewControllerDidFinish:(CallViewController *)viewController
|
|
|
|
{
|
|
|
|
if (_callViewController == viewController) {
|
2020-07-14 20:34:26 +03:00
|
|
|
NSString *token = [_callViewController.room.token copy];
|
2018-05-24 17:19:04 +03:00
|
|
|
_callViewController = nil;
|
2020-07-14 20:34:26 +03:00
|
|
|
[self callDidEndInRoomWithToken:token];
|
2018-05-24 17:19:04 +03:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2018-05-23 19:53:43 +03:00
|
|
|
#pragma mark - Notifications
|
|
|
|
|
2019-05-20 14:12:06 +03:00
|
|
|
- (void)checkForCallUpgrades:(NSNotification *)notification
|
|
|
|
{
|
|
|
|
if (_upgradeCallToken) {
|
|
|
|
NSString *token = [_upgradeCallToken copy];
|
|
|
|
_upgradeCallToken = nil;
|
|
|
|
// Add some delay so CallKit doesn't fail requesting new call
|
|
|
|
dispatch_after(dispatch_time(DISPATCH_TIME_NOW, (int64_t)(1 * NSEC_PER_SEC)), dispatch_get_main_queue(), ^(void){
|
|
|
|
[self joinCallWithCallToken:token withVideo:YES];
|
|
|
|
});
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2019-01-18 18:10:31 +03:00
|
|
|
- (void)acceptCallForRoom:(NSNotification *)notification
|
|
|
|
{
|
|
|
|
NSString *roomToken = [notification.userInfo objectForKey:@"roomToken"];
|
2020-07-14 20:34:26 +03:00
|
|
|
BOOL waitForCallEnd = [[notification.userInfo objectForKey:@"waitForCallEnd"] boolValue];
|
|
|
|
BOOL activeCalls = [self areThereActiveCalls];
|
|
|
|
if (!waitForCallEnd || (!activeCalls && !_leaveRoomTask)) {
|
|
|
|
[self startCallWithCallToken:roomToken withVideo:NO];
|
|
|
|
} else {
|
|
|
|
_pendingToStartCallToken = roomToken;
|
|
|
|
}
|
2019-01-18 18:10:31 +03:00
|
|
|
}
|
|
|
|
|
2019-02-01 17:01:02 +03:00
|
|
|
- (void)startCallForRoom:(NSNotification *)notification
|
|
|
|
{
|
|
|
|
NSString *roomToken = [notification.userInfo objectForKey:@"roomToken"];
|
|
|
|
BOOL isVideoEnabled = [[notification.userInfo objectForKey:@"isVideoEnabled"] boolValue];
|
|
|
|
[self startCallWithCallToken:roomToken withVideo:isVideoEnabled];
|
|
|
|
}
|
|
|
|
|
2018-05-23 19:53:43 +03:00
|
|
|
- (void)joinAudioCallAccepted:(NSNotification *)notification
|
|
|
|
{
|
|
|
|
NCPushNotification *pushNotification = [notification.userInfo objectForKey:@"pushNotification"];
|
2020-01-10 18:27:39 +03:00
|
|
|
[self joinCallWithCallToken:pushNotification.roomToken withVideo:NO];
|
2018-05-14 17:59:27 +03:00
|
|
|
}
|
|
|
|
|
2018-05-23 19:53:43 +03:00
|
|
|
- (void)joinVideoCallAccepted:(NSNotification *)notification
|
|
|
|
{
|
|
|
|
NCPushNotification *pushNotification = [notification.userInfo objectForKey:@"pushNotification"];
|
2020-01-10 18:27:39 +03:00
|
|
|
[self joinCallWithCallToken:pushNotification.roomToken withVideo:YES];
|
2018-05-23 19:53:43 +03:00
|
|
|
}
|
|
|
|
|
2018-05-24 15:27:12 +03:00
|
|
|
- (void)joinChat:(NSNotification *)notification
|
|
|
|
{
|
|
|
|
NCPushNotification *pushNotification = [notification.userInfo objectForKey:@"pushNotification"];
|
2020-01-10 18:27:39 +03:00
|
|
|
[self startChatWithRoomToken:pushNotification.roomToken];
|
2018-05-24 15:27:12 +03:00
|
|
|
}
|
|
|
|
|
2019-02-08 16:17:34 +03:00
|
|
|
- (void)joinChatWithLocalNotification:(NSNotification *)notification
|
|
|
|
{
|
|
|
|
NSString *roomToken = [notification.userInfo objectForKey:@"roomToken"];
|
|
|
|
if (roomToken) {
|
|
|
|
[self startChatWithRoomToken:roomToken];
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2018-05-23 19:53:43 +03:00
|
|
|
- (void)userSelectedContactForChat:(NSNotification *)notification
|
|
|
|
{
|
|
|
|
NSString *roomToken = [notification.userInfo objectForKey:@"token"];
|
|
|
|
[self startChatWithRoomToken:roomToken];
|
|
|
|
}
|
|
|
|
|
2018-06-20 13:55:49 +03:00
|
|
|
- (void)roomCreated:(NSNotification *)notification
|
|
|
|
{
|
|
|
|
NSString *roomToken = [notification.userInfo objectForKey:@"token"];
|
|
|
|
[self startChatWithRoomToken:roomToken];
|
|
|
|
}
|
|
|
|
|
2018-05-23 19:53:43 +03:00
|
|
|
|
2018-05-14 17:59:27 +03:00
|
|
|
@end
|