87a1700dde7076404ec728d7688e5e4ea7150248
[motion2.git] / server / api / chatMessage / chatMessage.model.js
1 // *************************************************************************
2 // *                                                                       *
3 // * xCALLY Motion -  The Omnichannel Contact Center                       *
4 // * Copyright (c) Xenialab s.r.l. All Rights Reserved                     *
5 // *                                                                       *
6 // *************************************************************************
7 // *                                                                       *
8 // * Email: info@xcally.com                                                *
9 // * Website: https://www.xcally.com                                       *
10 // *                                                                       *
11 // *************************************************************************
12 // *                                                                       *
13 // * The SOFTWARE PRODUCT is protected by copyright laws and international *
14 // * copyright treaties, as well as other intellectual property laws and   *
15 // * treaties. The SOFTWARE PRODUCT is licensed, not sold.                         *
16 // *                                                                       *
17 // *************************************************************************
18 var _0xf8ae=['UserId','ChatInteraction','findOne','ChatInteractionId','then','update','error','util','api','moment','request-promise','path','rimraf','../../config/environment','./chatMessage.attributes','exports','define','ChatMessage','body','FULLTEXT','models','get','direction','toLowerCase','secret'];(function(_0x4c2f11,_0x860e5){var _0x2b5a3c=function(_0x3d77de){while(--_0x3d77de){_0x4c2f11['push'](_0x4c2f11['shift']());}};_0x2b5a3c(++_0x860e5);}(_0xf8ae,0x1c9));var _0xef8a=function(_0x1d87fc,_0x1e5321){_0x1d87fc=_0x1d87fc-0x0;var _0x492b56=_0xf8ae[_0x1d87fc];return _0x492b56;};'use strict';var _=require('lodash');var util=require(_0xef8a('0x0'));var logger=require('../../config/logger')(_0xef8a('0x1'));var moment=require(_0xef8a('0x2'));var BPromise=require('bluebird');var rp=require(_0xef8a('0x3'));var fs=require('fs');var path=require(_0xef8a('0x4'));var rimraf=require(_0xef8a('0x5'));var config=require(_0xef8a('0x6'));var attributes=require(_0xef8a('0x7'));module[_0xef8a('0x8')]=function(_0x2a3496,_0x42ca8e){return _0x2a3496[_0xef8a('0x9')](_0xef8a('0xa'),attributes,{'tableName':'chat_messages','paranoid':![],'indexes':[{'name':'fti_chat_messages','fields':[_0xef8a('0xb')],'type':_0xef8a('0xc')}],'timestamps':!![],'hooks':{'afterCreate':function(_0x236876,_0x1120d4,_0x14df2f){var _0x46ddbd=_0x2a3496[_0xef8a('0xd')];var _0x25dfef=_0x236876[_0xef8a('0xe')]({'plain':!![]});if(_0x25dfef[_0xef8a('0xf')]['toLowerCase']()==='in'||_0x25dfef[_0xef8a('0xf')][_0xef8a('0x10')]()==='out'&&!_0x25dfef[_0xef8a('0x11')]&&!_['isNil'](_0x25dfef[_0xef8a('0x12')])){_0x46ddbd[_0xef8a('0x13')][_0xef8a('0x14')]({'where':{'id':_0x25dfef[_0xef8a('0x15')]}})[_0xef8a('0x16')](function(_0x3291d1){if(_0x3291d1){_0x3291d1[_0xef8a('0x17')]({'lastMsgAt':_0x25dfef['createdAt'],'lastMsgDirection':_0x25dfef[_0xef8a('0xf')]['toLowerCase']()});}})['catch'](function(_0x576201){console[_0xef8a('0x18')](_0x576201);});}_0x14df2f();}},'charset':'utf8mb4','collate':'utf8mb4_unicode_ci'});};