<commit_before>package io.scrollback.neighborhoods.modules.facebook;

import android.app.Activity;
import android.content.Intent;

import com.facebook.AccessToken;
import com.facebook.CallbackManager;
import com.facebook.FacebookCallback;
import com.facebook.FacebookException;
import com.facebook.FacebookSdk;
import com.facebook.login.LoginManager;
import com.facebook.login.LoginResult;
import com.facebook.react.bridge.Arguments;
import com.facebook.react.bridge.Promise;
import com.facebook.react.bridge.ReactApplicationContext;
import com.facebook.react.bridge.ReactContextBaseJavaModule;
import com.facebook.react.bridge.ReactMethod;
import com.facebook.react.bridge.ReadableArray;
import com.facebook.react.bridge.WritableArray;
import com.facebook.react.bridge.WritableMap;

import java.util.ArrayList;
import java.util.List;
import java.util.Set;

public class FacebookLoginModule extends ReactContextBaseJavaModule {

    private Activity mCurrentActivity;
    private CallbackManager mCallbackManager;
    private Promise mTokenPromise;

    public FacebookLoginModule(ReactApplicationContext reactContext, Activity activity) {
        super(reactContext);

        mCurrentActivity = activity;

        FacebookSdk.sdkInitialize(reactContext.getApplicationContext());

        mCallbackManager = CallbackManager.Factory.create();

        LoginManager.getInstance().registerCallback(mCallbackManager,
                new FacebookCallback<LoginResult>() {
                    @Override
                    public void onSuccess(final LoginResult loginResult) {
                        if (mTokenPromise != null) {
                            WritableMap map = Arguments.createMap();

                            map.putString("token", loginResult.getAccessToken().getToken());

                            WritableMap permissions = Arguments.createMap();

                            permissions.putArray("granted", permissionsToWritableArray(loginResult.getRecentlyGrantedPermissions()));
                            permissions.putArray("denied", permissionsToWritableArray(loginResult.getRecentlyDeniedPermissions()));

                            map.putMap("permissions", permissions);

                            resolvePromise(map);
                        }
                    }

                    @Override
                    public void onCancel() {
                        if (mTokenPromise != null) {
                            rejectPromise("Login was cancelled");
                        }
                    }

                    @Override
                    public void onError(FacebookException exception) {
                        if (mTokenPromise != null) {
                            rejectPromise(exception.getMessage());
                        }
                    }
                });
    }

    private void resolvePromise(WritableMap map) {
        if (mTokenPromise != null) {
            mTokenPromise.resolve(map);
            mTokenPromise = null;
        }
    }

    private void rejectPromise(String reason) {
        if (mTokenPromise != null) {
            mTokenPromise.reject(reason);
            mTokenPromise = null;
        }
    }

    private List<String> readableArrayToStringList(final ReadableArray array) {
        List<String> stringList = new ArrayList<>();

        for (int i = 0, l = array.size(); i < l; i++) {
            stringList.add(array.getString(i));
        }

        return stringList;
    }

    private WritableArray permissionsToWritableArray(Set<String> permissions) {
        WritableArray result = Arguments.createArray();

        for(String p: permissions) {
            result.pushString(p);
        }

        return result;
    }

    @Override
    public String getName() {
        return "FacebookLoginModule";
    }

    public void registerPermissionCallback(final Promise promise) {
        if (mTokenPromise != null) {
            rejectPromise("Cannot register multiple callbacks");
        }

        mTokenPromise = promise;
    }

    @ReactMethod
    public void logInWithReadPermissions(final ReadableArray permissions, final Promise promise) {
        registerPermissionCallback(promise);

        LoginManager.getInstance().logInWithReadPermissions(
                mCurrentActivity,
                readableArrayToStringList(permissions));
    }

    @ReactMethod
    public void logInWithPubishPermissions(final ReadableArray permissions, final Promise promise) {
        registerPermissionCallback(promise);

        LoginManager.getInstance().logInWithPublishPermissions(
                mCurrentActivity,
                readableArrayToStringList(permissions));
    }

    @ReactMethod
    public void getPermissions(final Promise promise) {
        promise.resolve(permissionsToWritableArray(AccessToken.getCurrentAccessToken().getPermissions()));
    }

    @ReactMethod
    public void logOut(final Promise promise) {
        LoginManager.getInstance().logOut();

        promise.resolve(true);
    }

