diff --git a/NinchatSDK/UI/ViewControllers/ChatViewController/ChatView/NINChatView.m b/NinchatSDK/UI/ViewControllers/ChatViewController/ChatView/NINChatView.m index 39138af..59fb1ab 100644 --- a/NinchatSDK/UI/ViewControllers/ChatViewController/ChatView/NINChatView.m +++ b/NinchatSDK/UI/ViewControllers/ChatViewController/ChatView/NINChatView.m @@ -160,6 +160,8 @@ -(void) setSessionManager:(NINSessionManager*)sessionManager { -(void) newMessageWasAddedAtIndex:(NSInteger)index { runOnMainThread(^{ + if ([self.tableView numberOfRowsInSection:0] >= [self.dataSource numberOfMessagesForChatView:self]) { return; } + [self.tableView beginUpdates]; [self.tableView insertRowsAtIndexPaths:@[[NSIndexPath indexPathForRow:index inSection:0]] withRowAnimation:UITableViewRowAnimationAutomatic]; [self.tableView endUpdates]; @@ -168,6 +170,8 @@ -(void) newMessageWasAddedAtIndex:(NSInteger)index { -(void) messageWasRemovedAtIndex:(NSInteger)index { runOnMainThread(^{ + if ([self.tableView numberOfRowsInSection:0] <= [self.dataSource numberOfMessagesForChatView:self]) { return; } + [self.tableView beginUpdates]; [self.tableView deleteRowsAtIndexPaths:@[[NSIndexPath indexPathForRow:index inSection:0]] withRowAnimation:UITableViewRowAnimationAutomatic]; [self.tableView endUpdates]; diff --git a/NinchatSDK/UI/ViewControllers/ChatViewController/NINChatViewController.m b/NinchatSDK/UI/ViewControllers/ChatViewController/NINChatViewController.m index 0ed6eaa..f674890 100644 --- a/NinchatSDK/UI/ViewControllers/ChatViewController/NINChatViewController.m +++ b/NinchatSDK/UI/ViewControllers/ChatViewController/NINChatViewController.m @@ -7,6 +7,7 @@ // @import CoreServices; +@import MobileCoreServices; @import AVFoundation; @import AVKit; @import Photos; @@ -391,13 +392,15 @@ -(void) listenToWebRTCSignaling { // Show the video view [weakSelf adjustConstraintsForSize:weakSelf.view.bounds.size animate:YES]; - [self resizeLocalVideoView]; + [weakSelf resizeLocalVideoView]; + [weakSelf stopIdleTimer:YES]; }]; } else if ([note.userInfo[@"messageType"] isEqualToString:kNINMessageTypeWebRTCHangup]) { NSLog(@"Got WebRTC hang-up - closing the video call."); // Disconnect [weakSelf disconnectWebRTC]; + [weakSelf stopIdleTimer:NO]; // Close the video view [weakSelf adjustConstraintsForSize:weakSelf.view.bounds.size animate:YES]; @@ -861,6 +864,14 @@ -(void) keyboardWillHide:(NSNotification *)notification { [self.sessionManager setIsWriting:NO completion:^(NSError* error) {}]; } +#pragma mark - Helper + +/// To prevent screen-saver during a video call +/// https://github.com/somia/mobile/issues/204 +- (void) stopIdleTimer:(BOOL )stop { + [UIApplication sharedApplication].idleTimerDisabled = stop; +} + #pragma mark - Lifecycle etc. -(void) viewWillAppear:(BOOL)animated { @@ -981,7 +992,7 @@ -(void) viewDidLoad { NSNumber* index = note.userInfo[@"index"]; if ([note.userInfo[@"action"] isEqualToString:@"insert"]) { [weakSelf.chatView newMessageWasAddedAtIndex:index.integerValue]; - } else { + } else if ([note.userInfo[@"action"] isEqualToString:@"remove"]) { [weakSelf.chatView messageWasRemovedAtIndex:index.integerValue]; }