Signed-off-by: Ivan Sein <ivan@nextcloud.com>
This commit is contained in:
Ivan Sein 2018-05-24 10:56:16 +02:00
Родитель 811db16142
Коммит a6489c0d53
2 изменённых файлов: 22 добавлений и 22 удалений

Просмотреть файл

@ -43,6 +43,7 @@
self.hidesBottomBarWhenPushed = YES;
// Register a SLKTextView subclass, if you need any special appearance and/or behavior customisation.
[self registerClassForTextView:[NCMessageTextView class]];
[[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(didJoinRoom:) name:NCRoomsManagerDidJoinRoomNotification object:nil];
[[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(didReceiveChatMessages:) name:NCRoomControllerDidReceiveChatMessagesNotification object:nil];
}
@ -97,12 +98,6 @@
[self registerPrefixesForAutoCompletion:@[@"@"]];
}
- (void)viewWillAppear:(BOOL)animated
{
[super viewWillAppear:animated];
[[NCRoomsManager sharedInstance] startReceivingChatMessagesInRoom:_room];
}
- (void)viewWillDisappear:(BOOL)animated
{
[super viewWillDisappear:animated];
@ -197,6 +192,16 @@
#pragma mark - Room Manager notifications
- (void)didJoinRoom:(NSNotification *)notification
{
NCRoomController *roomController = [notification.userInfo objectForKey:@"roomController"];
if (![roomController.roomToken isEqualToString:_room.token]) {
return;
}
[roomController startReceivingChatMessages];
}
- (void)didReceiveChatMessages:(NSNotification *)notification
{
NSString *room = [notification.userInfo objectForKey:@"room"];

Просмотреть файл

@ -70,12 +70,13 @@ NSString * const NCRoomsManagerDidReceiveChatMessagesNotification = @"ChatMess
- (void)joinRoom:(NCRoom *)room
{
NCRoomController *roomController = [_activeRooms objectForKey:room.token];
NSMutableDictionary *userInfo = [NSMutableDictionary new];
if (!roomController) {
[[NCAPIController sharedInstance] joinRoom:room.token withCompletionBlock:^(NSString *sessionId, NSError *error) {
NSMutableDictionary *userInfo = [NSMutableDictionary new];
if (!error) {
NCRoomController *controller = [[NCRoomController alloc] initForUser:sessionId inRoom:room.token];
[_activeRooms setObject:controller forKey:room.token];
[userInfo setObject:controller forKey:@"roomController"];
} else {
[userInfo setObject:error forKey:@"error"];
NSLog(@"Could not join room. Error: %@", error.description);
@ -84,6 +85,11 @@ NSString * const NCRoomsManagerDidReceiveChatMessagesNotification = @"ChatMess
object:self
userInfo:userInfo];
}];
} else {
[userInfo setObject:roomController forKey:@"roomController"];
[[NSNotificationCenter defaultCenter] postNotificationName:NCRoomsManagerDidJoinRoomNotification
object:self
userInfo:userInfo];
}
}
@ -151,23 +157,12 @@ NSString * const NCRoomsManagerDidReceiveChatMessagesNotification = @"ChatMess
- (void)startChatInRoom:(NCRoom *)room
{
NCChatViewController *chatVC = [[NCChatViewController alloc] initForRoom:room];
[[NCUserInterfaceController sharedInstance] presentChatViewController:chatVC];
NCRoomController *roomController = [_activeRooms objectForKey:room.token];
if (!roomController) {
[[NCAPIController sharedInstance] joinRoom:room.token withCompletionBlock:^(NSString *sessionId, NSError *error) {
NSMutableDictionary *userInfo = [NSMutableDictionary new];
if (!error) {
NCRoomController *controller = [[NCRoomController alloc] initForUser:sessionId inRoom:room.token];
[_activeRooms setObject:controller forKey:room.token];
NCChatViewController *chatVC = [[NCChatViewController alloc] initForRoom:room];
[[NCUserInterfaceController sharedInstance] presentChatViewController:chatVC];
} else {
[userInfo setObject:error forKey:@"error"];
NSLog(@"Could not join room. Error: %@", error.description);
}
}];
} else {
NCChatViewController *chatVC = [[NCChatViewController alloc] initForRoom:room];
[[NCUserInterfaceController sharedInstance] presentChatViewController:chatVC];
[self joinRoom:room];
}
}