2015-05-30 17:08:32 +00:00
|
|
|
'use strict';
|
|
|
|
|
|
|
|
|
|
angular.module('habitrpg').factory('Chat',
|
2015-05-30 17:33:51 +00:00
|
|
|
['$resource', '$http', 'ApiUrl', 'User',
|
|
|
|
|
function($resource, $http, ApiUrl, User) {
|
2015-05-30 17:08:32 +00:00
|
|
|
var utils = $resource(ApiUrl.get() + '/api/v2/groups/:gid',
|
|
|
|
|
{gid:'@_id', messageId: '@_messageId'},
|
|
|
|
|
{
|
|
|
|
|
postChat: {method: "POST", url: ApiUrl.get() + '/api/v2/groups/:gid/chat'},
|
|
|
|
|
like: {method: 'POST', isArray: true, url: ApiUrl.get() + '/api/v2/groups/:gid/chat/:messageId/like'},
|
|
|
|
|
deleteChatMessage: {method: "DELETE", url: ApiUrl.get() + '/api/v2/groups/:gid/chat/:messageId'},
|
|
|
|
|
flagChatMessage: {method: "POST", url: ApiUrl.get() + '/api/v2/groups/:gid/chat/:messageId/flag'},
|
|
|
|
|
clearFlagCount: {method: "POST", url: ApiUrl.get() + '/api/v2/groups/:gid/chat/:messageId/clearflags'},
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
var chatService = {
|
|
|
|
|
seenMessage: seenMessage,
|
2015-08-13 21:58:31 +00:00
|
|
|
clearCards: clearCards,
|
2015-05-30 17:08:32 +00:00
|
|
|
utils: utils
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
return chatService;
|
|
|
|
|
|
2015-08-13 21:58:31 +00:00
|
|
|
function clearCards() {
|
|
|
|
|
User.user.ops.update && User.set({'flags.cardReceived':false});
|
|
|
|
|
}
|
|
|
|
|
|
2015-05-30 17:08:32 +00:00
|
|
|
function seenMessage(gid) {
|
|
|
|
|
// On enter, set chat message to "seen"
|
|
|
|
|
$http.post(ApiUrl.get() + '/api/v2/groups/'+gid+'/chat/seen');
|
|
|
|
|
if (User.user.newMessages) delete User.user.newMessages[gid];
|
|
|
|
|
}
|
2015-08-13 21:58:31 +00:00
|
|
|
}]);
|