7962fda606d6b1a7b2f9deca7389b46772df8cdd
[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 _0x6a61=['ChatInteraction','findOne','ChatInteractionId','then','update','createdAt','catch','error','utf8mb4','utf8mb4_unicode_ci','lodash','../../config/logger','api','moment','bluebird','request-promise','path','../../config/environment','./chatMessage.attributes','exports','fti_chat_messages','FULLTEXT','models','direction','toLowerCase','out','secret','isNil','UserId'];(function(_0x17f452,_0x99c067){var _0x5cc495=function(_0xaa4ae){while(--_0xaa4ae){_0x17f452['push'](_0x17f452['shift']());}};_0x5cc495(++_0x99c067);}(_0x6a61,0x1a0));var _0x16a6=function(_0x52314e,_0x188188){_0x52314e=_0x52314e-0x0;var _0x2b4b4e=_0x6a61[_0x52314e];return _0x2b4b4e;};'use strict';var _=require(_0x16a6('0x0'));var util=require('util');var logger=require(_0x16a6('0x1'))(_0x16a6('0x2'));var moment=require(_0x16a6('0x3'));var BPromise=require(_0x16a6('0x4'));var rp=require(_0x16a6('0x5'));var fs=require('fs');var path=require(_0x16a6('0x6'));var rimraf=require('rimraf');var config=require(_0x16a6('0x7'));var attributes=require(_0x16a6('0x8'));module[_0x16a6('0x9')]=function(_0x1fe432,_0x4746fb){return _0x1fe432['define']('ChatMessage',attributes,{'tableName':'chat_messages','paranoid':![],'indexes':[{'name':_0x16a6('0xa'),'fields':['body'],'type':_0x16a6('0xb')}],'timestamps':!![],'hooks':{'afterCreate':function(_0x2a2e93,_0x1c4ae9,_0x5c9c58){var _0x51144d=_0x1fe432[_0x16a6('0xc')];var _0x4e617f=_0x2a2e93['get']({'plain':!![]});if(_0x4e617f[_0x16a6('0xd')][_0x16a6('0xe')]()==='in'||_0x4e617f['direction'][_0x16a6('0xe')]()===_0x16a6('0xf')&&!_0x4e617f[_0x16a6('0x10')]&&!_[_0x16a6('0x11')](_0x4e617f[_0x16a6('0x12')])){_0x51144d[_0x16a6('0x13')][_0x16a6('0x14')]({'where':{'id':_0x4e617f[_0x16a6('0x15')]}})[_0x16a6('0x16')](function(_0x34d667){if(_0x34d667){_0x34d667[_0x16a6('0x17')]({'lastMsgAt':_0x4e617f[_0x16a6('0x18')],'lastMsgDirection':_0x4e617f[_0x16a6('0xd')]['toLowerCase']()});}})[_0x16a6('0x19')](function(_0x873e63){console[_0x16a6('0x1a')](_0x873e63);});}_0x5c9c58();}},'charset':_0x16a6('0x1b'),'collate':_0x16a6('0x1c')});};