6aff88cca29c68da041b76d6bff9fca10471bd22
[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 _0x42e3=['FULLTEXT','get','direction','toLowerCase','secret','isNil','findOne','ChatInteractionId','then','update','createdAt','error','utf8mb4','utf8mb4_unicode_ci','util','../../config/logger','api','bluebird','request-promise','path','rimraf','exports','ChatMessage','chat_messages','fti_chat_messages'];(function(_0xbca1b1,_0x33f0ce){var _0x4e1686=function(_0x58a80c){while(--_0x58a80c){_0xbca1b1['push'](_0xbca1b1['shift']());}};_0x4e1686(++_0x33f0ce);}(_0x42e3,0x16c));var _0x342e=function(_0x45dfb9,_0x4110bb){_0x45dfb9=_0x45dfb9-0x0;var _0x2b6b76=_0x42e3[_0x45dfb9];return _0x2b6b76;};'use strict';var _=require('lodash');var util=require(_0x342e('0x0'));var logger=require(_0x342e('0x1'))(_0x342e('0x2'));var moment=require('moment');var BPromise=require(_0x342e('0x3'));var rp=require(_0x342e('0x4'));var fs=require('fs');var path=require(_0x342e('0x5'));var rimraf=require(_0x342e('0x6'));var config=require('../../config/environment');var attributes=require('./chatMessage.attributes');module[_0x342e('0x7')]=function(_0xdee4c6,_0x22c11c){return _0xdee4c6['define'](_0x342e('0x8'),attributes,{'tableName':_0x342e('0x9'),'paranoid':![],'indexes':[{'name':_0x342e('0xa'),'fields':['body'],'type':_0x342e('0xb')}],'timestamps':!![],'hooks':{'afterCreate':function(_0xfe1eb7,_0x1864da,_0x51b06d){var _0x56c53f=_0xdee4c6['models'];var _0x4f47a7=_0xfe1eb7[_0x342e('0xc')]({'plain':!![]});if(_0x4f47a7['direction']['toLowerCase']()==='in'||_0x4f47a7[_0x342e('0xd')][_0x342e('0xe')]()==='out'&&!_0x4f47a7[_0x342e('0xf')]&&!_[_0x342e('0x10')](_0x4f47a7['UserId'])){_0x56c53f['ChatInteraction'][_0x342e('0x11')]({'where':{'id':_0x4f47a7[_0x342e('0x12')]}})[_0x342e('0x13')](function(_0x2c4117){if(_0x2c4117){_0x2c4117[_0x342e('0x14')]({'lastMsgAt':_0x4f47a7[_0x342e('0x15')],'lastMsgDirection':_0x4f47a7[_0x342e('0xd')][_0x342e('0xe')]()});}})['catch'](function(_0x3d5b32){console[_0x342e('0x16')](_0x3d5b32);});}_0x51b06d();}},'charset':_0x342e('0x17'),'collate':_0x342e('0x18')});};