"Fossies" - the Fresh Open Source Software Archive

Member "jitsi-meet-5079/ios/sdk/src/dropbox/Dropbox.m" (17 Jun 2021, 5791 Bytes) of package /linux/misc/jitsi-meet-5079.tar.gz:


As a special service "Fossies" has tried to format the requested source page into HTML format using (guessed) Matlab source code syntax highlighting (style: standard) with prefixed line numbers. Alternatively you can here view or download the uninterpreted source code file.

    1 /*
    2  * Copyright @ 2017-present Atlassian Pty Ltd
    3  *
    4  * Licensed under the Apache License, Version 2.0 (the "License");
    5  * you may not use this file except in compliance with the License.
    6  * You may obtain a copy of the License at
    7  *
    8  *     http://www.apache.org/licenses/LICENSE-2.0
    9  *
   10  * Unless required by applicable law or agreed to in writing, software
   11  * distributed under the License is distributed on an "AS IS" BASIS,
   12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
   13  * See the License for the specific language governing permissions and
   14  * limitations under the License.
   15  */
   16 
   17 #import <React/RCTBridgeModule.h>
   18 #import <ObjectiveDropboxOfficial/ObjectiveDropboxOfficial.h>
   19 
   20 #import "Dropbox.h"
   21 
   22 RCTPromiseResolveBlock currentResolve = nil;
   23 RCTPromiseRejectBlock currentReject = nil;
   24 
   25 @implementation Dropbox
   26 
   27 + (NSString *)getAppKey{
   28     NSArray *urlTypes
   29         = [[NSBundle mainBundle] objectForInfoDictionaryKey:@"CFBundleURLTypes"];
   30 
   31     for (NSDictionary<NSString *, NSArray *> *urlType in urlTypes) {
   32         NSArray *urlSchemes = urlType[@"CFBundleURLSchemes"];
   33 
   34         if (urlSchemes) {
   35             for (NSString *urlScheme in urlSchemes) {
   36                 if (urlScheme && [urlScheme hasPrefix:@"db-"]) {
   37                     return [urlScheme substringFromIndex:3];
   38                 }
   39             }
   40         }
   41     }
   42    
   43     return nil;
   44 }
   45 
   46 RCT_EXPORT_MODULE();
   47 
   48 + (BOOL)requiresMainQueueSetup {
   49     return NO;
   50 }
   51 
   52 - (NSDictionary *)constantsToExport {
   53     BOOL enabled = [Dropbox getAppKey] != nil;
   54     
   55     return @{
   56         @"ENABLED": [NSNumber numberWithBool:enabled]
   57     };
   58 };
   59 
   60 RCT_EXPORT_METHOD(authorize:(RCTPromiseResolveBlock)resolve
   61                   reject:(__unused RCTPromiseRejectBlock)reject) {
   62     currentResolve = resolve;
   63     currentReject = reject;
   64     
   65     dispatch_async(dispatch_get_main_queue(), ^{
   66         [DBClientsManager authorizeFromController:[UIApplication sharedApplication]
   67                                        controller:[[self class] topMostController]
   68                                           openURL:^(NSURL *url) {
   69                                               [[UIApplication sharedApplication] openURL:url options:@{} completionHandler:nil];
   70                                           }];
   71     });
   72 }
   73 
   74 RCT_EXPORT_METHOD(getDisplayName: (NSString *)token
   75                   resolve: (RCTPromiseResolveBlock)resolve
   76                   reject:(RCTPromiseRejectBlock)reject) {
   77     DBUserClient *client = [[DBUserClient alloc] initWithAccessToken:token];
   78     [[client.usersRoutes getCurrentAccount] setResponseBlock:^(DBUSERSFullAccount *result, DBNilObject *routeError, DBRequestError *networkError) {
   79         if (result) {
   80             resolve(result.name.displayName);
   81         } else {
   82             NSString *msg = @"Failed!";
   83             if (networkError) {
   84                 msg = [NSString stringWithFormat:@"Failed! Error: %@", networkError];
   85             }
   86             reject(@"getDisplayName", @"Failed", nil);
   87         }
   88     }];
   89 
   90 }
   91 
   92 RCT_EXPORT_METHOD(getSpaceUsage: (NSString *)token
   93                   resolve: (RCTPromiseResolveBlock)resolve
   94                   reject:(RCTPromiseRejectBlock)reject) {
   95     DBUserClient *client = [[DBUserClient alloc] initWithAccessToken:token];
   96     [[client.usersRoutes getSpaceUsage] setResponseBlock:^(DBUSERSSpaceUsage *result, DBNilObject *routeError, DBRequestError *networkError) {
   97         if (result) {
   98             DBUSERSSpaceAllocation *allocation = result.allocation;
   99             NSNumber *allocated = 0;
  100             NSNumber *used = 0;
  101             if ([allocation isIndividual]) {
  102                 allocated = allocation.individual.allocated;
  103                 used = result.used;
  104             } else if ([allocation isTeam]) {
  105                 allocated = allocation.team.allocated;
  106                 used = allocation.team.used;
  107             }
  108             id objects[] = { used, allocated };
  109             id keys[] = { @"used", @"allocated" };
  110             NSDictionary *dictionary = [NSDictionary dictionaryWithObjects:objects
  111                                             forKeys:keys
  112                                             count:2];
  113             resolve(dictionary);
  114         } else {
  115             NSString *msg = @"Failed!";
  116             if (networkError) {
  117                 msg = [NSString stringWithFormat:@"Failed! Error: %@", networkError];
  118             }
  119             reject(@"getSpaceUsage", msg, nil);
  120         }
  121     }];
  122 
  123 }
  124 
  125 + (BOOL)application:(UIApplication *)app
  126             openURL:(NSURL *)url
  127             options:(NSDictionary<UIApplicationOpenURLOptionsKey,id> *)options {
  128     if (currentReject == nil || currentResolve == nil) {
  129         return NO;
  130     }
  131     DBOAuthResult *authResult = [DBClientsManager handleRedirectURL:url];
  132     if (authResult) {
  133         if ([authResult isSuccess]) {
  134             currentResolve(authResult.accessToken.accessToken);
  135         } else {
  136             NSString *msg;
  137             if ([authResult isError]) {
  138                 msg = [NSString stringWithFormat:@"%@, error type: %zd",[authResult errorDescription], [authResult errorType]];
  139             } else {
  140                 msg = @"OAuth canceled!";
  141             }
  142             currentReject(@"authorize", msg, nil);
  143         }
  144         currentResolve = nil;
  145         currentReject = nil;
  146 
  147         return YES;
  148     }
  149     return NO;
  150 }
  151 
  152 + (UIViewController *)topMostController {
  153     UIViewController *topController
  154         = [UIApplication sharedApplication].keyWindow.rootViewController;
  155     
  156     while (topController.presentedViewController) {
  157         topController = topController.presentedViewController;
  158     }
  159     
  160     return topController;
  161 }
  162 
  163 + (void)setAppKey {
  164     NSString *appKey = [self getAppKey];
  165 
  166     if (appKey) {
  167         [DBClientsManager setupWithAppKey:appKey];
  168     }
  169 }
  170 
  171 @end