b2454b4134474d3289ce60465b12fd29915484fe
[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 _0x9ee6=['bluebird','request-promise','path','../../config/environment','./chatMessage.attributes','define','ChatMessage','chat_messages','fti_chat_messages','get','direction','toLowerCase','out','secret','isNil','UserId','findOne','ChatInteractionId','then','createdAt','error','utf8mb4','utf8mb4_unicode_ci','lodash','util','../../config/logger','api'];(function(_0x35a274,_0x98b399){var _0x40d905=function(_0x5c8455){while(--_0x5c8455){_0x35a274['push'](_0x35a274['shift']());}};_0x40d905(++_0x98b399);}(_0x9ee6,0x125));var _0x69ee=function(_0x202d24,_0x5e8641){_0x202d24=_0x202d24-0x0;var _0x2b3a8e=_0x9ee6[_0x202d24];return _0x2b3a8e;};'use strict';var _=require(_0x69ee('0x0'));var util=require(_0x69ee('0x1'));var logger=require(_0x69ee('0x2'))(_0x69ee('0x3'));var moment=require('moment');var BPromise=require(_0x69ee('0x4'));var rp=require(_0x69ee('0x5'));var fs=require('fs');var path=require(_0x69ee('0x6'));var rimraf=require('rimraf');var config=require(_0x69ee('0x7'));var attributes=require(_0x69ee('0x8'));module['exports']=function(_0x1f8799,_0x52f3fe){return _0x1f8799[_0x69ee('0x9')](_0x69ee('0xa'),attributes,{'tableName':_0x69ee('0xb'),'paranoid':![],'indexes':[{'name':_0x69ee('0xc'),'fields':['body'],'type':'FULLTEXT'}],'timestamps':!![],'hooks':{'afterCreate':function(_0x1d8f6a,_0x4d2e9d,_0x1a99b3){var _0xa957e1=_0x1f8799['models'];var _0x3e6fb3=_0x1d8f6a[_0x69ee('0xd')]({'plain':!![]});if(_0x3e6fb3[_0x69ee('0xe')][_0x69ee('0xf')]()==='in'||_0x3e6fb3['direction']['toLowerCase']()===_0x69ee('0x10')&&!_0x3e6fb3[_0x69ee('0x11')]&&!_[_0x69ee('0x12')](_0x3e6fb3[_0x69ee('0x13')])){_0xa957e1['ChatInteraction'][_0x69ee('0x14')]({'where':{'id':_0x3e6fb3[_0x69ee('0x15')]}})[_0x69ee('0x16')](function(_0x44ea64){if(_0x44ea64){_0x44ea64['update']({'lastMsgAt':_0x3e6fb3[_0x69ee('0x17')],'lastMsgDirection':_0x3e6fb3['direction'][_0x69ee('0xf')]()});}})['catch'](function(_0x4bf6ac){console[_0x69ee('0x18')](_0x4bf6ac);});}_0x1a99b3();}},'charset':_0x69ee('0x19'),'collate':_0x69ee('0x1a')});};