FeatureMaskChecker.m 3.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081
  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 "FeatureMaskChecker.h"
  21. #import "FeatureMask.h"
  22. #import "BundleUtil.h"
  23. #import "Utils.h"
  24. #import "ProtocolDefines.h"
  25. #import "Conversation.h"
  26. #import "AppDelegate.h"
  27. typedef void (^CompletionBlock)(void);
  28. static FeatureMaskChecker *strongReference;
  29. @interface FeatureMaskChecker ()
  30. @property BOOL hasValidContacts;
  31. @property (copy) CompletionBlock onSuccess;
  32. @property (copy) CompletionBlock onFailure;
  33. @end
  34. @implementation FeatureMaskChecker
  35. - (void)checkFileTransferFor:(NSSet *)conversations presentAlarmOn:(UIViewController *)viewController onSuccess:(void (^)(void))onSuccess onFailure:(void (^)(void))onFailure{
  36. _onSuccess = onSuccess;
  37. _onFailure = onFailure;
  38. [FeatureMask checkFeatureMask:FEATURE_MASK_FILE_TRANSFER forConversations:conversations onCompletion:^(NSArray *unsupportedContacts) {
  39. if ([unsupportedContacts count] > 0) {
  40. NSMutableSet *allContacts = [NSMutableSet set];
  41. for (Conversation *conversation in conversations) {
  42. [allContacts addObjectsFromArray:conversation.participants.allObjects];
  43. }
  44. NSString *messageFormat;
  45. if ([unsupportedContacts count] == [allContacts count]) {
  46. _hasValidContacts = NO;
  47. messageFormat = [BundleUtil localizedStringForKey:@"error_message_none_feature_level"];
  48. } else {
  49. _hasValidContacts = YES;
  50. messageFormat = [BundleUtil localizedStringForKey:@"error_message_feature_level"];
  51. }
  52. NSString *participantNames = [Utils stringFromContacts:unsupportedContacts];
  53. NSString *message = [NSString stringWithFormat:messageFormat, participantNames];
  54. NSString *title = [BundleUtil localizedStringForKey:@"error_title_feature_level"];
  55. [UIAlertTemplate showAlertWithOwner:[[AppDelegate sharedAppDelegate] currentTopViewController] title:title message:message actionOk:^(UIAlertAction * _Nonnull okAction) {
  56. if (_hasValidContacts) {
  57. _onSuccess();
  58. } else {
  59. _onFailure();
  60. }
  61. }];
  62. } else {
  63. _onSuccess();
  64. }
  65. }];
  66. }
  67. @end