a8cb8ff8851effee29a9b2cc77502f0ebf9643a0
[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 _0x7cfe=['catch','error','utf8mb4','utf8mb4_unicode_ci','lodash','util','../../config/logger','moment','bluebird','request-promise','html-to-text','rimraf','../../config/environment','exports','MailMessage','mail_messages','messageId','plainBody','subject','FULLTEXT','body','models','get','direction','out','secret','UserId','MailInteraction','findOne','then','update','createdAt','toLowerCase'];(function(_0x376205,_0x285b4b){var _0x2e867b=function(_0x3799c7){while(--_0x3799c7){_0x376205['push'](_0x376205['shift']());}};_0x2e867b(++_0x285b4b);}(_0x7cfe,0xca));var _0xe7cf=function(_0x4778f2,_0x4a3c46){_0x4778f2=_0x4778f2-0x0;var _0x3d138a=_0x7cfe[_0x4778f2];return _0x3d138a;};'use strict';var _=require(_0xe7cf('0x0'));var util=require(_0xe7cf('0x1'));var logger=require(_0xe7cf('0x2'))('api');var moment=require(_0xe7cf('0x3'));var BPromise=require(_0xe7cf('0x4'));var rp=require(_0xe7cf('0x5'));var htmlToText=require(_0xe7cf('0x6'));var fs=require('fs');var path=require('path');var rimraf=require(_0xe7cf('0x7'));var config=require(_0xe7cf('0x8'));var attributes=require('./mailMessage.attributes');module[_0xe7cf('0x9')]=function(_0x32ad7a,_0x352608){return _0x32ad7a['define'](_0xe7cf('0xa'),attributes,{'tableName':_0xe7cf('0xb'),'paranoid':![],'indexes':[{'name':_0xe7cf('0xc'),'fields':[_0xe7cf('0xc')]},{'name':'fti_mail_messages','fields':[_0xe7cf('0xd'),_0xe7cf('0xe')],'type':_0xe7cf('0xf')}],'timestamps':!![],'hooks':{'beforeCreate':function(_0x7f7ef3,_0x670b4b,_0x289bf9){if(_0x7f7ef3[_0xe7cf('0x10')]){_0x7f7ef3[_0xe7cf('0xd')]=htmlToText['fromString'](_0x7f7ef3['body'],{'preserveNewlines':!![],'singleNewLineParagraphs':!![],'uppercaseHeadings':![],'noLinkBrackets':!![],'ignoreImage':!![]});}_0x289bf9(null,_0x670b4b);},'afterCreate':function(_0x1155da,_0x2ad7ef,_0x5089a4){var _0x435f0d=_0x32ad7a[_0xe7cf('0x11')];var _0x52f9e9=_0x1155da[_0xe7cf('0x12')]({'plain':!![]});if(_0x52f9e9['direction']['toLowerCase']()==='in'||_0x52f9e9[_0xe7cf('0x13')]['toLowerCase']()===_0xe7cf('0x14')&&!_0x52f9e9[_0xe7cf('0x15')]&&!_['isNil'](_0x52f9e9[_0xe7cf('0x16')])){_0x435f0d[_0xe7cf('0x17')][_0xe7cf('0x18')]({'where':{'id':_0x52f9e9['MailInteractionId']}})[_0xe7cf('0x19')](function(_0x111c90){if(_0x111c90){_0x111c90[_0xe7cf('0x1a')]({'lastMsgAt':_0x52f9e9[_0xe7cf('0x1b')],'lastMsgDirection':_0x52f9e9['direction'][_0xe7cf('0x1c')](),'lastMsgBody':_0x52f9e9[_0xe7cf('0x10')]});}})[_0xe7cf('0x1d')](function(_0x394068){console[_0xe7cf('0x1e')](_0x394068);});}_0x5089a4();}},'charset':_0xe7cf('0x1f'),'collate':_0xe7cf('0x20')});};