<commit_before>import React from "react-native";
import StartDiscussion from "../views/StartDiscussion";
import Container from "./Container";
import Facebook from "../modules/Facebook";
import generate from "../lib/generate.browser";
import url from "../lib/url";

const {
	ToastAndroid
} = React;

const PERMISSION_PUBLISH_ACTIONS = "publish_actions";
const PERMISSION_PUBLISH_ERROR = "REQUEST_PERMISSION_ERROR";

class StartDiscussionContainer extends React.Component {
	_getPublishPermissions = async () => {
		const result = await Facebook.logInWithPublishPermissions([ PERMISSION_PUBLISH_ACTIONS ]);

		if (result.permissions_granted.indexOf(PERMISSION_PUBLISH_ACTIONS) === -1) {
			throw new Error(PERMISSION_PUBLISH_ERROR);
		}

		return result;
	};

	_isFacebookPermissionGranted = async () => {
		try {
			const token = await Facebook.getCurrentAccessToken();

			return token.permissions_granted.indexOf(PERMISSION_PUBLISH_ACTIONS) > -1;
		} catch (err) {
			return false;
		}
	};

	_requestFacebookPermissions = async () => {
		try {
			const granted = await this._isFacebookPermissionGranted();

			if (!granted) {
				await this._getPublishPermissions();
			}
		} catch (err) {
			if (err.message === PERMISSION_PUBLISH_ERROR) {
				throw err;
			} else {
				await this._getPublishPermissions();
			}
		}
	};
<commit_msg>Fix requesting permission<commit_after>import React from "react-native";
import StartDiscussion from "../views/StartDiscussion";
import Container from "./Container";
import Facebook from "../modules/Facebook";
import generate from "../lib/generate.browser";
import url from "../lib/url";

const {
	ToastAndroid
} = React;

const PERMISSION_PUBLISH_ACTIONS = "publish_actions";
const PERMISSION_PUBLISH_ERROR = "REQUEST_PERMISSION_ERROR";

class StartDiscussionContainer extends React.Component {
	_getPublishPermissions = async () => {
		const result = await Facebook.logInWithPublishPermissions([ PERMISSION_PUBLISH_ACTIONS ]);

		if (result.permissions_granted.indexOf(PERMISSION_PUBLISH_ACTIONS) === -1) {
			throw new Error(PERMISSION_PUBLISH_ERROR);
		}

		return result;
	};

	_isFacebookPermissionGranted = async () => {
		try {
			const token = await Facebook.getCurrentAccessToken();

			return token.permissions_granted.indexOf(PERMISSION_PUBLISH_ACTIONS) > -1;
		} catch (err) {
			return false;
		}
	};

	_requestFacebookPermissions = async () => {
		let requested;

		try {
			const granted = await this._isFacebookPermissionGranted();

			if (!granted) {
				requested = true;
				await this._getPublishPermissions();
			}
		} catch (err) {
			if (requested) {
				throw err;
			} else {
				await this._getPublishPermissions();
			}
		}
	};

{'fraction_non_alphanumeric': 0.115570419918246, 'fraction_numerical': 0.0014864362690449647, 'mean_word_length': 4.42741935483871, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 11, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 14, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '1999761', 'n_tokens_mistral': 945, 'n_tokens_neox': 820, 'n_words': 179}