ForwardMultipleURLActivity.m 4.5 KB

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