add text reply action, comment out more deprecated uimenu code

pull/1/head
Michael Kirk 7 years ago
parent 6079ae2439
commit 2552368146

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

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

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

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

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

Loading…
Cancel
Save