16086cba125ef41aa9a06c64569d2f6bec5b2c54
[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 _0x1cb3=['error','utf8mb4_unicode_ci','lodash','util','../../config/logger','api','moment','bluebird','request-promise','html-to-text','path','rimraf','../../config/environment','./mailMessage.attributes','exports','define','MailMessage','mail_messages','messageId','fti_mail_messages','plainBody','FULLTEXT','body','fromString','models','direction','toLowerCase','out','isNil','UserId','MailInteractionId','then','update','createdAt','catch'];(function(_0x1d929a,_0xedf23){var _0x521437=function(_0x294bd4){while(--_0x294bd4){_0x1d929a['push'](_0x1d929a['shift']());}};_0x521437(++_0xedf23);}(_0x1cb3,0x1a6));var _0x31cb=function(_0x3691bf,_0x337821){_0x3691bf=_0x3691bf-0x0;var _0x4d9163=_0x1cb3[_0x3691bf];return _0x4d9163;};'use strict';var _=require(_0x31cb('0x0'));var util=require(_0x31cb('0x1'));var logger=require(_0x31cb('0x2'))(_0x31cb('0x3'));var moment=require(_0x31cb('0x4'));var BPromise=require(_0x31cb('0x5'));var rp=require(_0x31cb('0x6'));var htmlToText=require(_0x31cb('0x7'));var fs=require('fs');var path=require(_0x31cb('0x8'));var rimraf=require(_0x31cb('0x9'));var config=require(_0x31cb('0xa'));var attributes=require(_0x31cb('0xb'));module[_0x31cb('0xc')]=function(_0xe630c9,_0x2c89ef){return _0xe630c9[_0x31cb('0xd')](_0x31cb('0xe'),attributes,{'tableName':_0x31cb('0xf'),'paranoid':![],'indexes':[{'name':_0x31cb('0x10'),'fields':['messageId']},{'name':_0x31cb('0x11'),'fields':[_0x31cb('0x12'),'subject'],'type':_0x31cb('0x13')}],'timestamps':!![],'hooks':{'beforeCreate':function(_0x320ab3,_0x54704d,_0x34985d){if(_0x320ab3[_0x31cb('0x14')]){_0x320ab3['plainBody']=htmlToText[_0x31cb('0x15')](_0x320ab3[_0x31cb('0x14')],{'preserveNewlines':!![],'singleNewLineParagraphs':!![],'uppercaseHeadings':![],'noLinkBrackets':!![],'ignoreImage':!![]});}_0x34985d(null,_0x54704d);},'afterCreate':function(_0x58d83c,_0x144224,_0x58814e){var _0x1075c2=_0xe630c9[_0x31cb('0x16')];var _0x277f4b=_0x58d83c['get']({'plain':!![]});if(_0x277f4b[_0x31cb('0x17')][_0x31cb('0x18')]()==='in'||_0x277f4b[_0x31cb('0x17')][_0x31cb('0x18')]()===_0x31cb('0x19')&&!_0x277f4b['secret']&&!_[_0x31cb('0x1a')](_0x277f4b[_0x31cb('0x1b')])){_0x1075c2['MailInteraction']['findOne']({'where':{'id':_0x277f4b[_0x31cb('0x1c')]}})[_0x31cb('0x1d')](function(_0x14f231){if(_0x14f231){_0x14f231[_0x31cb('0x1e')]({'lastMsgAt':_0x277f4b[_0x31cb('0x1f')],'lastMsgDirection':_0x277f4b[_0x31cb('0x17')][_0x31cb('0x18')](),'lastMsgBody':_0x277f4b['body']});}})[_0x31cb('0x20')](function(_0x246f97){console[_0x31cb('0x21')](_0x246f97);});}_0x58814e();}},'charset':'utf8mb4','collate':_0x31cb('0x22')});};