236e5dbdc3031e31cf181b9122396c29d2e30087
[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 _0x0e8b=['UserId','ChatInteraction','findOne','then','update','createdAt','error','utf8mb4_unicode_ci','util','../../config/logger','moment','bluebird','request-promise','path','rimraf','../../config/environment','./chatMessage.attributes','exports','define','chat_messages','fti_chat_messages','body','FULLTEXT','models','get','direction','toLowerCase','out','secret','isNil'];(function(_0x5555c0,_0x2ec271){var _0x22312d=function(_0x27a9cc){while(--_0x27a9cc){_0x5555c0['push'](_0x5555c0['shift']());}};_0x22312d(++_0x2ec271);}(_0x0e8b,0x116));var _0xb0e8=function(_0x512df7,_0xdfa7d2){_0x512df7=_0x512df7-0x0;var _0x22f78e=_0x0e8b[_0x512df7];return _0x22f78e;};'use strict';var _=require('lodash');var util=require(_0xb0e8('0x0'));var logger=require(_0xb0e8('0x1'))('api');var moment=require(_0xb0e8('0x2'));var BPromise=require(_0xb0e8('0x3'));var rp=require(_0xb0e8('0x4'));var fs=require('fs');var path=require(_0xb0e8('0x5'));var rimraf=require(_0xb0e8('0x6'));var config=require(_0xb0e8('0x7'));var attributes=require(_0xb0e8('0x8'));module[_0xb0e8('0x9')]=function(_0x438fdd,_0x61156c){return _0x438fdd[_0xb0e8('0xa')]('ChatMessage',attributes,{'tableName':_0xb0e8('0xb'),'paranoid':![],'indexes':[{'name':_0xb0e8('0xc'),'fields':[_0xb0e8('0xd')],'type':_0xb0e8('0xe')}],'timestamps':!![],'hooks':{'afterCreate':function(_0xae1db,_0x4d6ce5,_0xebe10){var _0x1f053a=_0x438fdd[_0xb0e8('0xf')];var _0x5276ba=_0xae1db[_0xb0e8('0x10')]({'plain':!![]});if(_0x5276ba['direction']['toLowerCase']()==='in'||_0x5276ba[_0xb0e8('0x11')][_0xb0e8('0x12')]()===_0xb0e8('0x13')&&!_0x5276ba[_0xb0e8('0x14')]&&!_[_0xb0e8('0x15')](_0x5276ba[_0xb0e8('0x16')])){_0x1f053a[_0xb0e8('0x17')][_0xb0e8('0x18')]({'where':{'id':_0x5276ba['ChatInteractionId']}})[_0xb0e8('0x19')](function(_0xd48056){if(_0xd48056){_0xd48056[_0xb0e8('0x1a')]({'lastMsgAt':_0x5276ba[_0xb0e8('0x1b')],'lastMsgDirection':_0x5276ba[_0xb0e8('0x11')][_0xb0e8('0x12')]()});}})['catch'](function(_0x48fa65){console[_0xb0e8('0x1c')](_0x48fa65);});}_0xebe10();}},'charset':'utf8mb4','collate':_0xb0e8('0x1d')});};