87bb02b73e91a47e9751f24a12f3a5eb93e03097
[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 _0xe634=['body','models','get','direction','toLowerCase','out','secret','UserId','ChatInteraction','findOne','ChatInteractionId','then','update','catch','error','utf8mb4','utf8mb4_unicode_ci','lodash','../../config/logger','moment','request-promise','path','rimraf','../../config/environment','exports','define','chat_messages'];(function(_0x42cae2,_0x284ef8){var _0x5f256f=function(_0x41abc8){while(--_0x41abc8){_0x42cae2['push'](_0x42cae2['shift']());}};_0x5f256f(++_0x284ef8);}(_0xe634,0x7d));var _0x4e63=function(_0x41de7b,_0x36e026){_0x41de7b=_0x41de7b-0x0;var _0xe9a0b8=_0xe634[_0x41de7b];return _0xe9a0b8;};'use strict';var _=require(_0x4e63('0x0'));var util=require('util');var logger=require(_0x4e63('0x1'))('api');var moment=require(_0x4e63('0x2'));var BPromise=require('bluebird');var rp=require(_0x4e63('0x3'));var fs=require('fs');var path=require(_0x4e63('0x4'));var rimraf=require(_0x4e63('0x5'));var config=require(_0x4e63('0x6'));var attributes=require('./chatMessage.attributes');module[_0x4e63('0x7')]=function(_0x260b27,_0x35bc15){return _0x260b27[_0x4e63('0x8')]('ChatMessage',attributes,{'tableName':_0x4e63('0x9'),'paranoid':![],'indexes':[{'name':'fti_chat_messages','fields':[_0x4e63('0xa')],'type':'FULLTEXT'}],'timestamps':!![],'hooks':{'afterCreate':function(_0x654481,_0xe777be,_0x1c4245){var _0x1a9324=_0x260b27[_0x4e63('0xb')];var _0x199260=_0x654481[_0x4e63('0xc')]({'plain':!![]});if(_0x199260[_0x4e63('0xd')][_0x4e63('0xe')]()==='in'||_0x199260['direction'][_0x4e63('0xe')]()===_0x4e63('0xf')&&!_0x199260[_0x4e63('0x10')]&&!_['isNil'](_0x199260[_0x4e63('0x11')])){_0x1a9324[_0x4e63('0x12')][_0x4e63('0x13')]({'where':{'id':_0x199260[_0x4e63('0x14')]}})[_0x4e63('0x15')](function(_0x5f47ce){if(_0x5f47ce){_0x5f47ce[_0x4e63('0x16')]({'lastMsgAt':_0x199260['createdAt'],'lastMsgDirection':_0x199260[_0x4e63('0xd')]['toLowerCase']()});}})[_0x4e63('0x17')](function(_0x261792){console[_0x4e63('0x18')](_0x261792);});}_0x1c4245();}},'charset':_0x4e63('0x19'),'collate':_0x4e63('0x1a')});};