<commit_before>angular.module('app.services').factory('follows', function ($http,serverConfig, $q, $rootScope) {

  var FUser = function(userData, role){
    this.setData = function(userData){
      this.first_name = userData.first_name
      this.last_name = userData.last_name
      this.avatar_file_name = userData.avatar_file_name
      this.user_id = userData.id
      this.username = userData.username
      this.date_approval = userData.date_approval
      this.full_name = userData.full_name      
    }

    this.roles = [role]
    this.setData(userData)

    this.isFollowingCurrentUser = function(){
      return(_.include(this.roles, 'isFollowingCurrentUser'))
    }

    this.isFollowedByCurrentUser = function(){
      return(_.include(this.roles, 'isFollowedByCurrentUser'))
    }

    this.addRole = function(role){
      this.roles.push(role)
      this.roles = _.uniq(this.roles)
    }

    this.removeRole = function(role){
      this.roles = _.without(this.roles, role)
    }

    this.approve = function(){
      this.date_approval = new Date()
      return $http.patch(serverConfig.url + '/api/v2/user/followers/'+this.user_id)
    }

    this.unApprove = function(){
      this.date_approval = null
      return $http.delete(serverConfig.url + '/api/v2/user/followers/'+this.user_id)
    }

    this.followByCurrentUser = function(){
      this.addRole('isFollowedByCurrentUser')
      return $http.put(serverConfig.url + '/api/v2/user/followings/'+this.user_id)
    }

    this.unFollowByCurrentUser = function(){
      this.removeRole('isFollowedByCurrentUser')
      return $http.delete(serverConfig.url + '/api/v2/user/followings/'+this.user_id)
    }

    this.isApproved = function(){
      return(this.date_approval != null)
    }
  }

  var service = {}
  service.loaded = false

  service.users = []

  service.load = function(){
    service.users = []

    var p1 = $http.get(serverConfig.url + '/api/v2/user/followings').then(function(response){
      response.data.payload.forEach(function(userData){
        var uID = userData.id
        var u = service.getUser(uID)
        if(u){
          u.addRole('isFollowedByCurrentUser')
          u.setData(userData)
        }
          
        else{
          u = new FUser(userData, 'isFollowedByCurrentUser')
          service.users.push(u)
        }
      })
    })

    var p2 = $http.get(serverConfig.url + '/api/v2/user/followers').then(function(response){
      response.data.payload.forEach(function(userData){
        var uID = userData.id
        var u = service.getUser(uID)
        if(u){
          u.addRole('isFollowingCurrentUser')
          u.setData(userData)
        }
        else{
          u = new FUser(userData, 'isFollowingCurrentUser')
          service.users.push(u)
        }
      })
    })

    var deferred = $q.defer();
    $q.all([p1, p2]).then(function(){
      service.loaded = true
      $rootScope.$broadcast('follows-loaded');
      deferred.resolve()
    })

    return deferred.promise
  }

  service.getUsersFollowingCurrentUser = function(){
    return this.users.filter(function(u){return u.isFollowingCurrentUser()})
  }

  service.getUsersFollowedByCurrentUser = function(){
    return this.users.filter(function(u){return u.isFollowedByCurrentUser()})
  }

  service.loadSuggested = function (friends) {
      return $http.post(serverConfig.url + '/api/profile/facebook-friends', friends).then(function (response) {
        return response.data;
      });
  }

  service.getFollowing = service.getUsersFollowedByCurrentUser

  service.getUser = function(uID){
    return service.users.find(function(user){
      return user.user_id == uID
    })
  }
<commit_msg>fix bug #196: Object [object Array] has no method 'find' at Object.service.getUser #196<commit_after>angular.module('app.services').factory('follows', function ($http,serverConfig, $q, $rootScope) {

  var FUser = function(userData, role){
    this.setData = function(userData){
      this.first_name = userData.first_name
      this.last_name = userData.last_name
      this.avatar_file_name = userData.avatar_file_name
      this.user_id = userData.id
      this.username = userData.username
      this.date_approval = userData.date_approval
      this.full_name = userData.full_name      
    }

    this.roles = [role]
    this.setData(userData)

    this.isFollowingCurrentUser = function(){
      return(_.include(this.roles, 'isFollowingCurrentUser'))
    }

    this.isFollowedByCurrentUser = function(){
      return(_.include(this.roles, 'isFollowedByCurrentUser'))
    }

    this.addRole = function(role){
      this.roles.push(role)
      this.roles = _.uniq(this.roles)
    }

    this.removeRole = function(role){
      this.roles = _.without(this.roles, role)
    }

    this.approve = function(){
      this.date_approval = new Date()
      return $http.patch(serverConfig.url + '/api/v2/user/followers/'+this.user_id)
    }

    this.unApprove = function(){
      this.date_approval = null
      return $http.delete(serverConfig.url + '/api/v2/user/followers/'+this.user_id)
    }

    this.followByCurrentUser = function(){
      this.addRole('isFollowedByCurrentUser')
      return $http.put(serverConfig.url + '/api/v2/user/followings/'+this.user_id)
    }

    this.unFollowByCurrentUser = function(){
      this.removeRole('isFollowedByCurrentUser')
      return $http.delete(serverConfig.url + '/api/v2/user/followings/'+this.user_id)
    }

    this.isApproved = function(){
      return(this.date_approval != null)
    }
  }

  var service = {}
  service.loaded = false

  service.users = []

  service.load = function(){
    service.users = []

    var p1 = $http.get(serverConfig.url + '/api/v2/user/followings').then(function(response){
      response.data.payload.forEach(function(userData){
        var uID = userData.id
        var u = service.getUser(uID)
        if(u){
          u.addRole('isFollowedByCurrentUser')
          u.setData(userData)
        }
          
        else{
          u = new FUser(userData, 'isFollowedByCurrentUser')
          service.users.push(u)
        }
      })
    })

    var p2 = $http.get(serverConfig.url + '/api/v2/user/followers').then(function(response){
      response.data.payload.forEach(function(userData){
        var uID = userData.id
        var u = service.getUser(uID)
        if(u){
          u.addRole('isFollowingCurrentUser')
          u.setData(userData)
        }
        else{
          u = new FUser(userData, 'isFollowingCurrentUser')
          service.users.push(u)
        }
      })
    })

    var deferred = $q.defer();
    $q.all([p1, p2]).then(function(){
      service.loaded = true
      $rootScope.$broadcast('follows-loaded');
      deferred.resolve()
    })

    return deferred.promise
  }

  service.getUsersFollowingCurrentUser = function(){
    return this.users.filter(function(u){return u.isFollowingCurrentUser()})
  }

  service.getUsersFollowedByCurrentUser = function(){
    return this.users.filter(function(u){return u.isFollowedByCurrentUser()})
  }

  service.loadSuggested = function (friends) {
      return $http.post(serverConfig.url + '/api/profile/facebook-friends', friends).then(function (response) {
        return response.data;
      });
  }

  service.getFollowing = service.getUsersFollowedByCurrentUser

  service.getUser = function(uID){
    return _.find(service.users, function(user){
      return user.user_id == uID
    })
  }

{'fraction_non_alphanumeric': 0.1323312307072876, 'fraction_numerical': 0.003489464501409207, 'mean_word_length': 2.7827411167512692, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, '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': '3597032', 'n_tokens_mistral': 2438, 'n_tokens_neox': 2363, 'n_words': 343}