mattermost-mobile/app/mattermost_managed/mattermost-managed.ios.js
Elias Nahum 8e0d167f95 Fix push notification and emm race conditions (#1691)
* Fix push notification and emm race conditions

* feedback review

* Removed unnecesary code
2018-05-22 11:02:14 -04:00

75 lines
2.1 KiB
JavaScript

// Copyright (c) 2017-present Mattermost, Inc. All Rights Reserved.
// See License.txt for license information.
import {NativeModules, DeviceEventEmitter} from 'react-native';
import LocalAuth from 'react-native-local-auth';
import JailMonkey from 'jail-monkey';
const {BlurAppScreen, MattermostManaged} = NativeModules;
const listeners = [];
let localConfig;
export default {
addEventListener: (name, callback) => {
const listener = DeviceEventEmitter.addListener(name, (config) => {
localConfig = config;
if (callback && typeof callback === 'function') {
callback(config);
}
});
listeners.push(listener);
return listener;
},
clearListeners: () => {
listeners.forEach((listener) => {
listener.remove();
});
},
removeEventListener: (listenerId) => {
const index = listeners.findIndex((listener) => listener === listenerId);
if (index !== -1) {
listenerId.remove();
listeners.splice(index, 1);
}
},
authenticate: LocalAuth.authenticate,
blurAppScreen: BlurAppScreen.enabled,
getConfig: async () => {
return {
inAppPinCode: 'true',
blurApplicationScreen: 'true',
jailbreakDetection: 'true',
allowOtherServers: 'true',
vendor: 'Local Test',
serverUrl: 'http://192.168.0.18:8065',
username: 'elias',
};
},
getLocalConfig: async () => {
if (!localConfig) {
try {
localConfig = await MattermostManaged.getConfig();
} catch (error) {
// do nothing...
}
}
return localConfig || {};
},
isDeviceSecure: async () => {
try {
return await LocalAuth.isDeviceSecure();
} catch (err) {
return false;
}
},
isTrustedDevice: () => {
if (__DEV__) { //eslint-disable-line no-undef
return true;
}
return JailMonkey.trustFall();
},
quitApp: MattermostManaged.quitApp,
};