    @ReactMethod
    public void getCurrentAccessToken(final Promise promise) {
        String token = AccessToken.getCurrentAccessToken().getToken();

        if (token != null) {
            promise.resolve(token);
        } else {
            promise.reject("Failed to get current access token");
        }
    }<commit_msg>Fix typo in Facebook module<commit_after>package io.scrollback.neighborhoods.modules.facebook;

import android.app.Activity;
import android.content.Intent;

import com.facebook.AccessToken;
import com.facebook.CallbackManager;
import com.facebook.FacebookCallback;
import com.facebook.FacebookException;
import com.facebook.FacebookSdk;
import com.facebook.login.LoginManager;
import com.facebook.login.LoginResult;
import com.facebook.react.bridge.Arguments;
import com.facebook.react.bridge.Promise;
import com.facebook.react.bridge.ReactApplicationContext;
import com.facebook.react.bridge.ReactContextBaseJavaModule;
import com.facebook.react.bridge.ReactMethod;
import com.facebook.react.bridge.ReadableArray;
import com.facebook.react.bridge.WritableArray;
import com.facebook.react.bridge.WritableMap;

import java.util.ArrayList;
import java.util.List;
import java.util.Set;

public class FacebookLoginModule extends ReactContextBaseJavaModule {

    private Activity mCurrentActivity;
    private CallbackManager mCallbackManager;
    private Promise mTokenPromise;

    public FacebookLoginModule(ReactApplicationContext reactContext, Activity activity) {
        super(reactContext);

        mCurrentActivity = activity;

        FacebookSdk.sdkInitialize(reactContext.getApplicationContext());

        mCallbackManager = CallbackManager.Factory.create();

        LoginManager.getInstance().registerCallback(mCallbackManager,
                new FacebookCallback<LoginResult>() {
                    @Override
                    public void onSuccess(final LoginResult loginResult) {
                        if (mTokenPromise != null) {
                            WritableMap map = Arguments.createMap();

                            map.putString("token", loginResult.getAccessToken().getToken());

                            WritableMap permissions = Arguments.createMap();

                            permissions.putArray("granted", permissionsToWritableArray(loginResult.getRecentlyGrantedPermissions()));
                            permissions.putArray("denied", permissionsToWritableArray(loginResult.getRecentlyDeniedPermissions()));

                            map.putMap("permissions", permissions);

                            resolvePromise(map);
                        }
                    }

                    @Override
                    public void onCancel() {
                        if (mTokenPromise != null) {
                            rejectPromise("Login was cancelled");
                        }
                    }

                    @Override
                    public void onError(FacebookException exception) {
                        if (mTokenPromise != null) {
                            rejectPromise(exception.getMessage());
                        }
                    }
                });
    }

    private void resolvePromise(WritableMap map) {
        if (mTokenPromise != null) {
            mTokenPromise.resolve(map);
            mTokenPromise = null;
        }
    }

    private void rejectPromise(String reason) {
        if (mTokenPromise != null) {
            mTokenPromise.reject(reason);
            mTokenPromise = null;
        }
    }

    private List<String> readableArrayToStringList(final ReadableArray array) {
        List<String> stringList = new ArrayList<>();

        for (int i = 0, l = array.size(); i < l; i++) {
            stringList.add(array.getString(i));
        }

        return stringList;
    }

    private WritableArray permissionsToWritableArray(Set<String> permissions) {
        WritableArray result = Arguments.createArray();

        for(String p: permissions) {
            result.pushString(p);
        }

        return result;
    }

    @Override
    public String getName() {
        return "FacebookLoginModule";
    }

    public void registerPermissionCallback(final Promise promise) {
        if (mTokenPromise != null) {
            rejectPromise("Cannot register multiple callbacks");
        }

        mTokenPromise = promise;
    }

    @ReactMethod
    public void logInWithReadPermissions(final ReadableArray permissions, final Promise promise) {
        registerPermissionCallback(promise);

        LoginManager.getInstance().logInWithReadPermissions(
                mCurrentActivity,
                readableArrayToStringList(permissions));
    }

    @ReactMethod
    public void logInWithPublishPermissions(final ReadableArray permissions, final Promise promise) {
        registerPermissionCallback(promise);

        LoginManager.getInstance().logInWithPublishPermissions(
                mCurrentActivity,
                readableArrayToStringList(permissions));
    }

    @ReactMethod
    public void getPermissions(final Promise promise) {
        promise.resolve(permissionsToWritableArray(AccessToken.getCurrentAccessToken().getPermissions()));
    }

    @ReactMethod
    public void logOut(final Promise promise) {
        LoginManager.getInstance().logOut();

        promise.resolve(true);
    }

    @ReactMethod
    public void getCurrentAccessToken(final Promise promise) {
        String token = AccessToken.getCurrentAccessToken().getToken();

        if (token != null) {
            promise.resolve(token);
        } else {
            promise.reject("Failed to get current access token");
        }
    }
{'fraction_non_alphanumeric': 0.08306112925804947, 'fraction_numerical': 0.00018665422305179653, 'mean_word_length': 2.2921658986175113, 'pattern_counts': {'":': 0, '<': 15, '<?xml version=': 0, '>': 13, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 19, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '3441755', 'n_tokens_mistral': 2560, 'n_tokens_neox': 2478, 'n_words': 500}