3 var _
= require('lodash');
4 var appEvents
= require('gitter-web-appevents');
5 var restSerializer
= require('../../serializers/rest-serializer');
7 function serializeChatToRoom(operation
, chat
) {
8 var url
= '/rooms/' + chat
.toTroupeId
+ '/chatMessages';
9 var strategy
= new restSerializer
.ChatStrategy();
11 return restSerializer
.serializeObject(chat
, strategy
).then(function(serializedChat
) {
12 appEvents
.dataChange2(url
, operation
, serializedChat
, 'chatMessage');
17 create: function(chat
) {
18 return serializeChatToRoom('create', chat
);
21 update: function(chat
) {
22 return serializeChatToRoom('update', chat
);
25 patch: function(chatId
, troupeId
, patch
) {
26 var url
= '/rooms/' + troupeId
+ '/chatMessages';
27 var patchMessage
= _
.extend({}, patch
, { id
: chatId
});
28 appEvents
.dataChange2(url
, 'patch', patchMessage
, 'chatMessage');
31 remove: function(chat
) {
32 return this.removeId(chat
._id
, chat
.toTroupeId
);
35 removeId: function(chatId
, troupeId
) {
36 var url
= '/rooms/' + troupeId
+ '/chatMessages';
37 appEvents
.dataChange2(url
, 'remove', { id
: chatId
}, 'chatMessage');