1510b6732a10349f928c50824450848325017fe3
[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 _0x5eb3=['plainBody','subject','FULLTEXT','models','get','direction','toLowerCase','out','secret','isNil','UserId','findOne','MailInteractionId','catch','error','utf8mb4','lodash','util','../../config/logger','api','moment','bluebird','request-promise','html-to-text','rimraf','../../config/environment','./mailMessage.attributes','exports','define','MailMessage','messageId','fti_mail_messages'];(function(_0x363618,_0x5ebf3a){var _0x496dee=function(_0x3b312a){while(--_0x3b312a){_0x363618['push'](_0x363618['shift']());}};_0x496dee(++_0x5ebf3a);}(_0x5eb3,0xd0));var _0x35eb=function(_0x34ad72,_0x1e43f6){_0x34ad72=_0x34ad72-0x0;var _0x5c9aa8=_0x5eb3[_0x34ad72];return _0x5c9aa8;};'use strict';var _=require(_0x35eb('0x0'));var util=require(_0x35eb('0x1'));var logger=require(_0x35eb('0x2'))(_0x35eb('0x3'));var moment=require(_0x35eb('0x4'));var BPromise=require(_0x35eb('0x5'));var rp=require(_0x35eb('0x6'));var htmlToText=require(_0x35eb('0x7'));var fs=require('fs');var path=require('path');var rimraf=require(_0x35eb('0x8'));var config=require(_0x35eb('0x9'));var attributes=require(_0x35eb('0xa'));module[_0x35eb('0xb')]=function(_0x2a8d75,_0x45a283){return _0x2a8d75[_0x35eb('0xc')](_0x35eb('0xd'),attributes,{'tableName':'mail_messages','paranoid':![],'indexes':[{'name':_0x35eb('0xe'),'fields':[_0x35eb('0xe')]},{'name':_0x35eb('0xf'),'fields':[_0x35eb('0x10'),_0x35eb('0x11')],'type':_0x35eb('0x12')}],'timestamps':!![],'hooks':{'beforeCreate':function(_0x17d485,_0x11587f,_0x42bb21){if(_0x17d485['body']){_0x17d485[_0x35eb('0x10')]=htmlToText['fromString'](_0x17d485['body'],{'preserveNewlines':!![],'singleNewLineParagraphs':!![],'uppercaseHeadings':![],'noLinkBrackets':!![],'ignoreImage':!![]});}_0x42bb21(null,_0x11587f);},'afterCreate':function(_0x2267b4,_0xc51210,_0x234265){var _0x11ea04=_0x2a8d75[_0x35eb('0x13')];var _0x1d927a=_0x2267b4[_0x35eb('0x14')]({'plain':!![]});if(_0x1d927a[_0x35eb('0x15')][_0x35eb('0x16')]()==='in'||_0x1d927a[_0x35eb('0x15')][_0x35eb('0x16')]()===_0x35eb('0x17')&&!_0x1d927a[_0x35eb('0x18')]&&!_[_0x35eb('0x19')](_0x1d927a[_0x35eb('0x1a')])){_0x11ea04['MailInteraction'][_0x35eb('0x1b')]({'where':{'id':_0x1d927a[_0x35eb('0x1c')]}})['then'](function(_0x18d470){if(_0x18d470){_0x18d470['update']({'lastMsgAt':_0x1d927a['createdAt'],'lastMsgDirection':_0x1d927a[_0x35eb('0x15')][_0x35eb('0x16')]()});}})[_0x35eb('0x1d')](function(_0x247e2e){console[_0x35eb('0x1e')](_0x247e2e);});}_0x234265();}},'charset':_0x35eb('0x1f'),'collate':'utf8mb4_unicode_ci'});};