13d9ca2a6595f2eaecdc135f54e726a0ae0393e5
[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 _0xf609=['isNil','UserId','ChatInteractionId','then','createdAt','toLowerCase','error','utf8mb4_unicode_ci','lodash','util','../../config/logger','api','moment','bluebird','request-promise','rimraf','./chatMessage.attributes','ChatMessage','fti_chat_messages','body','FULLTEXT','direction','out','secret'];(function(_0x16b9ed,_0x56517a){var _0x66b1f8=function(_0x1c883){while(--_0x1c883){_0x16b9ed['push'](_0x16b9ed['shift']());}};_0x66b1f8(++_0x56517a);}(_0xf609,0x1d0));var _0x9f60=function(_0x3664b1,_0x89cb75){_0x3664b1=_0x3664b1-0x0;var _0x42934e=_0xf609[_0x3664b1];return _0x42934e;};'use strict';var _=require(_0x9f60('0x0'));var util=require(_0x9f60('0x1'));var logger=require(_0x9f60('0x2'))(_0x9f60('0x3'));var moment=require(_0x9f60('0x4'));var BPromise=require(_0x9f60('0x5'));var rp=require(_0x9f60('0x6'));var fs=require('fs');var path=require('path');var rimraf=require(_0x9f60('0x7'));var config=require('../../config/environment');var attributes=require(_0x9f60('0x8'));module['exports']=function(_0x12ffc7,_0x40b757){return _0x12ffc7['define'](_0x9f60('0x9'),attributes,{'tableName':'chat_messages','paranoid':![],'indexes':[{'name':_0x9f60('0xa'),'fields':[_0x9f60('0xb')],'type':_0x9f60('0xc')}],'timestamps':!![],'hooks':{'afterCreate':function(_0x3a476f,_0x2307d6,_0x44a360){var _0xd99400=_0x12ffc7['models'];var _0xadc86f=_0x3a476f['get']({'plain':!![]});if(_0xadc86f[_0x9f60('0xd')]['toLowerCase']()==='in'||_0xadc86f[_0x9f60('0xd')]['toLowerCase']()===_0x9f60('0xe')&&!_0xadc86f[_0x9f60('0xf')]&&!_[_0x9f60('0x10')](_0xadc86f[_0x9f60('0x11')])){_0xd99400['ChatInteraction']['findOne']({'where':{'id':_0xadc86f[_0x9f60('0x12')]}})[_0x9f60('0x13')](function(_0x33a9cb){if(_0x33a9cb){_0x33a9cb['update']({'lastMsgAt':_0xadc86f[_0x9f60('0x14')],'lastMsgDirection':_0xadc86f['direction'][_0x9f60('0x15')]()});}})['catch'](function(_0x19ec9d){console[_0x9f60('0x16')](_0x19ec9d);});}_0x44a360();}},'charset':'utf8mb4','collate':_0x9f60('0x17')});};