ForwardTextActivity.m 3.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105
  1. // _____ _
  2. // |_ _| |_ _ _ ___ ___ _ __ __ _
  3. // | | | ' \| '_/ -_) -_) ' \/ _` |_
  4. // |_| |_||_|_| \___\___|_|_|_\__,_(_)
  5. //
  6. // Threema iOS Client
  7. // Copyright (c) 2015-2020 Threema GmbH
  8. //
  9. // This program is free software: you can redistribute it and/or modify
  10. // it under the terms of the GNU Affero General Public License, version 3,
  11. // as published by the Free Software Foundation.
  12. //
  13. // This program is distributed in the hope that it will be useful,
  14. // but WITHOUT ANY WARRANTY; without even the implied warranty of
  15. // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  16. // GNU Affero General Public License for more details.
  17. //
  18. // You should have received a copy of the GNU Affero General Public License
  19. // along with this program. If not, see <https://www.gnu.org/licenses/>.
  20. #import "ForwardTextActivity.h"
  21. #import "ContactGroupPickerViewController.h"
  22. #import "Contact.h"
  23. #import "GroupProxy.h"
  24. #import "MessageSender.h"
  25. #import "EntityManager.h"
  26. @interface ForwardTextActivity () <ContactGroupPickerDelegate, ModalNavigationControllerDelegate>
  27. @property NSString *text;
  28. @end
  29. @implementation ForwardTextActivity
  30. + (UIActivityCategory)activityCategory {
  31. return UIActivityCategoryAction;
  32. }
  33. - (NSString *)activityType {
  34. return APP_ID ".forwardMsg";
  35. }
  36. - (NSString *)activityTitle {
  37. return NSLocalizedString(@"forward", nil);
  38. }
  39. - (UIImage *)activityImage {
  40. return [UIImage imageNamed:@"ShareForward"];
  41. }
  42. - (BOOL)canPerformWithActivityItems:(NSArray *)activityItems {
  43. if (activityItems.count != 1) {
  44. return NO;
  45. }
  46. return [activityItems[0] isKindOfClass:[NSString class]];
  47. }
  48. - (void)prepareWithActivityItems:(NSArray *)activityItems {
  49. _text = activityItems[0];
  50. }
  51. - (UIViewController *)activityViewController {
  52. ModalNavigationController *navigationController = [ContactGroupPickerViewController pickerFromStoryboardWithDelegate:self];
  53. return navigationController;
  54. }
  55. - (void)sendMessageToConversation:(Conversation *)conversation {
  56. [MessageSender sendMessage:_text inConversation:conversation async:YES quickReply:NO requestId:nil onCompletion:^(TextMessage *message, Conversation *conv) {
  57. ;//nop
  58. }];
  59. }
  60. #pragma mark - ContactPickerDelegate
  61. - (void)contactPicker:(ContactGroupPickerViewController*)contactPicker didPickConversations:(NSSet *)conversations renderType:(NSNumber *)renderType sendAsFile:(BOOL)sendAsFile {
  62. for (Conversation *conversation in conversations) {
  63. [self sendMessageToConversation:conversation];
  64. if (contactPicker.additionalTextToSend) {
  65. [MessageSender sendMessage:contactPicker.additionalTextToSend inConversation:conversation async:YES quickReply:NO requestId:nil onCompletion:^(TextMessage *message, Conversation *conv) {
  66. ;//nop
  67. }];
  68. }
  69. }
  70. [contactPicker dismissViewControllerAnimated:YES completion:nil];
  71. }
  72. - (void)contactPickerDidCancel:(ContactGroupPickerViewController*)contactPicker {
  73. [contactPicker dismissViewControllerAnimated:YES completion:nil];
  74. }
  75. - (void)contactPicker:(ContactGroupPickerViewController *)contactPicker addText:(NSString *)text {
  76. }
  77. #pragma mark - ModalNavigationControllerDelegate
  78. - (void)willDismissModalNavigationController {
  79. }
  80. @end