Files
habitica/website/client/js/services/chatServices.js
Matteo Pagliazzi 0880850408 Real-time Chat (#7664)
* feat(realtime-chat): add Pusher library to the server

* feat(realtime-chat): only for private groups

* feat(realtime-chat): add authentication endpoint for Pusher

* feat(realtime-chat): client proof of concept

* fix typo in apidoc

* feat(realtime-chat): redo authentication and write integration tests

* remove firebase code

* fix client side tests

* fix line ending in bower.json

* feat(realtime chat): use presence channels for parties, send events & disconnect clients if user leaves or is removed from party, automatically update UI

* pusher: enable all events in the background

* fix pusher integration tests
2016-07-02 15:17:24 +02:00

89 lines
2.2 KiB
JavaScript

'use strict';
angular.module('habitrpg')
.factory('Chat', ['$http', 'ApiUrl', 'User', 'Pusher',
function($http, ApiUrl, User, Pusher) {
var apiV3Prefix = '/api/v3';
function getChat (groupId) {
return $http({
method: 'GET',
url: apiV3Prefix + '/groups/' + groupId + '/chat',
});
}
function postChat (groupId, message, previousMsg) {
var url = apiV3Prefix + '/groups/' + groupId + '/chat';
if (previousMsg) {
url += '?previousMsg=' + previousMsg;
}
return $http({
method: 'POST',
url: url,
data: {
message: message,
pusherSocketId: Pusher.socketId, // to make sure the send doesn't get notified of it's own message
}
});
}
function deleteChat (groupId, chatId, previousMsg) {
var url = apiV3Prefix + '/groups/' + groupId + '/chat/' + chatId;
if (previousMsg) {
url += '?previousMsg=' + previousMsg;
}
return $http({
method: 'DELETE',
url: url,
});
}
function like (groupId, chatId) {
return $http({
method: 'POST',
url: apiV3Prefix + '/groups/' + groupId + '/chat/' + chatId + '/like',
});
}
function flagChatMessage (groupId, chatId) {
return $http({
method: 'POST',
url: apiV3Prefix + '/groups/' + groupId + '/chat/' + chatId + '/flag',
});
}
function clearFlagCount (groupId, chatId) {
return $http({
method: 'POST',
url: apiV3Prefix + '/groups/' + groupId + '/chat/' + chatId + '/clearflags',
});
}
function markChatSeen (groupId) {
if (User.user.newMessages) delete User.user.newMessages[groupId];
return $http({
method: 'POST',
url: apiV3Prefix + '/groups/' + groupId + '/chat/seen',
});
}
function clearCards () {
User.user._wrapped && User.set({'flags.cardReceived':false});
}
return {
getChat: getChat,
postChat: postChat,
deleteChat: deleteChat,
like: like,
flagChatMessage: flagChatMessage,
clearFlagCount: clearFlagCount,
markChatSeen: markChatSeen,
clearCards: clearCards,
}
}]);