Gitter migration: Setup redirects (rollout pt. 3)
[gitter.git] / server / services / live-collection-handlers / live-collection-chats.js
blob839ecdb065337fce9d2c886837acab042eb07abf
1 'use strict';
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');
13 });
16 module.exports = {
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');