2039ef9407a56643e94b4fb2d67589c6b8ee06b7
[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 _0xf354=['subject','FULLTEXT','fromString','body','models','direction','toLowerCase','out','secret','MailInteraction','findOne','MailInteractionId','then','update','catch','error','utf8mb4','utf8mb4_unicode_ci','lodash','../../config/logger','api','moment','bluebird','request-promise','path','rimraf','../../config/environment','./mailMessage.attributes','exports','define','mail_messages','messageId','plainBody'];(function(_0x365e54,_0x44be74){var _0x13317a=function(_0x2d917f){while(--_0x2d917f){_0x365e54['push'](_0x365e54['shift']());}};_0x13317a(++_0x44be74);}(_0xf354,0x1bf));var _0x4f35=function(_0x9fa9fd,_0x29ed49){_0x9fa9fd=_0x9fa9fd-0x0;var _0x3bcabd=_0xf354[_0x9fa9fd];return _0x3bcabd;};'use strict';var _=require(_0x4f35('0x0'));var util=require('util');var logger=require(_0x4f35('0x1'))(_0x4f35('0x2'));var moment=require(_0x4f35('0x3'));var BPromise=require(_0x4f35('0x4'));var rp=require(_0x4f35('0x5'));var htmlToText=require('html-to-text');var fs=require('fs');var path=require(_0x4f35('0x6'));var rimraf=require(_0x4f35('0x7'));var config=require(_0x4f35('0x8'));var attributes=require(_0x4f35('0x9'));module[_0x4f35('0xa')]=function(_0x5e009d,_0x2d780f){return _0x5e009d[_0x4f35('0xb')]('MailMessage',attributes,{'tableName':_0x4f35('0xc'),'paranoid':![],'indexes':[{'name':_0x4f35('0xd'),'fields':[_0x4f35('0xd')]},{'name':'fti_mail_messages','fields':[_0x4f35('0xe'),_0x4f35('0xf')],'type':_0x4f35('0x10')}],'timestamps':!![],'hooks':{'beforeCreate':function(_0x392da2,_0x15d623,_0x5980dd){if(_0x392da2['body']){_0x392da2[_0x4f35('0xe')]=htmlToText[_0x4f35('0x11')](_0x392da2[_0x4f35('0x12')],{'preserveNewlines':!![],'singleNewLineParagraphs':!![],'uppercaseHeadings':![],'noLinkBrackets':!![],'ignoreImage':!![]});}_0x5980dd(null,_0x15d623);},'afterCreate':function(_0x2a9433,_0x9646af,_0x557169){var _0x36f2a1=_0x5e009d[_0x4f35('0x13')];var _0x45c4c9=_0x2a9433['get']({'plain':!![]});if(_0x45c4c9[_0x4f35('0x14')]['toLowerCase']()==='in'||_0x45c4c9['direction'][_0x4f35('0x15')]()===_0x4f35('0x16')&&!_0x45c4c9[_0x4f35('0x17')]&&!_['isNil'](_0x45c4c9['UserId'])){_0x36f2a1[_0x4f35('0x18')][_0x4f35('0x19')]({'where':{'id':_0x45c4c9[_0x4f35('0x1a')]}})[_0x4f35('0x1b')](function(_0x418553){if(_0x418553){_0x418553[_0x4f35('0x1c')]({'lastMsgAt':_0x45c4c9['createdAt'],'lastMsgDirection':_0x45c4c9[_0x4f35('0x14')][_0x4f35('0x15')]()});}})[_0x4f35('0x1d')](function(_0x352db){console[_0x4f35('0x1e')](_0x352db);});}_0x557169();}},'charset':_0x4f35('0x1f'),'collate':_0x4f35('0x20')});};