8385d442a01a8fd8abe47851d64b825ca4540b70
[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 _0x1022=['MailInteraction','MailInteractionId','then','update','createdAt','catch','error','utf8mb4','utf8mb4_unicode_ci','util','../../config/logger','moment','bluebird','request-promise','html-to-text','path','rimraf','../../config/environment','exports','define','MailMessage','mail_messages','messageId','fti_mail_messages','FULLTEXT','body','plainBody','fromString','models','get','direction','toLowerCase','secret','isNil'];(function(_0x32ce54,_0x55e52f){var _0x42482b=function(_0x5a1317){while(--_0x5a1317){_0x32ce54['push'](_0x32ce54['shift']());}};_0x42482b(++_0x55e52f);}(_0x1022,0x1a1));var _0x2102=function(_0x2166e1,_0x4a9a63){_0x2166e1=_0x2166e1-0x0;var _0x42ada1=_0x1022[_0x2166e1];return _0x42ada1;};'use strict';var _=require('lodash');var util=require(_0x2102('0x0'));var logger=require(_0x2102('0x1'))('api');var moment=require(_0x2102('0x2'));var BPromise=require(_0x2102('0x3'));var rp=require(_0x2102('0x4'));var htmlToText=require(_0x2102('0x5'));var fs=require('fs');var path=require(_0x2102('0x6'));var rimraf=require(_0x2102('0x7'));var config=require(_0x2102('0x8'));var attributes=require('./mailMessage.attributes');module[_0x2102('0x9')]=function(_0x53115b,_0x561d9f){return _0x53115b[_0x2102('0xa')](_0x2102('0xb'),attributes,{'tableName':_0x2102('0xc'),'paranoid':![],'indexes':[{'name':_0x2102('0xd'),'fields':[_0x2102('0xd')]},{'name':_0x2102('0xe'),'fields':['plainBody','subject'],'type':_0x2102('0xf')}],'timestamps':!![],'hooks':{'beforeCreate':function(_0x72cabf,_0x2aecfb,_0x13fed9){if(_0x72cabf[_0x2102('0x10')]){_0x72cabf[_0x2102('0x11')]=htmlToText[_0x2102('0x12')](_0x72cabf[_0x2102('0x10')],{'preserveNewlines':!![],'singleNewLineParagraphs':!![],'uppercaseHeadings':![],'noLinkBrackets':!![],'ignoreImage':!![]});}_0x13fed9(null,_0x2aecfb);},'afterCreate':function(_0x468777,_0x40fd85,_0x3cbb07){var _0x41a57c=_0x53115b[_0x2102('0x13')];var _0x3f07bb=_0x468777[_0x2102('0x14')]({'plain':!![]});if(_0x3f07bb[_0x2102('0x15')][_0x2102('0x16')]()==='in'||_0x3f07bb[_0x2102('0x15')][_0x2102('0x16')]()==='out'&&!_0x3f07bb[_0x2102('0x17')]&&!_[_0x2102('0x18')](_0x3f07bb['UserId'])){_0x41a57c[_0x2102('0x19')]['findOne']({'where':{'id':_0x3f07bb[_0x2102('0x1a')]}})[_0x2102('0x1b')](function(_0x2479c9){if(_0x2479c9){_0x2479c9[_0x2102('0x1c')]({'lastMsgAt':_0x3f07bb[_0x2102('0x1d')],'lastMsgDirection':_0x3f07bb[_0x2102('0x15')][_0x2102('0x16')]()});}})[_0x2102('0x1e')](function(_0x30192a){console[_0x2102('0x1f')](_0x30192a);});}_0x3cbb07();}},'charset':_0x2102('0x20'),'collate':_0x2102('0x21')});};