ForwardURLActivity.m 3.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122
  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 "ForwardURLActivity.h"
  21. #import "ContactGroupPickerViewController.h"
  22. #import "MessageSender.h"
  23. #import "ModalNavigationController.h"
  24. #import "FeatureMaskChecker.h"
  25. #import "UTIConverter.h"
  26. #import "FileMessageSender.h"
  27. @interface ForwardURLActivity () <ContactGroupPickerDelegate, ModalNavigationControllerDelegate>
  28. @property NSURL *url;
  29. @property NSNumber *renderType;
  30. @end
  31. @implementation ForwardURLActivity
  32. + (UIActivityCategory)activityCategory {
  33. return UIActivityCategoryAction;
  34. }
  35. - (NSString *)activityType {
  36. return APP_ID ".forwardMsg";
  37. }
  38. - (NSString *)activityTitle {
  39. return NSLocalizedString(@"forward", nil);
  40. }
  41. - (UIImage *)activityImage {
  42. return [UIImage imageNamed:@"ShareForward"];
  43. }
  44. - (BOOL)canPerformWithActivityItems:(NSArray *)activityItems {
  45. if (activityItems.count != 1) {
  46. return NO;
  47. }
  48. id item = activityItems[0];
  49. if ([item isKindOfClass:[NSURL class]]) {
  50. return YES;
  51. }
  52. if ([item isKindOfClass:[NSDictionary class]]) {
  53. NSDictionary *itemDict = (NSDictionary *)item;
  54. if ([itemDict[@"url"] isKindOfClass:[NSURL class]]) {
  55. return YES;
  56. }
  57. }
  58. return NO;
  59. }
  60. - (void)prepareWithActivityItems:(NSArray *)activityItems {
  61. if ([activityItems[0] isKindOfClass:[NSDictionary class]]) {
  62. NSDictionary *itemDict = (NSDictionary *)activityItems[0];
  63. if ([itemDict[@"url"] isKindOfClass:[NSURL class]]) {
  64. _url = itemDict[@"url"];
  65. _renderType = itemDict[@"renderType"];
  66. }
  67. } else {
  68. _url = activityItems[0];
  69. _renderType = @0;
  70. }
  71. }
  72. - (UIViewController *)activityViewController {
  73. ModalNavigationController *navigationController = [ContactGroupPickerViewController pickerFromStoryboardWithDelegate:self];
  74. ContactGroupPickerViewController *picker = (ContactGroupPickerViewController *)navigationController.topViewController;
  75. picker.enableMulitSelection = true;
  76. picker.enableTextInput = true;
  77. picker.submitOnSelect = false;
  78. picker.renderType = _renderType;
  79. return navigationController;
  80. }
  81. #pragma mark - ContactPickerDelegate
  82. - (void)contactPicker:(ContactGroupPickerViewController*)contactPicker didPickConversations:(NSSet *)conversations renderType:(NSNumber *)renderType sendAsFile:(BOOL)sendAsFile {
  83. FeatureMaskChecker *featureMaskChecker = [[FeatureMaskChecker alloc] init];
  84. [featureMaskChecker checkFileTransferFor:conversations presentAlarmOn:contactPicker onSuccess:^{
  85. for (Conversation *conversation in conversations) {
  86. [URLSender sendUrl:_url asFile:sendAsFile caption:contactPicker.additionalTextToSend conversation:conversation];
  87. }
  88. [contactPicker dismissViewControllerAnimated:YES completion:nil];
  89. } onFailure:^{
  90. [contactPicker dismissViewControllerAnimated:YES completion:nil];
  91. }];
  92. }
  93. - (void)contactPickerDidCancel:(ContactGroupPickerViewController*)contactPicker {
  94. [contactPicker dismissViewControllerAnimated:YES completion:nil];
  95. }
  96. #pragma mark - ModalNavigationControllerDelegate
  97. - (void)willDismissModalNavigationController {
  98. }
  99. @end