<commit_before>import { LOG_IN, LOG_OUT, UPDATE_FRIENDS} from '../constants/constants.js';
import { ref } from '../lib/db/db.js';
import { Actions } from 'react-native-router-flux';

export const logIn = (payload) => {
  return {
    type: LOG_IN,
    payload
  };
};
export const updateFriends = (payload) => {
  return{
    type: UPDATE_FRIENDS,
    payload
  };
};
export const firebase_check = (userCredentials) => {
  let id = userCredentials.userId;
  let token = userCredentials.token;
  let api = "https://graph.facebook.com/v2.3/"+id+"?fields=name,email,friends,picture&access_token="+token;
  // let callfriends = "https://graph.facebook.com/v2.3/"+id+"?fields=name,email,friends,picture&access_token="+token;
  function checkIfUserExists(userId, callback) {
    ref.once('value', function(snapshot) {
    let userExistsBool = snapshot.hasChild(userId);
      callback(userExistsBool);
    });
  }
  return(dispatch) => {
    checkIfUserExists(id, (userExist) => {
      if(!userExist) {
        let userInfo={};
        userInfo.id = id;
        //fetch the other info
        return fetch(api)
        .then((response) => response.json())
        .then((responseData)=> {
          console.log('this is responseData and it should have friends', responseData.friends.data);

          userInfo.name = responseData.name;
          userInfo.email = responseData.email;
          userInfo.picture = responseData.picture.data.url;
        //pushes all gathereed infor to database
        let newUser = ref.child(id).set(userInfo);
        dispatch(updateFriends(responseData.friends.data));
        dispatch(logIn(userInfo));
        });
      } else {
        ref.child(id).on("value", function(snapshot) {
          let found = snapshot.val();
          dispatch(logIn(found));
        });
      }
    });
  };
};

export const logOut = function () {
  return {
    type: LOG_OUT<commit_msg>update friends for users who've already signed up<commit_after>import { LOG_IN, LOG_OUT, UPDATE_FRIENDS} from '../constants/constants.js';
import { ref } from '../lib/db/db.js';
import { Actions } from 'react-native-router-flux';

export const logIn = (payload) => {
  return {
    type: LOG_IN,
    payload
  };
};
export const updateFriends = (payload) => {
  return{
    type: UPDATE_FRIENDS,
    payload
  };
};
export const firebase_check = (userCredentials) => {
  let id = userCredentials.userId;
  let token = userCredentials.token;
  let api = "https://graph.facebook.com/v2.3/"+id+"?fields=name,email,friends,picture&access_token="+token;
  // let callfriends = "https://graph.facebook.com/v2.3/"+id+"?fields=name,email,friends,picture&access_token="+token;
  let friendcall = "https://graph.facebook.com/v2.3/"+id+"?fields=name,friends&access_token="+token;
  function checkIfUserExists(userId, callback) {
    ref.once('value', function(snapshot) {
    let userExistsBool = snapshot.hasChild(userId);
      callback(userExistsBool);
    });
  }
  return(dispatch) => {
    checkIfUserExists(id, (userExist) => {
      if(!userExist) {
        let userInfo={};
        userInfo.id = id;
        //fetch the other info
        return fetch(api)
        .then((response) => response.json())
        .then((responseData)=> {
          userInfo.name = responseData.name;
          userInfo.email = responseData.email;
          userInfo.picture = responseData.picture.data.url;
        //pushes all gathereed infor to database
        let newUser = ref.child(id).set(userInfo);
        dispatch(updateFriends(responseData.friends.data));
        dispatch(logIn(userInfo));
        });
      } else {
        //this api call to fb updates friends list
        return fetch(friendcall)
        .then((response) => response.json())
        .then((responseData) => {
          ref.child(id).on("value", function(snapshot) {
            let found = snapshot.val();
            dispatch(logIn(found));
          });
          dispatch(updateFriends(responseData.friends.data));
        });
      }
    });
  };
};

export const logOut = function () {
  return {
    type: LOG_OUT
{'fraction_non_alphanumeric': 0.14730392156862746, 'fraction_numerical': 0.0024509803921568627, 'mean_word_length': 2.897803247373448, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 19, 'https://': 5, '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': '2980703', 'n_tokens_mistral': 1267, 'n_tokens_neox': 1265, 'n_words': 238}