<commit_before>import React from 'react';
import {
  Alert,
  Platform,
} from 'react-native';

import { connect } from 'react-redux';
import FCM, {
  FCMEvent,
} from 'react-native-fcm';
import Permissions from 'react-native-permissions';

class PushNotificationContainer extends React.Component {
  componentDidMount() {
    this.checkPermission();

    // if we launch with a notification waiting for us
    // Note: Have to check what type of notification it is, especially on android, since some non-push things are notifications
    FCM.getInitialNotification().then((notif) => {
      console.log('launched w/notification waiting for us', notif);
    });

    this.notificationListener = FCM.on(FCMEvent.Notification, (notif) => {
      if (!notif) return; // make sure we get something

      console.log('got notification', notif);

      // there are two parts of notif. notif.notification contains the notification payload, notif.data contains data payload
      if (notif.local_notification) {
        // this is a local notification
        return;
      }
      if (notif.opened_from_tray) {
        // app is open/resumed because user clicked banner
        return;
      }

      // if app is already open, show a local notification with the same info
      this.showLocalNotification(notif);
    });
    this.refreshTokenListener = FCM.on(FCMEvent.RefreshToken, (token) => {
      this.updateServerToken(token);
      // fcm token may not be available on first load, catch it here
    });
  }

  componentWillUnmount() {
    // stop listening for events
    this.notificationListener.remove();
    this.refreshTokenListener.remove();
  }

  getNotificationToken = () => {
    FCM.getFCMToken().then((token) => {
      this.updateServerToken(token);
    });
  }

  getSoftPermission = () => {
    Alert.alert(
      'Allow this app to send you notifications?',
      'We need access so we can keep you informed.',
      [
        { text: 'No', onPress: () => {} },
        { text: 'Yes', onPress: this.getPermission }
      ]
    );
  }

  getPermission = () => {
    Permissions.requestPermission('notification')
    .then((response) => {
      // if authorized, act
      if (response === 'authorized') {
        this.getNotificationToken();
      }
    })
    .catch(logger.error);
  }

  showLocalNotification = (notif) => {
    // NOTE: will not work until we configure local notifications
    if (notif && notif.notification) {
      FCM.presentLocalNotification({<commit_msg>Resolve promise warning from err catch<commit_after>import React from 'react';
import {
  Alert,
  Platform,
} from 'react-native';

import { connect } from 'react-redux';
import FCM, {
  FCMEvent,
} from 'react-native-fcm';
import Permissions from 'react-native-permissions';

class PushNotificationContainer extends React.Component {
  componentDidMount() {
    this.checkPermission();

    // if we launch with a notification waiting for us
    // Note: Have to check what type of notification it is, especially on android, since some non-push things are notifications
    FCM.getInitialNotification().then((notif) => {
      console.log('launched w/notification waiting for us', notif);
    });

    this.notificationListener = FCM.on(FCMEvent.Notification, (notif) => {
      if (!notif) return; // make sure we get something

      console.log('got notification', notif);

      // there are two parts of notif. notif.notification contains the notification payload, notif.data contains data payload
      if (notif.local_notification) {
        // this is a local notification
        return;
      }
      if (notif.opened_from_tray) {
        // app is open/resumed because user clicked banner
        return;
      }

      // if app is already open, show a local notification with the same info
      this.showLocalNotification(notif);
    });
    this.refreshTokenListener = FCM.on(FCMEvent.RefreshToken, (token) => {
      this.updateServerToken(token);
      // fcm token may not be available on first load, catch it here
    });
  }

  componentWillUnmount() {
    // stop listening for events
    this.notificationListener.remove();
    this.refreshTokenListener.remove();
  }

  getNotificationToken = () => {
    FCM.getFCMToken().then((token) => {
      this.updateServerToken(token);
    });
  }

  getSoftPermission = () => {
    Alert.alert(
      'Allow this app to send you notifications?',
      'We need access so we can keep you informed.',
      [
        { text: 'No', onPress: () => {} },
        { text: 'Yes', onPress: this.getPermission }
      ]
    );
  }

  getPermission = () => {
    Permissions.requestPermission('notification')
    .then((response) => {
      // if authorized, act
      if (response === 'authorized') {
        this.getNotificationToken();
      }
    })
  }

  showLocalNotification = (notif) => {
    // NOTE: will not work until we configure local notifications
    if (notif && notif.notification) {
      FCM.presentLocalNotification({
{'fraction_non_alphanumeric': 0.11671671671671671, 'fraction_numerical': 0.0, 'mean_word_length': 2.828352490421456, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 23, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '4881389', 'n_tokens_mistral': 1413, 'n_tokens_neox': 1377, 'n_words': 405}