зеркало из https://github.com/nextcloud/talk-ios.git
Present and highlight searched messages in chat when selecting them.
Signed-off-by: Ivan Sein <ivan@nextcloud.com>
This commit is contained in:
Родитель
3fdfd2b5bc
Коммит
cb59dbe8a8
|
@ -32,6 +32,7 @@ extern NSString * const NCChatViewControllerTalkToUserNotification;
|
|||
|
||||
@property (nonatomic, strong) NCRoom *room;
|
||||
@property (nonatomic, assign) BOOL presentedInCall;
|
||||
@property (nonatomic, assign) NSInteger highlightMessageId;
|
||||
|
||||
- (instancetype)initForRoom:(NCRoom *)room;
|
||||
- (void)stopChat;
|
||||
|
|
|
@ -1530,6 +1530,15 @@ NSString * const NCChatViewControllerTalkToUserNotification = @"NCChatViewContro
|
|||
}];
|
||||
}
|
||||
|
||||
- (void)highlightMessageAtIndexPath:(NSIndexPath *)indexPath withScrollPosition:(UITableViewScrollPosition)scrollPosition
|
||||
{
|
||||
[self.tableView selectRowAtIndexPath:indexPath animated:YES scrollPosition:scrollPosition];
|
||||
|
||||
dispatch_after(dispatch_time(DISPATCH_TIME_NOW, (int64_t)(1 * NSEC_PER_SEC)), dispatch_get_main_queue(), ^{
|
||||
[self.tableView deselectRowAtIndexPath:indexPath animated:YES];
|
||||
});
|
||||
}
|
||||
|
||||
#pragma mark - UITextField delegate
|
||||
|
||||
- (BOOL)textFieldShouldReturn:(UITextField *)textField
|
||||
|
@ -2615,6 +2624,14 @@ NSString * const NCChatViewControllerTalkToUserNotification = @"NCChatViewContro
|
|||
[self->_chatBackgroundView.loadingView stopAnimating];
|
||||
[self->_chatBackgroundView.loadingView setHidden:YES];
|
||||
}
|
||||
|
||||
if (self->_highlightMessageId) {
|
||||
NSIndexPath *indexPath = [self indexPathForMessageWithMessageId:self->_highlightMessageId];
|
||||
if (indexPath) {
|
||||
[self highlightMessageAtIndexPath:indexPath withScrollPosition:UITableViewScrollPositionMiddle];
|
||||
}
|
||||
self->_highlightMessageId = 0;
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
|
@ -3825,11 +3842,7 @@ NSString * const NCChatViewControllerTalkToUserNotification = @"NCChatViewContro
|
|||
- (void)cellWantsToScrollToMessage:(NCChatMessage *)message {
|
||||
NSIndexPath *indexPath = [self indexPathForMessage:message];
|
||||
if (indexPath) {
|
||||
[self.tableView selectRowAtIndexPath:indexPath animated:YES scrollPosition:UITableViewScrollPositionTop];
|
||||
|
||||
dispatch_after(dispatch_time(DISPATCH_TIME_NOW, (int64_t)(0.5 * NSEC_PER_SEC)), dispatch_get_main_queue(), ^{
|
||||
[self.tableView deselectRowAtIndexPath:indexPath animated:YES];
|
||||
});
|
||||
[self highlightMessageAtIndexPath:indexPath withScrollPosition:UITableViewScrollPositionTop];
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -56,6 +56,7 @@ NSString * const NCRoomsManagerDidReceiveChatMessagesNotification = @"ChatMess
|
|||
@property (nonatomic, strong) NSString *upgradeCallToken;
|
||||
@property (nonatomic, strong) NSString *pendingToStartCallToken;
|
||||
@property (nonatomic, assign) BOOL pendingToStartCallHasVideo;
|
||||
@property (nonatomic, strong) NSDictionary *highlightMessageDict;
|
||||
|
||||
@end
|
||||
|
||||
|
@ -94,6 +95,7 @@ NSString * const NCRoomsManagerDidReceiveChatMessagesNotification = @"ChatMess
|
|||
[[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(joinChatOfForwardedMessage:) name:NCChatViewControllerForwardNotification object:nil];
|
||||
[[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(joinOrCreateChat:) name:NCChatViewControllerTalkToUserNotification object:nil];
|
||||
[[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(joinOrCreateChatWithURL:) name:NCURLWantsToOpenConversationNotification object:nil];
|
||||
[[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(joinChatHighlightingMessage:) name:NCPresentChatHighlightingMessageNotification object:nil];
|
||||
}
|
||||
|
||||
return self;
|
||||
|
@ -528,6 +530,9 @@ NSString * const NCRoomsManagerDidReceiveChatMessagesNotification = @"ChatMess
|
|||
|
||||
if (!_chatViewController || ![_chatViewController.room.token isEqualToString:room.token]) {
|
||||
_chatViewController = [[NCChatViewController alloc] initForRoom:room];
|
||||
if (_highlightMessageDict && [[_highlightMessageDict objectForKey:@"token"] isEqualToString:room.token]) {
|
||||
_chatViewController.highlightMessageId = [[_highlightMessageDict objectForKey:@"messageId"] integerValue];
|
||||
}
|
||||
[[NCUserInterfaceController sharedInstance] presentChatViewController:_chatViewController];
|
||||
} else {
|
||||
NSLog(@"Not starting chat: chatViewController for room %@ does already exist.", room.token);
|
||||
|
@ -835,6 +840,13 @@ NSString * const NCRoomsManagerDidReceiveChatMessagesNotification = @"ChatMess
|
|||
}
|
||||
}
|
||||
|
||||
- (void)joinChatHighlightingMessage:(NSNotification *)notification
|
||||
{
|
||||
_highlightMessageDict = notification.userInfo;
|
||||
NSString *token = [notification.userInfo objectForKey:@"token"];
|
||||
[self startChatWithRoomToken:token];
|
||||
}
|
||||
|
||||
- (void)userSelectedContactForChat:(NSNotification *)notification
|
||||
{
|
||||
NSString *roomToken = [notification.userInfo objectForKey:@"token"];
|
||||
|
|
|
@ -32,5 +32,6 @@ extern NSString * const NCTokenRevokedResponseReceivedNotification;
|
|||
extern NSString * const NCURLWantsToOpenConversationNotification;
|
||||
extern NSString * const NCServerMaintenanceModeNotification;
|
||||
extern NSString * const NCTalkConfigurationHashChangedNotification;
|
||||
extern NSString * const NCPresentChatHighlightingMessageNotification;
|
||||
|
||||
NS_ASSUME_NONNULL_END
|
||||
|
|
|
@ -30,4 +30,5 @@ NSString * const NCTokenRevokedResponseReceivedNotification = @"NCTokenRevokedRe
|
|||
NSString * const NCURLWantsToOpenConversationNotification = @"NCURLWantsToOpenConversationNotification";
|
||||
NSString * const NCServerMaintenanceModeNotification = @"NCServerMaintenanceModeNotification";
|
||||
NSString * const NCTalkConfigurationHashChangedNotification = @"NCTalkConfigurationHashChangedNotification";
|
||||
NSString * const NCPresentChatHighlightingMessageNotification = @"NCPresentChatHighlightingMessageNotification";
|
||||
|
||||
|
|
|
@ -1200,11 +1200,19 @@ typedef void (^FetchRoomsCompletionBlock)(BOOL success);
|
|||
{
|
||||
[tableView deselectRowAtIndexPath:indexPath animated:YES];
|
||||
|
||||
// Searched messages
|
||||
// Present searched messages
|
||||
if (tableView == _resultTableViewController.tableView) {
|
||||
NCCSearchEntry *searchMessage = [_resultTableViewController messageForIndexPath:indexPath];
|
||||
if (searchMessage) {
|
||||
NSString *roomToken = [searchMessage.attributes objectForKey:@"conversation"];
|
||||
NSString *messageId = [searchMessage.attributes objectForKey:@"messageId"];
|
||||
if (roomToken && messageId) {
|
||||
// Present message in chat view
|
||||
NSMutableDictionary *userInfo = [[NSMutableDictionary alloc] init];
|
||||
[userInfo setObject:roomToken forKey:@"token"];
|
||||
[userInfo setObject:messageId forKey:@"messageId"];
|
||||
[[NSNotificationCenter defaultCenter] postNotificationName:NCPresentChatHighlightingMessageNotification
|
||||
object:self
|
||||
userInfo:userInfo];
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
|
Загрузка…
Ссылка в новой задаче