-'use strict';
-
-var _ = require('lodash');
-var md5 = require('md5');
-
-var User = require('../../models').User;
-var ChatRoom = require('../../models').ChatRoom;
-var ChatMessage = require('../../models').ChatMessage;
-var ChatVisitor = require('../../models').ChatVisitor;
-
-// Get list of chat_messages
-exports.index = function (req, res) {
- ChatMessage
- .findAll()
- .then(function (chat_messages) {
- return res.status(200).send(chat_messages);
- })
- .catch(function (err) {
- return handleError(res, err);
- });
-};
-
-// Get a single chatMessage
-exports.show = function (req, res) {
- ChatMessage
- .findById(req.params.id)
- .then(function (chatMessage) {
- if (!chatMessage) {
- return res.sendStatus(404);
- }
- return res.send(chatMessage);
- })
- .catch(function (err) {
- return handleError(res, err);
- });
-};
-
-// Creates a new chatMessage in the DB.
-exports.create = function (req, res, next) {
- // if (req.body.ChatRoomId && req.body.to) {
- // return handleError(res, new Error('Select ChatRoomId or to'));
- // } else if (req.body.to) {
- //
- // switch (req.body.type) {
- // case 'internal':
- // User
- // .findOne({
- // where: {
- // $or: [{
- // id: {
- // $like: req.body.to
- // }
- // }, {
- // name: req.body.to
- // }]
- // }
- // })
- // .then(function(user) {
- // if (user) {
- //
- // var users = _.sortBy([user, req.user], 'id');
- // var participants = {
- // users: {
- // ids: [users[0].id, users[1].id]
- // },
- // visitors: {
- // ids: []
- // }
- // };
- //
- // var token = md5(JSON.stringify(participants)).toString(
- // 'base64');
- //
- // participants.users.fullnames = [users[0].fullname, users[1].fullname];
- // participants.visitors.fullnames = [];
- //
- // ChatRoom
- // .findOrCreate({
- // where: {
- // token: token
- // },
- // defaults: {
- // type: req.body.type,
- // token: token,
- // participants: JSON.stringify(participants)
- // }
- // })
- // .spread(function(chatRoom, created) {
- //
- // chatRoom
- // .updateAttributes({
- // participants: JSON.stringify(participants)
- // });
- //
- // ChatMessage
- // .create({
- // body: req.body.body,
- // fullname: req.user.fullname,
- // email: req.user.email,
- // ChatRoomId: chatRoom.id,
- // userId: req.user.id
- // })
- // .then(function(chatMessage) {
- // return res.status(201).send(chatMessage);
- // })
- // .catch(function(err) {
- // return handleError(res, err);
- // });
- // });
- //
- // } else {
- // return handleError(res, new Error('User not found'));
- // }
- // })
- // .catch(function(err) {
- // return handleError(res, err);
- // });
- //
- // break;
- // case 'external':
- // ChatVisitor
- // .findOne({
- // where: {
- // $or: [{
- // id: {
- // $like: req.body.to
- // }
- // }, {
- // fullname: req.body.to
- // }]
- // }
- // })
- // .then(function(chatVisitor) {
- // if (chatVisitor) {
- //
- // var participants = {
- // users: {
- // ids: [req.user.id]
- // },
- // visitors: {
- // ids: [chatVisitor.id]
- // }
- // };
- //
- // var token = md5(JSON.stringify(participants)).toString(
- // 'base64');
- //
- // participants.users.fullnames = [req.user.fullname];
- // participants.visitors.fullnames = [chatVisitor.fullname];
- //
- // ChatRoom
- // .findOrCreate({
- // where: {
- // token: token
- // },
- // defaults: {
- // type: req.body.type,
- // token: token,
- // participants: JSON.stringify(participants)
- // }
- // })
- // .spread(function(chatRoom, created) {
- //
- // chatRoom
- // .updateAttributes({
- // participants: JSON.stringify(participants)
- // });
- //
- // ChatMessage
- // .create({
- // body: req.body.body,
- // fullname: req.user.fullname,
- // email: req.user.email,
- // ChatRoomId: chatRoom.id,
- // userId: req.user.id
- // })
- // .then(function(chatMessage) {
- // return res.status(201).send(chatMessage);
- // })
- // .catch(function(err) {
- // return handleError(res, err);
- // });
- // });
- // }
- // });
- // break;
- // default:
- // return handleError(res, new Error('Room type unsupported'));
- // }
- //
- //
- // } else if (req.body.ChatRoomId) {
- //
- // ChatMessage
- // .create(_.merge({
- // userId: req.user.id,
- // email: req.user.email,
- // fullname: req.user.fullname
- // }, req.body))
- // .then(function(chatMessage) {
- // return res.status(201).send(chatMessage);
- // })
- // .catch(function(err) {
- // return handleError(res, err);
- // });
- // } else {
- // return handleError(res, new Error('Select ChatRoomId or to'));
- // }
- ChatMessage
- .create(_.merge(req.body, {
- UserId: req.user.id
- }))
- .then(function (chatMessage) {
- return res.status(201).send(chatMessage);
- })
- .catch(function (err) {
- return handleError(res, err);
- });
-};
-
-// Updates an existing chatMessage in the DB.
-exports.update = function (req, res) {
- if (req.body.id) {
- delete req.body.id;
- }
-
- return ChatMessage
- .findById(req.params.id)
- .then(function (chatMessage) {
- if (!chatMessage) {
- return res.sendStatus(404);
- }
- var updated = _.merge(chatMessage, req.body);
- return updated.save();
- })
- .then(function (chatMessage) {
- return res.status(200).send(chatMessage);
- })
- .catch(function (err) {
- return handleError(res, err);
- });
-};
-
-// Deletes a chatMessage from the DB.
-exports.destroy = function (req, res) {
- ChatMessage
- .findById(req.params.id)
- .then(function (chatMessage) {
- if (!chatMessage) {
- return res.sendStatus(404);
- }
- chatMessage.destroy()
- .then(function () {
- return res.sendStatus(204);
- })
- .catch(function (err) {
- return handleError(res, err);
- });
- })
- .catch(function (err) {
- return handleError(res, err);
- });
-};
-
-function handleError(res, err) {
- return res.status(500).send(err);
-}
+var _0xea6a=["\x75\x73\x65\x20\x73\x74\x72\x69\x63\x74","\x6C\x6F\x64\x61\x73\x68","\x6D\x64\x35","\x55\x73\x65\x72","\x2E\x2E\x2F\x2E\x2E\x2F\x6D\x6F\x64\x65\x6C\x73","\x43\x68\x61\x74\x52\x6F\x6F\x6D","\x43\x68\x61\x74\x4D\x65\x73\x73\x61\x67\x65","\x43\x68\x61\x74\x56\x69\x73\x69\x74\x6F\x72","\x69\x6E\x64\x65\x78","\x63\x61\x74\x63\x68","\x73\x65\x6E\x64","\x73\x74\x61\x74\x75\x73","\x74\x68\x65\x6E","\x66\x69\x6E\x64\x41\x6C\x6C","\x73\x68\x6F\x77","\x73\x65\x6E\x64\x53\x74\x61\x74\x75\x73","\x69\x64","\x70\x61\x72\x61\x6D\x73","\x66\x69\x6E\x64\x42\x79\x49\x64","\x63\x72\x65\x61\x74\x65","\x62\x6F\x64\x79","\x75\x73\x65\x72","\x6D\x65\x72\x67\x65","\x75\x70\x64\x61\x74\x65","\x73\x61\x76\x65","\x64\x65\x73\x74\x72\x6F\x79"];_0xea6a[0];var _=require(_0xea6a[1]);var md5=require(_0xea6a[2]);var User=require(_0xea6a[4])[_0xea6a[3]];var ChatRoom=require(_0xea6a[4])[_0xea6a[5]];var ChatMessage=require(_0xea6a[4])[_0xea6a[6]];var ChatVisitor=require(_0xea6a[4])[_0xea6a[7]];exports[_0xea6a[8]]=function(_0x6ff9x7,_0x6ff9x8){ChatMessage[_0xea6a[13]]()[_0xea6a[12]](function(_0x6ff9xa){return _0x6ff9x8[_0xea6a[11]](200)[_0xea6a[10]](_0x6ff9xa)})[_0xea6a[9]](function(_0x6ff9x9){return handleError(_0x6ff9x8,_0x6ff9x9)})};exports[_0xea6a[14]]=function(_0x6ff9x7,_0x6ff9x8){ChatMessage[_0xea6a[18]](_0x6ff9x7[_0xea6a[17]][_0xea6a[16]])[_0xea6a[12]](function(_0x6ff9xb){if(!_0x6ff9xb){return _0x6ff9x8[_0xea6a[15]](404)};return _0x6ff9x8[_0xea6a[10]](_0x6ff9xb);})[_0xea6a[9]](function(_0x6ff9x9){return handleError(_0x6ff9x8,_0x6ff9x9)})};exports[_0xea6a[19]]=function(_0x6ff9x7,_0x6ff9x8,_0x6ff9xc){ChatMessage[_0xea6a[19]](_[_0xea6a[22]](_0x6ff9x7[_0xea6a[20]],{UserId:_0x6ff9x7[_0xea6a[21]][_0xea6a[16]]}))[_0xea6a[12]](function(_0x6ff9xb){return _0x6ff9x8[_0xea6a[11]](201)[_0xea6a[10]](_0x6ff9xb)})[_0xea6a[9]](function(_0x6ff9x9){return handleError(_0x6ff9x8,_0x6ff9x9)})};exports[_0xea6a[23]]=function(_0x6ff9x7,_0x6ff9x8){if(_0x6ff9x7[_0xea6a[20]][_0xea6a[16]]){delete _0x6ff9x7[_0xea6a[20]][_0xea6a[16]]};return ChatMessage[_0xea6a[18]](_0x6ff9x7[_0xea6a[17]][_0xea6a[16]])[_0xea6a[12]](function(_0x6ff9xb){if(!_0x6ff9xb){return _0x6ff9x8[_0xea6a[15]](404)};var _0x6ff9xd=_[_0xea6a[22]](_0x6ff9xb,_0x6ff9x7[_0xea6a[20]]);return _0x6ff9xd[_0xea6a[24]]();})[_0xea6a[12]](function(_0x6ff9xb){return _0x6ff9x8[_0xea6a[11]](200)[_0xea6a[10]](_0x6ff9xb)})[_0xea6a[9]](function(_0x6ff9x9){return handleError(_0x6ff9x8,_0x6ff9x9)});};exports[_0xea6a[25]]=function(_0x6ff9x7,_0x6ff9x8){ChatMessage[_0xea6a[18]](_0x6ff9x7[_0xea6a[17]][_0xea6a[16]])[_0xea6a[12]](function(_0x6ff9xb){if(!_0x6ff9xb){return _0x6ff9x8[_0xea6a[15]](404)};_0x6ff9xb[_0xea6a[25]]()[_0xea6a[12]](function(){return _0x6ff9x8[_0xea6a[15]](204)})[_0xea6a[9]](function(_0x6ff9x9){return handleError(_0x6ff9x8,_0x6ff9x9)});})[_0xea6a[9]](function(_0x6ff9x9){return handleError(_0x6ff9x8,_0x6ff9x9)})};function handleError(_0x6ff9x8,_0x6ff9x9){return _0x6ff9x8[_0xea6a[11]](500)[_0xea6a[10]](_0x6ff9x9)}
\ No newline at end of file