<commit_before>'use strict';

/**
 * The Likes service
 */

angular.module('cloudnode.service.likes', [
  'cloudnode.service.api'
])

.factory('LikesService', function (ApiService) {
  var likes = [];
  var isInitialized = false;

  var observerCallbacks = [];

  function notifyObservers(){
    for (var i = observerCallbacks.length - 1; i >= 0; i--) {
      observerCallbacks[i]();
    }
    observerCallbacks = [];
  }

  function removeTrack(trackId) {
    for (var i = likes.length - 1; i >= 0; i--) {
      if (likes[i].id === trackId)
        delete likes[i];
    }
  }

  return {
    init: function initLikesService(){
      ApiService.getMeLikes().then(function (likesArr){
        likes = likesArr;

        isInitialized = true;
        notifyObservers();
      }, function(){
        console.warn('Unable to retrieve likes');
      });
    },

    getAllLikes: function getAllLikes(){
      return likes;
    },

    isLiked: function isLiked(trackId) {
      return likes.filter(function (like){
        return like.id === trackId;
      }).length > 0;
    },

    unlikeTrack: function unlikeTrack(trackId) {
      return ApiService.unlikeTrack(trackId).then(function() {
        removeTrack(trackId);
        return true;
      }, function() {
        return false;
      });
    },

    likeTrack: function likeTrack(track) {
      return ApiService.likeTrack(track.id).then(function() {
        likes.push(track);
        return true;
      }, function() {
        return false;
      });
    },<commit_msg>Change likes way of working<commit_after>'use strict';

/**
 * The Likes service
 */

angular.module('cloudnode.service.likes', [
  'cloudnode.service.api'
])

.factory('LikesService', function (ApiService) {
  var likes         = [];
  var likesIds      = [];
  var isInitialized = false;

  var observerCallbacks = [];

  function notifyObservers(){
    for (var i = observerCallbacks.length - 1; i >= 0; i--) {
      observerCallbacks[i]();
    }
    observerCallbacks = [];
  }

  function removeTrack(trackId) {
    for (var i = likes.length - 1; i >= 0; i--) {
      if (likes[i].id === trackId)
        delete likes[i];
    }
  }

  return {
    init: function initLikesService(){
      var _this = this;
      ApiService.getMeLikesIds().then(function (likesIdsObj){
        likesIds = likesIdsObj.collection;

        _this.getAllLikesObjs();
        isInitialized = true;
        notifyObservers();
      }, function(){
        console.warn('Unable to retrieve likes');
      });
    },

    getAllLikes: function getAllLikes(){
      return likes;
    },

    getAllLikesObjs: function getAllLikesIds(){
      ApiService.getMeLikes().then(function (likesArr){
        likes = likesArr;
      }, function(){
        console.warn('Unable to retrieve likes');
      });
    },

    isLiked: function isLiked(trackId) {
      return likesIds.indexOf(trackId) !== -1;
    },

    unlikeTrack: function unlikeTrack(trackId) {
      return ApiService.unlikeTrack(trackId).then(function() {
        removeTrack(trackId);
        return true;
      }, function() {
        return false;
      });
    },

    likeTrack: function likeTrack(track) {
      return ApiService.likeTrack(track.id).then(function() {
        likes.push(track);
        return true;
      }, function() {
        return false;
      });
    },
{'fraction_non_alphanumeric': 0.14055023923444976, 'fraction_numerical': 0.0029904306220095694, 'mean_word_length': 2.4063136456211813, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 8, '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': '799593', 'n_tokens_mistral': 1034, 'n_tokens_neox': 1024, 'n_words': 213}