dccaf7ad2bfcdd1d1b6357fc3bbf778bacc0957b
[motion2.git] / server / api / mailMessage / mailMessage.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 _0xf84c=['moment','path','../../config/environment','./mailMessage.attributes','exports','define','MailMessage','mail_messages','messageId','fti_mail_messages','subject','FULLTEXT','body','plainBody','fromString','get','direction','secret','MailInteraction','MailInteractionId','then','toLowerCase','catch','error','utf8mb4_unicode_ci','lodash','util'];(function(_0x37bf43,_0x5b2339){var _0x4101c5=function(_0x382432){while(--_0x382432){_0x37bf43['push'](_0x37bf43['shift']());}};_0x4101c5(++_0x5b2339);}(_0xf84c,0x127));var _0xcf84=function(_0x3dd15e,_0x1f0015){_0x3dd15e=_0x3dd15e-0x0;var _0x231fd0=_0xf84c[_0x3dd15e];return _0x231fd0;};'use strict';var _=require(_0xcf84('0x0'));var util=require(_0xcf84('0x1'));var logger=require('../../config/logger')('api');var moment=require(_0xcf84('0x2'));var BPromise=require('bluebird');var rp=require('request-promise');var htmlToText=require('html-to-text');var fs=require('fs');var path=require(_0xcf84('0x3'));var rimraf=require('rimraf');var config=require(_0xcf84('0x4'));var attributes=require(_0xcf84('0x5'));module[_0xcf84('0x6')]=function(_0x1c2752,_0x581aa8){return _0x1c2752[_0xcf84('0x7')](_0xcf84('0x8'),attributes,{'tableName':_0xcf84('0x9'),'paranoid':![],'indexes':[{'name':_0xcf84('0xa'),'fields':[_0xcf84('0xa')]},{'name':_0xcf84('0xb'),'fields':['plainBody',_0xcf84('0xc')],'type':_0xcf84('0xd')}],'timestamps':!![],'hooks':{'beforeCreate':function(_0x4bab3f,_0x4b0f7d,_0x2e9679){if(_0x4bab3f[_0xcf84('0xe')]){_0x4bab3f[_0xcf84('0xf')]=htmlToText[_0xcf84('0x10')](_0x4bab3f['body'],{'preserveNewlines':!![],'singleNewLineParagraphs':!![],'uppercaseHeadings':![],'noLinkBrackets':!![],'ignoreImage':!![]});}_0x2e9679(null,_0x4b0f7d);},'afterCreate':function(_0x1761d6,_0x3cdfe5,_0x5797ff){var _0x65a1f7=_0x1c2752['models'];var _0x51d842=_0x1761d6[_0xcf84('0x11')]({'plain':!![]});if(_0x51d842[_0xcf84('0x12')]['toLowerCase']()==='in'||_0x51d842['direction']['toLowerCase']()==='out'&&!_0x51d842[_0xcf84('0x13')]&&!_['isNil'](_0x51d842['UserId'])){_0x65a1f7[_0xcf84('0x14')]['findOne']({'where':{'id':_0x51d842[_0xcf84('0x15')]}})[_0xcf84('0x16')](function(_0x27dc21){if(_0x27dc21){_0x27dc21['update']({'lastMsgAt':_0x51d842['createdAt'],'lastMsgDirection':_0x51d842[_0xcf84('0x12')][_0xcf84('0x17')]()});}})[_0xcf84('0x18')](function(_0x6c2123){console[_0xcf84('0x19')](_0x6c2123);});}_0x5797ff();}},'charset':'utf8mb4','collate':_0xcf84('0x1a')});};