Pony.fm/resources/assets/scripts/app/services/comments.coffee
2015-10-24 19:35:37 -07:00

27 lines
1,003 B
CoffeeScript

angular.module('ponyfm').factory('comments', [
'$rootScope', '$http'
($rootScope, $http) ->
commentCache = []
self =
filters: {}
addComment: (resourceType, resourceId, content) ->
commentDef = new $.Deferred()
$http.post('/api/web/comments/' + resourceType + '/' + resourceId, {content: content, _token: pfm.token}).success (comment) ->
commentDef.resolve comment
commentDef.promise()
fetchList: (resourceType, resourceId, force) ->
key = resourceType + '-' + resourceId
force = force || false
return commentCache[key] if !force && commentCache[key]
commentDef = new $.Deferred()
$http.get('/api/web/comments/' + resourceType + '/' + resourceId).success (comments) ->
commentDef.resolve comments
commentCache[key] = commentDef.promise()
self
])