From c32e143873a0bdd7465397b0d49704bb134b3076 Mon Sep 17 00:00:00 2001 From: Ivan Sein Date: Mon, 25 Oct 2021 18:41:38 +0200 Subject: [PATCH] Add tap gesture recognizer to chat cells' avatar. Signed-off-by: Ivan Sein --- NextcloudTalk/ChatMessageTableViewCell.h | 2 +- NextcloudTalk/ChatMessageTableViewCell.m | 34 +++++++++++------- NextcloudTalk/ChatTableViewCell.h | 9 +++++ NextcloudTalk/ChatTableViewCell.m | 1 + NextcloudTalk/FileMessageTableViewCell.h | 2 +- NextcloudTalk/FileMessageTableViewCell.m | 36 ++++++++++++------- .../GroupedChatMessageTableViewCell.m | 1 + NextcloudTalk/LocationMessageTableViewCell.h | 2 +- NextcloudTalk/LocationMessageTableViewCell.m | 36 ++++++++++++------- NextcloudTalk/NCChatViewController.m | 14 ++++++++ NextcloudTalk/SystemMessageTableViewCell.m | 2 ++ NextcloudTalk/VoiceMessageTableViewCell.h | 2 +- NextcloudTalk/VoiceMessageTableViewCell.m | 14 +++++++- 13 files changed, 114 insertions(+), 41 deletions(-) diff --git a/NextcloudTalk/ChatMessageTableViewCell.h b/NextcloudTalk/ChatMessageTableViewCell.h index e6f57ced..3f895506 100644 --- a/NextcloudTalk/ChatMessageTableViewCell.h +++ b/NextcloudTalk/ChatMessageTableViewCell.h @@ -36,7 +36,7 @@ static NSString *AutoCompletionCellIdentifier = @"AutoCompletionCellIdentifier @class ChatMessageTableViewCell; -@protocol ChatMessageTableViewCellDelegate +@protocol ChatMessageTableViewCellDelegate - (void)cellWantsToScrollToMessage:(NCChatMessage *)message; diff --git a/NextcloudTalk/ChatMessageTableViewCell.m b/NextcloudTalk/ChatMessageTableViewCell.m index 28ba18f5..4aa89d8e 100644 --- a/NextcloudTalk/ChatMessageTableViewCell.m +++ b/NextcloudTalk/ChatMessageTableViewCell.m @@ -35,7 +35,6 @@ @interface ChatMessageTableViewCell () @property (nonatomic, strong) UIView *quoteContainerView; -@property (nonatomic, strong) NCChatMessage *message; @end @implementation ChatMessageTableViewCell @@ -54,11 +53,13 @@ { _avatarView = [[UIImageView alloc] initWithFrame:CGRectMake(0, 0, kChatMessageCellAvatarHeight, kChatMessageCellAvatarHeight)]; _avatarView.translatesAutoresizingMaskIntoConstraints = NO; - _avatarView.userInteractionEnabled = NO; + _avatarView.userInteractionEnabled = YES; _avatarView.backgroundColor = [NCAppBranding placeholderColor]; _avatarView.layer.cornerRadius = kChatMessageCellAvatarHeight/2.0; _avatarView.layer.masksToBounds = YES; _avatarView.contentMode = UIViewContentModeScaleToFill; + UITapGestureRecognizer *avatarTap = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(avatarTapped:)]; + [_avatarView addGestureRecognizer:avatarTap]; [self.contentView addSubview:_avatarView]; _statusView = [[UIView alloc] initWithFrame:CGRectMake(0, 0, kChatCellStatusViewHeight, kChatCellStatusViewHeight)]; @@ -78,8 +79,8 @@ [self.contentView addSubview:self.quoteContainerView]; [_quoteContainerView addSubview:self.quotedMessageView]; - UITapGestureRecognizer *tapRecognizer = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(quoteTapped:)]; - [self.quoteContainerView addGestureRecognizer:tapRecognizer]; + UITapGestureRecognizer *quoteTap = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(quoteTapped:)]; + [self.quoteContainerView addGestureRecognizer:quoteTap]; } NSDictionary *views = @{@"avatarView": self.avatarView, @@ -162,6 +163,22 @@ [self.statusView.subviews makeObjectsPerformSelector: @selector(removeFromSuperview)]; } +#pragma mark - Gesture recognizers + +- (void)avatarTapped:(UIGestureRecognizer *)gestureRecognizer +{ + if (self.delegate && self.message) { + [self.delegate cellWantsToDisplayOptionsForMessageActor:self.message]; + } +} + +- (void)quoteTapped:(UIGestureRecognizer *)gestureRecognizer +{ + if (self.delegate && self.message && self.message.parent) { + [self.delegate cellWantsToScrollToMessage:self.message.parent]; + } +} + #pragma mark - Getters - (UILabel *)titleLabel @@ -234,6 +251,7 @@ self.titleLabel.text = message.actorDisplayName; self.bodyTextView.attributedText = message.parsedMessage; self.messageId = message.messageId; + self.message = message; NSDate *date = [[NSDate alloc] initWithTimeIntervalSince1970:message.timestamp]; self.dateLabel.text = [NCUtils getTimeFromDate:date]; TalkAccount *activeAccount = [[NCDatabaseManager sharedInstance] activeAccount]; @@ -286,8 +304,6 @@ self.bodyTextView.textColor = [UIColor tertiaryLabelColor]; } } - - self.message = message; } - (void)setGuestAvatar:(NSString *)displayName @@ -362,12 +378,6 @@ } } -- (void)quoteTapped:(UIGestureRecognizer *)gestureRecognizer { - if (self.delegate && self.message && self.message.parent) { - [self.delegate cellWantsToScrollToMessage:self.message.parent]; - } -} - + (CGFloat)defaultFontSize { CGFloat pointSize = 16.0; diff --git a/NextcloudTalk/ChatTableViewCell.h b/NextcloudTalk/ChatTableViewCell.h index 188ebc51..833293d8 100644 --- a/NextcloudTalk/ChatTableViewCell.h +++ b/NextcloudTalk/ChatTableViewCell.h @@ -22,6 +22,8 @@ #import +#import "NCChatMessage.h" + static CGFloat kChatCellStatusViewHeight = 20.0; typedef enum ChatMessageDeliveryState { @@ -32,8 +34,15 @@ typedef enum ChatMessageDeliveryState { ChatMessageDeliveryStateFailed } ChatMessageDeliveryState; +@protocol ChatTableViewCellDelegate + +- (void)cellWantsToDisplayOptionsForMessageActor:(NCChatMessage *)message; + +@end + @interface ChatTableViewCell : UITableViewCell @property (nonatomic, assign) NSInteger messageId; +@property (nonatomic, strong) NCChatMessage *message; @end diff --git a/NextcloudTalk/ChatTableViewCell.m b/NextcloudTalk/ChatTableViewCell.m index 3fc97455..78808f81 100644 --- a/NextcloudTalk/ChatTableViewCell.m +++ b/NextcloudTalk/ChatTableViewCell.m @@ -39,6 +39,7 @@ { [super prepareForReuse]; self.messageId = -1; + self.message = nil; } @end diff --git a/NextcloudTalk/FileMessageTableViewCell.h b/NextcloudTalk/FileMessageTableViewCell.h index f0d98a49..ce45dd53 100644 --- a/NextcloudTalk/FileMessageTableViewCell.h +++ b/NextcloudTalk/FileMessageTableViewCell.h @@ -38,7 +38,7 @@ static NSString *GroupedFileMessageCellIdentifier = @"GroupedFileMessageCellId @class FileMessageTableViewCell; -@protocol FileMessageTableViewCellDelegate +@protocol FileMessageTableViewCellDelegate - (void)cellWantsToDownloadFile:(NCMessageFileParameter *)fileParameter; diff --git a/NextcloudTalk/FileMessageTableViewCell.m b/NextcloudTalk/FileMessageTableViewCell.m index af031da0..1d1652c3 100644 --- a/NextcloudTalk/FileMessageTableViewCell.m +++ b/NextcloudTalk/FileMessageTableViewCell.m @@ -60,10 +60,12 @@ { _avatarView = [[UIImageView alloc] initWithFrame:CGRectMake(0, 0, kFileMessageCellAvatarHeight, kFileMessageCellAvatarHeight)]; _avatarView.translatesAutoresizingMaskIntoConstraints = NO; - _avatarView.userInteractionEnabled = NO; + _avatarView.userInteractionEnabled = YES; _avatarView.backgroundColor = [NCAppBranding placeholderColor]; _avatarView.layer.cornerRadius = kFileMessageCellAvatarHeight/2.0; _avatarView.layer.masksToBounds = YES; + UITapGestureRecognizer *avatarTap = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(avatarTapped:)]; + [_avatarView addGestureRecognizer:avatarTap]; _previewImageView = [[FilePreviewImageView alloc] initWithFrame:CGRectMake(0, 0, kFileMessageCellFilePreviewHeight, kFileMessageCellFilePreviewHeight)]; _previewImageView.translatesAutoresizingMaskIntoConstraints = NO; @@ -162,6 +164,7 @@ self.titleLabel.text = message.actorDisplayName; self.bodyTextView.attributedText = message.parsedMessage; self.messageId = message.messageId; + self.message = message; NSDate *date = [[NSDate alloc] initWithTimeIntervalSince1970:message.timestamp]; self.dateLabel.text = [NCUtils getTimeFromDate:date]; @@ -296,6 +299,26 @@ [self.fileStatusView addSubview:_activityIndicator]; } +#pragma mark - Gesture recognizers + +- (void)avatarTapped:(UIGestureRecognizer *)gestureRecognizer +{ + if (self.delegate && self.message) { + [self.delegate cellWantsToDisplayOptionsForMessageActor:self.message]; + } +} + +- (void)previewTapped:(UITapGestureRecognizer *)recognizer +{ + if (!self.fileParameter || !self.fileParameter.path || !self.fileParameter.link) { + return; + } + + if (self.delegate) { + [self.delegate cellWantsToDownloadFile:self.fileParameter]; + } +} + #pragma mark - Getters @@ -346,17 +369,6 @@ return _bodyTextView; } -- (void)previewTapped:(UITapGestureRecognizer *)recognizer -{ - if (!self.fileParameter || !self.fileParameter.path || !self.fileParameter.link) { - return; - } - - if (self.delegate) { - [self.delegate cellWantsToDownloadFile:self.fileParameter]; - } -} - - (void)setGuestAvatar:(NSString *)displayName { UIColor *guestAvatarColor = [NCAppBranding placeholderColor]; diff --git a/NextcloudTalk/GroupedChatMessageTableViewCell.m b/NextcloudTalk/GroupedChatMessageTableViewCell.m index 1db7eb0a..25e1df73 100644 --- a/NextcloudTalk/GroupedChatMessageTableViewCell.m +++ b/NextcloudTalk/GroupedChatMessageTableViewCell.m @@ -83,6 +83,7 @@ { self.bodyTextView.attributedText = message.parsedMessage; self.messageId = message.messageId; + self.message = message; TalkAccount *activeAccount = [[NCDatabaseManager sharedInstance] activeAccount]; ServerCapabilities *serverCapabilities = [[NCDatabaseManager sharedInstance] serverCapabilitiesForAccountId:activeAccount.accountId]; diff --git a/NextcloudTalk/LocationMessageTableViewCell.h b/NextcloudTalk/LocationMessageTableViewCell.h index d34ccee1..3c1aa6a8 100644 --- a/NextcloudTalk/LocationMessageTableViewCell.h +++ b/NextcloudTalk/LocationMessageTableViewCell.h @@ -37,7 +37,7 @@ static NSString *GroupedLocationMessageCellIdentifier = @"GroupedLocationMessa @class LocationMessageTableViewCell; -@protocol LocationMessageTableViewCellDelegate +@protocol LocationMessageTableViewCellDelegate - (void)cellWantsToOpenLocation:(GeoLocationRichObject *)geoLocationRichObject; diff --git a/NextcloudTalk/LocationMessageTableViewCell.m b/NextcloudTalk/LocationMessageTableViewCell.m index 0db01f47..a01695e6 100644 --- a/NextcloudTalk/LocationMessageTableViewCell.m +++ b/NextcloudTalk/LocationMessageTableViewCell.m @@ -57,10 +57,12 @@ { _avatarView = [[UIImageView alloc] initWithFrame:CGRectMake(0, 0, kLocationMessageCellAvatarHeight, kLocationMessageCellAvatarHeight)]; _avatarView.translatesAutoresizingMaskIntoConstraints = NO; - _avatarView.userInteractionEnabled = NO; + _avatarView.userInteractionEnabled = YES; _avatarView.backgroundColor = [NCAppBranding placeholderColor]; _avatarView.layer.cornerRadius = kLocationMessageCellAvatarHeight/2.0; _avatarView.layer.masksToBounds = YES; + UITapGestureRecognizer *avatarTap = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(avatarTapped:)]; + [_avatarView addGestureRecognizer:avatarTap]; _previewImageView = [[UIImageView alloc] initWithFrame:CGRectMake(0, 0, kLocationMessageCellPreviewWidth, kLocationMessageCellPreviewHeight)]; _previewImageView.translatesAutoresizingMaskIntoConstraints = NO; @@ -150,6 +152,7 @@ self.titleLabel.text = message.actorDisplayName; self.bodyTextView.attributedText = message.parsedMessage; self.messageId = message.messageId; + self.message = message; NSDate *date = [[NSDate alloc] initWithTimeIntervalSince1970:message.timestamp]; self.dateLabel.text = [NCUtils getTimeFromDate:date]; @@ -235,6 +238,26 @@ } } +#pragma mark - Gesture recognizers + +- (void)avatarTapped:(UIGestureRecognizer *)gestureRecognizer +{ + if (self.delegate && self.message) { + [self.delegate cellWantsToDisplayOptionsForMessageActor:self.message]; + } +} + +- (void)previewTapped:(UITapGestureRecognizer *)recognizer +{ + if (!self.geoLocationRichObject) { + return; + } + + if (self.delegate) { + [self.delegate cellWantsToOpenLocation:self.geoLocationRichObject]; + } +} + #pragma mark - Getters - (UILabel *)titleLabel @@ -284,17 +307,6 @@ return _bodyTextView; } -- (void)previewTapped:(UITapGestureRecognizer *)recognizer -{ - if (!self.geoLocationRichObject) { - return; - } - - if (self.delegate) { - [self.delegate cellWantsToOpenLocation:self.geoLocationRichObject]; - } -} - - (void)setGuestAvatar:(NSString *)displayName { UIColor *guestAvatarColor = [NCAppBranding placeholderColor]; diff --git a/NextcloudTalk/NCChatViewController.m b/NextcloudTalk/NCChatViewController.m index c4d751ba..d8fcc74a 100644 --- a/NextcloudTalk/NCChatViewController.m +++ b/NextcloudTalk/NCChatViewController.m @@ -1254,6 +1254,11 @@ NSString * const NCChatViewControllerForwardNotification = @"NCChatViewControlle } } +- (void)presentOptionsForMessageActor:(NCChatMessage *)message +{ + +} + #pragma mark - UIImagePickerController Delegate - (void)imagePickerController:(UIImagePickerController *)picker didFinishPickingMediaWithInfo:(NSDictionary *)info @@ -2924,6 +2929,8 @@ NSString * const NCChatViewControllerForwardNotification = @"NCChatViewControlle return groupedCell; } else { ChatMessageTableViewCell *normalCell = (ChatMessageTableViewCell *)[self.tableView dequeueReusableCellWithIdentifier:ChatMessageCellIdentifier]; + normalCell.delegate = self; + [normalCell setupForMessage:message withLastCommonReadMessage:_room.lastCommonReadMessage]; return normalCell; @@ -3259,6 +3266,13 @@ NSString * const NCChatViewControllerForwardNotification = @"NCChatViewControlle } } +- (void)cellWantsToDisplayOptionsForMessageActor:(NCChatMessage *)message { + NSIndexPath *indexPath = [self indexPathForMessage:message]; + if (indexPath) { + [self presentOptionsForMessageActor:message]; + } +} + #pragma mark - NCChatFileControllerDelegate - (void)fileControllerDidLoadFile:(NCChatFileController *)fileController withFileStatus:(NCChatFileStatus *)fileStatus diff --git a/NextcloudTalk/SystemMessageTableViewCell.m b/NextcloudTalk/SystemMessageTableViewCell.m index 108eb045..508d56c5 100644 --- a/NextcloudTalk/SystemMessageTableViewCell.m +++ b/NextcloudTalk/SystemMessageTableViewCell.m @@ -117,6 +117,8 @@ { self.bodyTextView.attributedText = message.systemMessageFormat; self.messageId = message.messageId; + self.message = message; + if (!message.isGroupMessage) { NSDate *date = [[NSDate alloc] initWithTimeIntervalSince1970:message.timestamp]; self.dateLabel.text = [NCUtils getTimeFromDate:date]; diff --git a/NextcloudTalk/VoiceMessageTableViewCell.h b/NextcloudTalk/VoiceMessageTableViewCell.h index 52477f46..be4f3329 100644 --- a/NextcloudTalk/VoiceMessageTableViewCell.h +++ b/NextcloudTalk/VoiceMessageTableViewCell.h @@ -33,7 +33,7 @@ static CGFloat kVoiceMessageCellPlayerHeight = 44.0; static NSString *VoiceMessageCellIdentifier = @"VoiceMessageCellIdentifier"; static NSString *GroupedVoiceMessageCellIdentifier = @"GroupedVoiceMessageCellIdentifier"; -@protocol VoiceMessageTableViewCellDelegate +@protocol VoiceMessageTableViewCellDelegate - (void)cellWantsToPlayAudioFile:(NCMessageFileParameter *)fileParameter; - (void)cellWantsToPauseAudioFile:(NCMessageFileParameter *)fileParameter; diff --git a/NextcloudTalk/VoiceMessageTableViewCell.m b/NextcloudTalk/VoiceMessageTableViewCell.m index b15438da..dc884642 100644 --- a/NextcloudTalk/VoiceMessageTableViewCell.m +++ b/NextcloudTalk/VoiceMessageTableViewCell.m @@ -60,10 +60,12 @@ { _avatarView = [[UIImageView alloc] initWithFrame:CGRectMake(0, 0, kVoiceMessageCellAvatarHeight, kVoiceMessageCellAvatarHeight)]; _avatarView.translatesAutoresizingMaskIntoConstraints = NO; - _avatarView.userInteractionEnabled = NO; + _avatarView.userInteractionEnabled = YES; _avatarView.backgroundColor = [NCAppBranding placeholderColor]; _avatarView.layer.cornerRadius = kVoiceMessageCellAvatarHeight/2.0; _avatarView.layer.masksToBounds = YES; + UITapGestureRecognizer *avatarTap = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(avatarTapped:)]; + [_avatarView addGestureRecognizer:avatarTap]; _audioPlayerView = [[UIView alloc] initWithFrame:CGRectMake(0, 0, 200, 44)]; _audioPlayerView.translatesAutoresizingMaskIntoConstraints = NO; @@ -183,6 +185,7 @@ { self.titleLabel.text = message.actorDisplayName; self.messageId = message.messageId; + self.message = message; NSDate *date = [[NSDate alloc] initWithTimeIntervalSince1970:message.timestamp]; self.dateLabel.text = [NCUtils getTimeFromDate:date]; @@ -366,6 +369,15 @@ [self.fileStatusView addSubview:_activityIndicator]; } +#pragma mark - Gesture recognizers + +- (void)avatarTapped:(UIGestureRecognizer *)gestureRecognizer +{ + if (self.delegate && self.message) { + [self.delegate cellWantsToDisplayOptionsForMessageActor:self.message]; + } +} + #pragma mark - Getters