ca3ceefdac5dd3d33be6051fa08bdca55298f7c6
[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 _0xa3a9=['bluebird','request-promise','rimraf','../../config/environment','./chatMessage.attributes','exports','define','ChatMessage','chat_messages','fti_chat_messages','body','FULLTEXT','toLowerCase','out','secret','UserId','findOne','direction','utf8mb4','lodash','util','../../config/logger','api','moment'];(function(_0x16b55f,_0x301c6c){var _0x391c2f=function(_0x4f1941){while(--_0x4f1941){_0x16b55f['push'](_0x16b55f['shift']());}};_0x391c2f(++_0x301c6c);}(_0xa3a9,0x14b));var _0x9a3a=function(_0x2d1ca4,_0x1f9ae4){_0x2d1ca4=_0x2d1ca4-0x0;var _0xc6ece8=_0xa3a9[_0x2d1ca4];return _0xc6ece8;};'use strict';var _=require(_0x9a3a('0x0'));var util=require(_0x9a3a('0x1'));var logger=require(_0x9a3a('0x2'))(_0x9a3a('0x3'));var moment=require(_0x9a3a('0x4'));var BPromise=require(_0x9a3a('0x5'));var rp=require(_0x9a3a('0x6'));var fs=require('fs');var path=require('path');var rimraf=require(_0x9a3a('0x7'));var config=require(_0x9a3a('0x8'));var attributes=require(_0x9a3a('0x9'));module[_0x9a3a('0xa')]=function(_0x5f2833,_0x24624f){return _0x5f2833[_0x9a3a('0xb')](_0x9a3a('0xc'),attributes,{'tableName':_0x9a3a('0xd'),'paranoid':![],'indexes':[{'name':_0x9a3a('0xe'),'fields':[_0x9a3a('0xf')],'type':_0x9a3a('0x10')}],'timestamps':!![],'hooks':{'afterCreate':function(_0x4edfd0,_0x27158c,_0x40f297){var _0x20209f=_0x5f2833['models'];var _0x31f987=_0x4edfd0['get']({'plain':!![]});if(_0x31f987['direction'][_0x9a3a('0x11')]()==='in'||_0x31f987['direction'][_0x9a3a('0x11')]()===_0x9a3a('0x12')&&!_0x31f987[_0x9a3a('0x13')]&&!_['isNil'](_0x31f987[_0x9a3a('0x14')])){_0x20209f['ChatInteraction'][_0x9a3a('0x15')]({'where':{'id':_0x31f987['ChatInteractionId']}})['then'](function(_0x5bbdea){if(_0x5bbdea){_0x5bbdea['update']({'lastMsgAt':_0x31f987['createdAt'],'lastMsgDirection':_0x31f987[_0x9a3a('0x16')][_0x9a3a('0x11')]()});}})['catch'](function(_0x5d499d){console['error'](_0x5d499d);});}_0x40f297();}},'charset':_0x9a3a('0x17'),'collate':'utf8mb4_unicode_ci'});};