2018-09-25 00:08:55 +00:00
|
|
|
import { NativeModules } from 'react-native';
|
|
|
|
|
2022-11-10 08:45:56 +00:00
|
|
|
import { IReduxState } from '../app/types';
|
|
|
|
// eslint-disable-next-line lines-around-comment
|
|
|
|
// @ts-ignore
|
2022-06-21 05:49:46 +00:00
|
|
|
import { setPictureInPictureEnabled } from '../mobile/picture-in-picture/functions';
|
2021-09-14 09:37:08 +00:00
|
|
|
|
2022-11-10 08:45:56 +00:00
|
|
|
const { Dropbox } = NativeModules;
|
|
|
|
|
2018-09-26 17:57:58 +00:00
|
|
|
/**
|
|
|
|
* Action to authorize the Jitsi Recording app in dropbox.
|
|
|
|
*
|
2022-11-10 08:45:56 +00:00
|
|
|
* @param {any} _appKey - Used on web.
|
|
|
|
* @param {any} _redirectURI - Used on web.
|
2021-09-01 12:21:03 +00:00
|
|
|
* @returns {Promise<Object>} - The promise will be resolved with the dropbox
|
2018-09-26 17:57:58 +00:00
|
|
|
* access token or rejected with an error.
|
|
|
|
*/
|
2022-11-10 08:45:56 +00:00
|
|
|
export async function _authorizeDropbox(_appKey?: any, _redirectURI?: any): Promise<any> {
|
2022-06-21 05:49:46 +00:00
|
|
|
setPictureInPictureEnabled(false);
|
2021-09-14 09:37:08 +00:00
|
|
|
|
|
|
|
try {
|
|
|
|
return await Dropbox.authorize();
|
|
|
|
} finally {
|
2022-06-21 05:49:46 +00:00
|
|
|
setPictureInPictureEnabled(true);
|
2021-09-14 09:37:08 +00:00
|
|
|
}
|
2021-09-01 12:21:03 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
2022-07-14 07:10:08 +00:00
|
|
|
* Gets a new access token based on the refresh token.
|
2021-09-01 12:21:03 +00:00
|
|
|
*
|
|
|
|
* @returns {Promise}
|
|
|
|
*/
|
|
|
|
export function getNewAccessToken() {
|
|
|
|
return _authorizeDropbox();
|
2018-09-26 17:57:58 +00:00
|
|
|
}
|
|
|
|
|
2018-09-25 00:08:55 +00:00
|
|
|
/**
|
|
|
|
* Returns the display name for the current dropbox account.
|
|
|
|
*
|
|
|
|
* @param {string} token - The dropbox access token.
|
2022-11-10 08:45:56 +00:00
|
|
|
* @param {any} _appKey - Used on web.
|
2018-09-25 00:08:55 +00:00
|
|
|
* @returns {Promise<string>} - The promise will be resolved with the display
|
|
|
|
* name or rejected with an error.
|
|
|
|
*/
|
2022-11-10 08:45:56 +00:00
|
|
|
export function getDisplayName(token: string, _appKey?: any) {
|
2018-09-25 00:08:55 +00:00
|
|
|
return Dropbox.getDisplayName(token);
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Returns information about the space usage for the current dropbox account.
|
|
|
|
*
|
|
|
|
* @param {string} token - The dropbox access token.
|
2022-11-10 08:45:56 +00:00
|
|
|
* @param {any} _appKey - Used on web.
|
2018-09-25 00:08:55 +00:00
|
|
|
* @returns {Promise<{ used: number, allocated: number}>} - The promise will be
|
|
|
|
* resolved with the object with information about the space usage (the used
|
|
|
|
* space and the allocated space) for the current dropbox account or rejected
|
|
|
|
* with an error.
|
|
|
|
*/
|
2022-11-10 08:45:56 +00:00
|
|
|
export function getSpaceUsage(token: string, _appKey?: any) {
|
2018-09-25 00:08:55 +00:00
|
|
|
return Dropbox.getSpaceUsage(token);
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Returns <tt>true</tt> if the dropbox features is enabled and <tt>false</tt>
|
|
|
|
* otherwise.
|
|
|
|
*
|
2019-03-11 16:17:21 +00:00
|
|
|
* @param {Object} state - The redux state.
|
2018-09-25 00:08:55 +00:00
|
|
|
* @returns {boolean}
|
|
|
|
*/
|
2022-11-10 08:45:56 +00:00
|
|
|
export function isEnabled(state: IReduxState) {
|
2019-03-11 16:17:21 +00:00
|
|
|
const { dropbox = {} } = state['features/base/config'];
|
|
|
|
|
2022-11-10 08:45:56 +00:00
|
|
|
// @ts-ignore
|
2022-08-01 15:15:59 +00:00
|
|
|
return Boolean(Dropbox?.ENABLED && typeof dropbox.appKey === 'string');
|
2018-09-25 00:08:55 +00:00
|
|
|
}
|