add text reply action, comment out more deprecated uimenu code

This commit is contained in:
Michael Kirk 2018-07-11 21:47:37 -06:00
parent 6079ae2439
commit 2552368146
5 changed files with 197 additions and 192 deletions

View File

@ -1995,6 +1995,7 @@ typedef enum : NSUInteger {
- (void)messageActionsReplyToItem:(ConversationViewItem *)conversationViewItem
{
[self populateReplyForViewItem:conversationViewItem];
}
#pragma mark - ConversationViewCellDelegate
@ -2471,7 +2472,7 @@ typedef enum : NSUInteger {
[self.navigationController pushViewController:view animated:YES];
}
- (void)conversationCell:(ConversationViewCell *)cell didTapReplyForViewItem:(ConversationViewItem *)conversationItem
- (void)populateReplyForViewItem:(ConversationViewItem *)conversationItem
{
DDLogDebug(@"%@ user did tap reply", self.logTag);

View File

@ -109,24 +109,29 @@ NSString *NSStringForOWSMessageCellType(OWSMessageCellType cellType);
@property (nonatomic, readonly, nullable) ContactShareViewModel *contactShare;
#pragma mark - UIMenuController
#pragma mark - MessageActions
@property (nonatomic, readonly) BOOL hasBodyTextActionContent;
- (NSArray<UIMenuItem *> *)textMenuControllerItems;
- (NSArray<UIMenuItem *> *)mediaMenuControllerItems;
- (NSArray<UIMenuItem *> *)defaultMenuControllerItems;
- (BOOL)canPerformAction:(SEL)action;
- (void)copyMediaAction;
- (void)copyTextAction;
- (void)shareMediaAction;
- (void)shareTextAction;
- (void)saveMediaAction;
- (void)deleteAction;
- (void)copyMediaAction;
- (SEL)replyActionSelector;
- (SEL)metadataActionSelector;
// #pragma mark - UIMenuController
//
//- (NSArray<UIMenuItem *> *)textMenuControllerItems;
//- (NSArray<UIMenuItem *> *)mediaMenuControllerItems;
//- (NSArray<UIMenuItem *> *)defaultMenuControllerItems;
//
//- (BOOL)canPerformAction:(SEL)action;
//- (void)deleteAction;
//
//- (SEL)replyActionSelector;
//- (SEL)metadataActionSelector;
@end

View File

@ -600,146 +600,146 @@ NSString *NSStringForOWSMessageCellType(OWSMessageCellType cellType)
#pragma mark - UIMenuController
- (NSArray<UIMenuItem *> *)textMenuControllerItems
{
return @[
[[UIMenuItem alloc] initWithTitle:NSLocalizedString(@"EDIT_ITEM_MESSAGE_METADATA_ACTION",
@"Short name for edit menu item to show message metadata.")
action:self.metadataActionSelector],
[[UIMenuItem alloc] initWithTitle:NSLocalizedString(@"EDIT_ITEM_COPY_ACTION",
@"Short name for edit menu item to copy contents of media message.")
action:self.copyTextActionSelector],
[[UIMenuItem alloc] initWithTitle:NSLocalizedString(@"REPLY_ITEM_ACTION",
@"Short name for edit menu item to reply to a message.")
action:self.replyActionSelector],
[[UIMenuItem alloc] initWithTitle:NSLocalizedString(@"EDIT_ITEM_DELETE_ACTION",
@"Short name for edit menu item to delete contents of media message.")
action:self.deleteActionSelector]
];
}
//- (NSArray<UIMenuItem *> *)textMenuControllerItems
//{
// return @[
// [[UIMenuItem alloc] initWithTitle:NSLocalizedString(@"EDIT_ITEM_MESSAGE_METADATA_ACTION",
// @"Short name for edit menu item to show message metadata.")
// action:self.metadataActionSelector],
// [[UIMenuItem alloc] initWithTitle:NSLocalizedString(@"EDIT_ITEM_COPY_ACTION",
// @"Short name for edit menu item to copy contents of media message.")
// action:self.copyTextActionSelector],
// [[UIMenuItem alloc] initWithTitle:NSLocalizedString(@"REPLY_ITEM_ACTION",
// @"Short name for edit menu item to reply to a message.")
// action:self.replyActionSelector],
// [[UIMenuItem alloc] initWithTitle:NSLocalizedString(@"EDIT_ITEM_DELETE_ACTION",
// @"Short name for edit menu item to delete contents of media message.")
// action:self.deleteActionSelector]
// ];
//}
- (NSArray<UIMenuItem *> *)mediaMenuControllerItems
{
return @[
[[UIMenuItem alloc] initWithTitle:NSLocalizedString(@"EDIT_ITEM_MESSAGE_METADATA_ACTION",
@"Short name for edit menu item to show message metadata.")
action:self.metadataActionSelector],
[[UIMenuItem alloc] initWithTitle:NSLocalizedString(@"EDIT_ITEM_COPY_ACTION",
@"Short name for edit menu item to copy contents of media message.")
action:self.copyMediaActionSelector],
[[UIMenuItem alloc] initWithTitle:NSLocalizedString(@"REPLY_ITEM_ACTION",
@"Short name for edit menu item to reply to a message.")
action:self.replyActionSelector],
[[UIMenuItem alloc] initWithTitle:NSLocalizedString(@"EDIT_ITEM_DELETE_ACTION",
@"Short name for edit menu item to delete contents of media message.")
action:self.deleteActionSelector],
[[UIMenuItem alloc] initWithTitle:NSLocalizedString(@"EDIT_ITEM_SAVE_ACTION",
@"Short name for edit menu item to save contents of media message.")
action:self.saveMediaActionSelector],
];
}
//- (NSArray<UIMenuItem *> *)mediaMenuControllerItems
//{
// return @[
// [[UIMenuItem alloc] initWithTitle:NSLocalizedString(@"EDIT_ITEM_MESSAGE_METADATA_ACTION",
// @"Short name for edit menu item to show message metadata.")
// action:self.metadataActionSelector],
// [[UIMenuItem alloc] initWithTitle:NSLocalizedString(@"EDIT_ITEM_COPY_ACTION",
// @"Short name for edit menu item to copy contents of media message.")
// action:self.copyMediaActionSelector],
// [[UIMenuItem alloc] initWithTitle:NSLocalizedString(@"REPLY_ITEM_ACTION",
// @"Short name for edit menu item to reply to a message.")
// action:self.replyActionSelector],
// [[UIMenuItem alloc] initWithTitle:NSLocalizedString(@"EDIT_ITEM_DELETE_ACTION",
// @"Short name for edit menu item to delete contents of media message.")
// action:self.deleteActionSelector],
// [[UIMenuItem alloc] initWithTitle:NSLocalizedString(@"EDIT_ITEM_SAVE_ACTION",
// @"Short name for edit menu item to save contents of media message.")
// action:self.saveMediaActionSelector],
// ];
//}
//
//- (NSArray<UIMenuItem *> *)defaultMenuControllerItems
//{
// return @[
// [[UIMenuItem alloc] initWithTitle:NSLocalizedString(@"EDIT_ITEM_MESSAGE_METADATA_ACTION",
// @"Short name for edit menu item to show message metadata.")
// action:self.metadataActionSelector],
// [[UIMenuItem alloc] initWithTitle:NSLocalizedString(@"REPLY_ITEM_ACTION",
// @"Short name for edit menu item to reply to a message.")
// action:self.replyActionSelector],
// [[UIMenuItem alloc] initWithTitle:NSLocalizedString(@"EDIT_ITEM_DELETE_ACTION",
// @"Short name for edit menu item to delete contents of media message.")
// action:self.deleteActionSelector],
// ];
//}
- (NSArray<UIMenuItem *> *)defaultMenuControllerItems
{
return @[
[[UIMenuItem alloc] initWithTitle:NSLocalizedString(@"EDIT_ITEM_MESSAGE_METADATA_ACTION",
@"Short name for edit menu item to show message metadata.")
action:self.metadataActionSelector],
[[UIMenuItem alloc] initWithTitle:NSLocalizedString(@"REPLY_ITEM_ACTION",
@"Short name for edit menu item to reply to a message.")
action:self.replyActionSelector],
[[UIMenuItem alloc] initWithTitle:NSLocalizedString(@"EDIT_ITEM_DELETE_ACTION",
@"Short name for edit menu item to delete contents of media message.")
action:self.deleteActionSelector],
];
}
- (SEL)copyTextActionSelector
{
return NSSelectorFromString(@"copyTextAction:");
}
- (SEL)copyMediaActionSelector
{
return NSSelectorFromString(@"copyMediaAction:");
}
- (SEL)saveMediaActionSelector
{
return NSSelectorFromString(@"saveMediaAction:");
}
- (SEL)shareTextActionSelector
{
return NSSelectorFromString(@"shareTextAction:");
}
- (SEL)shareMediaActionSelector
{
return NSSelectorFromString(@"shareMediaAction:");
}
- (SEL)deleteActionSelector
{
return NSSelectorFromString(@"deleteAction:");
}
- (SEL)replyActionSelector
{
return NSSelectorFromString(@"replyAction:");
}
- (SEL)metadataActionSelector
{
return NSSelectorFromString(@"metadataAction:");
}
//- (SEL)copyTextActionSelector
//{
// return NSSelectorFromString(@"copyTextAction:");
//}
//
//- (SEL)copyMediaActionSelector
//{
// return NSSelectorFromString(@"copyMediaAction:");
//}
//
//- (SEL)saveMediaActionSelector
//{
// return NSSelectorFromString(@"saveMediaAction:");
//}
//
//- (SEL)shareTextActionSelector
//{
// return NSSelectorFromString(@"shareTextAction:");
//}
//
//- (SEL)shareMediaActionSelector
//{
// return NSSelectorFromString(@"shareMediaAction:");
//}
//
//- (SEL)deleteActionSelector
//{
// return NSSelectorFromString(@"deleteAction:");
//}
//
//- (SEL)replyActionSelector
//{
// return NSSelectorFromString(@"replyAction:");
//}
//
//- (SEL)metadataActionSelector
//{
// return NSSelectorFromString(@"metadataAction:");
//}
// We only use custom actions in UIMenuController.
- (BOOL)canPerformAction:(SEL)action
{
if (action == self.copyTextActionSelector) {
return [self hasBodyTextActionContent];
} else if (action == self.copyMediaActionSelector) {
return [self hasMediaActionContent];
} else if (action == self.saveMediaActionSelector) {
return [self canSaveMedia];
} else if (action == self.shareTextActionSelector) {
return [self hasBodyTextActionContent];
} else if (action == self.shareMediaActionSelector) {
return [self hasMediaActionContent];
} else if (action == self.deleteActionSelector) {
return YES;
} else if (action == self.metadataActionSelector) {
return YES;
} else if (action == self.replyActionSelector) {
if ([self.interaction isKindOfClass:[TSOutgoingMessage class]]) {
TSOutgoingMessage *outgoingMessage = (TSOutgoingMessage *)self.interaction;
if (outgoingMessage.messageState == TSOutgoingMessageStateFailed
|| outgoingMessage.messageState == TSOutgoingMessageStateSending) {
// Don't let users reply to messages which aren't yet delivered to the service.
return NO;
}
} else if ([self.interaction isKindOfClass:[TSIncomingMessage class]]) {
TSIncomingMessage *incomingMessage = (TSIncomingMessage *)self.interaction;
if (incomingMessage.hasAttachments) {
NSString *attachmentId = incomingMessage.attachmentIds.firstObject;
__block TSAttachment *_Nullable attachment = nil;
[[OWSPrimaryStorage.sharedManager newDatabaseConnection]
readWithBlock:^(YapDatabaseReadTransaction *transaction) {
attachment = [TSAttachment fetchObjectWithUniqueID:attachmentId transaction:transaction];
}];
if (![attachment isKindOfClass:[TSAttachmentStream class]]) {
// Don't let users reply to attachments which aren't yet downloaded
// (or otherwise missing on disk).
return NO;
}
}
}
return YES;
} else {
return NO;
}
}
//- (BOOL)canPerformAction:(SEL)action
//{
// if (action == self.copyTextActionSelector) {
// return [self hasBodyTextActionContent];
// } else if (action == self.copyMediaActionSelector) {
// return [self hasMediaActionContent];
// } else if (action == self.saveMediaActionSelector) {
// return [self canSaveMedia];
// } else if (action == self.shareTextActionSelector) {
// return [self hasBodyTextActionContent];
// } else if (action == self.shareMediaActionSelector) {
// return [self hasMediaActionContent];
// } else if (action == self.deleteActionSelector) {
// return YES;
// } else if (action == self.metadataActionSelector) {
// return YES;
// } else if (action == self.replyActionSelector) {
// if ([self.interaction isKindOfClass:[TSOutgoingMessage class]]) {
// TSOutgoingMessage *outgoingMessage = (TSOutgoingMessage *)self.interaction;
// if (outgoingMessage.messageState == TSOutgoingMessageStateFailed
// || outgoingMessage.messageState == TSOutgoingMessageStateSending) {
// // Don't let users reply to messages which aren't yet delivered to the service.
// return NO;
// }
// } else if ([self.interaction isKindOfClass:[TSIncomingMessage class]]) {
// TSIncomingMessage *incomingMessage = (TSIncomingMessage *)self.interaction;
// if (incomingMessage.hasAttachments) {
// NSString *attachmentId = incomingMessage.attachmentIds.firstObject;
// __block TSAttachment *_Nullable attachment = nil;
// [[OWSPrimaryStorage.sharedManager newDatabaseConnection]
// readWithBlock:^(YapDatabaseReadTransaction *transaction) {
// attachment = [TSAttachment fetchObjectWithUniqueID:attachmentId transaction:transaction];
// }];
// if (![attachment isKindOfClass:[TSAttachmentStream class]]) {
// // Don't let users reply to attachments which aren't yet downloaded
// // (or otherwise missing on disk).
// return NO;
// }
// }
// }
// return YES;
// } else {
// return NO;
// }
//}
// TODO: Update for quoted text.
- (void)copyTextAction

View File

@ -372,28 +372,28 @@ NS_ASSUME_NONNULL_BEGIN
}
}
- (void)longPressGesture:(UIGestureRecognizer *)sender
{
// We "eagerly" respond when the long press begins, not when it ends.
if (sender.state == UIGestureRecognizerStateBegan) {
if (!self.viewItem) {
return;
}
[self.view becomeFirstResponder];
if ([UIMenuController sharedMenuController].isMenuVisible) {
[[UIMenuController sharedMenuController] setMenuVisible:NO animated:NO];
}
NSArray *menuItems = self.viewItem.mediaMenuControllerItems;
[UIMenuController sharedMenuController].menuItems = menuItems;
CGPoint location = [sender locationInView:self.view];
CGRect targetRect = CGRectMake(location.x, location.y, 1, 1);
[[UIMenuController sharedMenuController] setTargetRect:targetRect inView:self.view];
[[UIMenuController sharedMenuController] setMenuVisible:YES animated:YES];
}
}
//- (void)longPressGesture:(UIGestureRecognizer *)sender
//{
// // We "eagerly" respond when the long press begins, not when it ends.
// if (sender.state == UIGestureRecognizerStateBegan) {
// if (!self.viewItem) {
// return;
// }
//
// [self.view becomeFirstResponder];
//
// if ([UIMenuController sharedMenuController].isMenuVisible) {
// [[UIMenuController sharedMenuController] setMenuVisible:NO animated:NO];
// }
//
// NSArray *menuItems = self.viewItem.mediaMenuControllerItems;
// [UIMenuController sharedMenuController].menuItems = menuItems;
// CGPoint location = [sender locationInView:self.view];
// CGRect targetRect = CGRectMake(location.x, location.y, 1, 1);
// [[UIMenuController sharedMenuController] setTargetRect:targetRect inView:self.view];
// [[UIMenuController sharedMenuController] setMenuVisible:YES animated:YES];
// }
//}
- (void)didPressShare:(id)sender
{
@ -417,26 +417,26 @@ NS_ASSUME_NONNULL_BEGIN
[self.delegate mediaDetailViewController:self requestDeleteConversationViewItem:self.viewItem];
}
- (BOOL)canPerformAction:(SEL)action withSender:(nullable id)sender
{
if (self.viewItem == nil) {
return NO;
}
// Already in detail view, so no link to "info"
if (action == self.viewItem.metadataActionSelector) {
return NO;
}
// Reply is not supported from MediaDetailView.
// TODO implement a "scroll to message" action which would
// let users scroll back to the media message in their message history.
if (action == self.viewItem.replyActionSelector) {
return NO;
}
return [self.viewItem canPerformAction:action];
}
//- (BOOL)canPerformAction:(SEL)action withSender:(nullable id)sender
//{
// if (self.viewItem == nil) {
// return NO;
// }
//
// // Already in detail view, so no link to "info"
// if (action == self.viewItem.metadataActionSelector) {
// return NO;
// }
//
// // Reply is not supported from MediaDetailView.
// // TODO implement a "scroll to message" action which would
// // let users scroll back to the media message in their message history.
// if (action == self.viewItem.replyActionSelector) {
// return NO;
// }
//
// return [self.viewItem canPerformAction:action];
//}
- (void)copyMediaAction:(nullable id)sender
{

View File

@ -56,9 +56,8 @@ extension ConversationViewItem {
func textActions(delegate: MessageActionsDelegate) -> [MessageAction] {
var actions: [MessageAction] = []
// [[UIMenuItem alloc] initWithTitle:NSLocalizedString(@"EDIT_ITEM_MESSAGE_METADATA_ACTION",
// @"Short name for edit menu item to show message metadata.")
// action:self.metadataActionSelector],
let replyAction = MessageActionBuilder.reply(conversationViewItem: self, delegate: delegate)
actions.append(replyAction)
if self.hasBodyTextActionContent {
let copyTextAction = MessageActionBuilder.copyText(conversationViewItem: self, delegate: delegate)