77fc7d519bc30834c6fac72f6c0928c187524a03
[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 _0xabe5=['utf8mb4','utf8mb4_unicode_ci','lodash','util','../../config/logger','api','bluebird','request-promise','path','rimraf','define','MailMessage','messageId','fti_mail_messages','plainBody','FULLTEXT','body','fromString','direction','toLowerCase','out','isNil','findOne','update','createdAt','catch'];(function(_0x47a5bd,_0x508329){var _0x5c2184=function(_0x40ddea){while(--_0x40ddea){_0x47a5bd['push'](_0x47a5bd['shift']());}};_0x5c2184(++_0x508329);}(_0xabe5,0xec));var _0x5abe=function(_0x15bfa5,_0x3645b2){_0x15bfa5=_0x15bfa5-0x0;var _0x16f5cc=_0xabe5[_0x15bfa5];return _0x16f5cc;};'use strict';var _=require(_0x5abe('0x0'));var util=require(_0x5abe('0x1'));var logger=require(_0x5abe('0x2'))(_0x5abe('0x3'));var moment=require('moment');var BPromise=require(_0x5abe('0x4'));var rp=require(_0x5abe('0x5'));var htmlToText=require('html-to-text');var fs=require('fs');var path=require(_0x5abe('0x6'));var rimraf=require(_0x5abe('0x7'));var config=require('../../config/environment');var attributes=require('./mailMessage.attributes');module['exports']=function(_0x5ecc44,_0x18051e){return _0x5ecc44[_0x5abe('0x8')](_0x5abe('0x9'),attributes,{'tableName':'mail_messages','paranoid':![],'indexes':[{'name':_0x5abe('0xa'),'fields':[_0x5abe('0xa')]},{'name':_0x5abe('0xb'),'fields':[_0x5abe('0xc'),'subject'],'type':_0x5abe('0xd')}],'timestamps':!![],'hooks':{'beforeCreate':function(_0x49c984,_0x375f44,_0xc9ada2){if(_0x49c984[_0x5abe('0xe')]){_0x49c984[_0x5abe('0xc')]=htmlToText[_0x5abe('0xf')](_0x49c984[_0x5abe('0xe')],{'preserveNewlines':!![],'singleNewLineParagraphs':!![],'uppercaseHeadings':![],'noLinkBrackets':!![],'ignoreImage':!![]});}_0xc9ada2(null,_0x375f44);},'afterCreate':function(_0x3e74f0,_0x3d84b6,_0x5a3725){var _0x5602d1=_0x5ecc44['models'];var _0x2fab1c=_0x3e74f0['get']({'plain':!![]});if(_0x2fab1c[_0x5abe('0x10')]['toLowerCase']()==='in'||_0x2fab1c['direction'][_0x5abe('0x11')]()===_0x5abe('0x12')&&!_0x2fab1c['secret']&&!_[_0x5abe('0x13')](_0x2fab1c['UserId'])){_0x5602d1['MailInteraction'][_0x5abe('0x14')]({'where':{'id':_0x2fab1c['MailInteractionId']}})['then'](function(_0x15c629){if(_0x15c629){_0x15c629[_0x5abe('0x15')]({'lastMsgAt':_0x2fab1c[_0x5abe('0x16')],'lastMsgDirection':_0x2fab1c[_0x5abe('0x10')][_0x5abe('0x11')]()});}})[_0x5abe('0x17')](function(_0x2e9394){console['error'](_0x2e9394);});}_0x5a3725();}},'charset':_0x5abe('0x18'),'collate':_0x5abe('0x19')});};