210298756541dc7c4fe78c04e171cb8408a25030
[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 _0x9757=['../../config/logger','bluebird','request-promise','path','rimraf','../../config/environment','exports','define','ChatMessage','chat_messages','fti_chat_messages','body','get','direction','secret','isNil','UserId','findOne','ChatInteractionId','then','createdAt','toLowerCase','error','utf8mb4_unicode_ci','lodash','util'];(function(_0x49a50e,_0x20e541){var _0x52fc92=function(_0x219278){while(--_0x219278){_0x49a50e['push'](_0x49a50e['shift']());}};_0x52fc92(++_0x20e541);}(_0x9757,0x16a));var _0x7975=function(_0x828e6e,_0x4b8c84){_0x828e6e=_0x828e6e-0x0;var _0x3a2174=_0x9757[_0x828e6e];return _0x3a2174;};'use strict';var _=require(_0x7975('0x0'));var util=require(_0x7975('0x1'));var logger=require(_0x7975('0x2'))('api');var moment=require('moment');var BPromise=require(_0x7975('0x3'));var rp=require(_0x7975('0x4'));var fs=require('fs');var path=require(_0x7975('0x5'));var rimraf=require(_0x7975('0x6'));var config=require(_0x7975('0x7'));var attributes=require('./chatMessage.attributes');module[_0x7975('0x8')]=function(_0x50e86d,_0x191687){return _0x50e86d[_0x7975('0x9')](_0x7975('0xa'),attributes,{'tableName':_0x7975('0xb'),'paranoid':![],'indexes':[{'name':_0x7975('0xc'),'fields':[_0x7975('0xd')],'type':'FULLTEXT'}],'timestamps':!![],'hooks':{'afterCreate':function(_0x12caa6,_0x7f0115,_0x5154dc){var _0x19abf2=_0x50e86d['models'];var _0x1ac7e1=_0x12caa6[_0x7975('0xe')]({'plain':!![]});if(_0x1ac7e1[_0x7975('0xf')]['toLowerCase']()==='in'||_0x1ac7e1[_0x7975('0xf')]['toLowerCase']()==='out'&&!_0x1ac7e1[_0x7975('0x10')]&&!_[_0x7975('0x11')](_0x1ac7e1[_0x7975('0x12')])){_0x19abf2['ChatInteraction'][_0x7975('0x13')]({'where':{'id':_0x1ac7e1[_0x7975('0x14')]}})[_0x7975('0x15')](function(_0x2775b4){if(_0x2775b4){_0x2775b4['update']({'lastMsgAt':_0x1ac7e1[_0x7975('0x16')],'lastMsgDirection':_0x1ac7e1[_0x7975('0xf')][_0x7975('0x17')]()});}})['catch'](function(_0x1ebdfe){console[_0x7975('0x18')](_0x1ebdfe);});}_0x5154dc();}},'charset':'utf8mb4','collate':_0x7975('0x19')});};