mattermost-mobile/app/notification_preferences/notification_preferences.android.js
Jesse Hallam 58b72302d6 update eslint's comma-dangle rule to always-multiline (#1457)
* update eslint's `comma-dangle` rule to `always-multiline`

* add check and fix scripts to package.json

* Invoke `yarn fix` to adopt the updated eslint rules. No other changes are included.
2018-02-23 09:06:02 -05:00

38 lines
1.2 KiB
JavaScript

// Copyright (c) 2017-present Mattermost, Inc. All Rights Reserved.
// See License.txt for license information.
import {NativeModules, PermissionsAndroid} from 'react-native';
const {NotificationPreferences} = NativeModules;
const defaultPreferences = {
sounds: [],
shouldBlink: false,
shouldVibrate: true,
};
export default {
getPreferences: async () => {
try {
const hasPermission = await PermissionsAndroid.check(PermissionsAndroid.PERMISSIONS.READ_EXTERNAL_STORAGE);
let granted;
if (!hasPermission) {
granted = await PermissionsAndroid.request(
PermissionsAndroid.PERMISSIONS.READ_EXTERNAL_STORAGE
);
}
if (hasPermission || granted === PermissionsAndroid.RESULTS.GRANTED) {
return await NotificationPreferences.getPreferences();
}
return defaultPreferences;
} catch (error) {
return defaultPreferences;
}
},
setNotificationSound: NotificationPreferences.setNotificationSound,
setShouldVibrate: NotificationPreferences.setShouldVibrate,
setShouldBlink: NotificationPreferences.setShouldBlink,
play: NotificationPreferences.previewSound,
};