-
-
Save beautyfree/d6d59c3469d7cf14b74b to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
.factory('feed', function($http, vk, $localStorage){ | |
var owner_id = '-34882023'; | |
var version = '5.34'; | |
var count = '5'; | |
var items = []; | |
var liked; | |
var isLiked = function(itemId){ | |
return vk.call('likes.isLiked', {item_id: itemId, owner_id: owner_id, access_token: $localStorage.token, type: 'post', v: version}).then(function(result){ | |
return result; | |
}, function(err){console.log('err' + err)}); | |
}; | |
return { | |
getFeed: function(offset){ | |
// Вызываем асинхронный запрос к апи, который вернет промис | |
return vk.call('wall.get', {owner_id: owner_id, offset: offset, count: count, v: version}).then(function(res){ | |
console.log(res); | |
items = res.data.response.items; | |
// Перебираем массив айтемс получая массив измененных айтемов | |
var promises = items.map(function(item) { | |
// Возвращаем модифицированный айтем в мэп | |
return isLiked(item.id).then(function(ress){ | |
if(ress.data.response.liked == true){ | |
console.log(item); | |
} | |
// Модифицированный айтем либо такой же | |
return item; | |
}); | |
}); | |
// Возвращаем промис с результатами когда отработают все промисы в массиве | |
return $q.all(promises); | |
}, function(err){ | |
console.log('cant call'); | |
}); | |
}, | |
... |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment