6af040c223c97d3491871055f4b9922c84586f56
[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 _0xfdb2=['../../config/logger','api','moment','bluebird','path','../../config/environment','./chatMessage.attributes','exports','ChatMessage','fti_chat_messages','body','models','get','direction','toLowerCase','UserId','findOne','ChatInteractionId','error','utf8mb4','utf8mb4_unicode_ci','lodash','util'];(function(_0xcf196c,_0x56fe53){var _0x132ef3=function(_0x34d04e){while(--_0x34d04e){_0xcf196c['push'](_0xcf196c['shift']());}};_0x132ef3(++_0x56fe53);}(_0xfdb2,0x185));var _0x2fdb=function(_0x375600,_0x2dd0f){_0x375600=_0x375600-0x0;var _0x463214=_0xfdb2[_0x375600];return _0x463214;};'use strict';var _=require(_0x2fdb('0x0'));var util=require(_0x2fdb('0x1'));var logger=require(_0x2fdb('0x2'))(_0x2fdb('0x3'));var moment=require(_0x2fdb('0x4'));var BPromise=require(_0x2fdb('0x5'));var rp=require('request-promise');var fs=require('fs');var path=require(_0x2fdb('0x6'));var rimraf=require('rimraf');var config=require(_0x2fdb('0x7'));var attributes=require(_0x2fdb('0x8'));module[_0x2fdb('0x9')]=function(_0x2bd71b,_0x37ea3e){return _0x2bd71b['define'](_0x2fdb('0xa'),attributes,{'tableName':'chat_messages','paranoid':![],'indexes':[{'name':_0x2fdb('0xb'),'fields':[_0x2fdb('0xc')],'type':'FULLTEXT'}],'timestamps':!![],'hooks':{'afterCreate':function(_0x41c5c7,_0x570f1a,_0x5c02d3){var _0x42e430=_0x2bd71b[_0x2fdb('0xd')];var _0x521502=_0x41c5c7[_0x2fdb('0xe')]({'plain':!![]});if(_0x521502[_0x2fdb('0xf')][_0x2fdb('0x10')]()==='in'||_0x521502[_0x2fdb('0xf')][_0x2fdb('0x10')]()==='out'&&!_0x521502['secret']&&!_['isNil'](_0x521502[_0x2fdb('0x11')])){_0x42e430['ChatInteraction'][_0x2fdb('0x12')]({'where':{'id':_0x521502[_0x2fdb('0x13')]}})['then'](function(_0x57a8e0){if(_0x57a8e0){_0x57a8e0['update']({'lastMsgAt':_0x521502['createdAt'],'lastMsgDirection':_0x521502[_0x2fdb('0xf')][_0x2fdb('0x10')]()});}})['catch'](function(_0x482156){console[_0x2fdb('0x14')](_0x482156);});}_0x5c02d3();}},'charset':_0x2fdb('0x15'),'collate':_0x2fdb('0x16')});};