Built motion from commit fe909640.|2.6.8
[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 _0xeac9=['error','utf8mb4','utf8mb4_unicode_ci','lodash','util','../../config/logger','api','moment','path','../../config/environment','./mailMessage.attributes','exports','define','MailMessage','mail_messages','messageId','fti_mail_messages','plainBody','body','fromString','get','direction','toLowerCase','out','isNil','UserId','MailInteraction','findOne','MailInteractionId','then','catch'];(function(_0x54d6b6,_0x431bdc){var _0x1f91ec=function(_0x47a79e){while(--_0x47a79e){_0x54d6b6['push'](_0x54d6b6['shift']());}};_0x1f91ec(++_0x431bdc);}(_0xeac9,0x139));var _0x9eac=function(_0x19e35c,_0x29cd1e){_0x19e35c=_0x19e35c-0x0;var _0x3e1fe8=_0xeac9[_0x19e35c];return _0x3e1fe8;};'use strict';var _=require(_0x9eac('0x0'));var util=require(_0x9eac('0x1'));var logger=require(_0x9eac('0x2'))(_0x9eac('0x3'));var moment=require(_0x9eac('0x4'));var BPromise=require('bluebird');var rp=require('request-promise');var htmlToText=require('html-to-text');var fs=require('fs');var path=require(_0x9eac('0x5'));var rimraf=require('rimraf');var config=require(_0x9eac('0x6'));var attributes=require(_0x9eac('0x7'));module[_0x9eac('0x8')]=function(_0x3de328,_0x257f33){return _0x3de328[_0x9eac('0x9')](_0x9eac('0xa'),attributes,{'tableName':_0x9eac('0xb'),'paranoid':![],'indexes':[{'name':'messageId','fields':[_0x9eac('0xc')]},{'name':_0x9eac('0xd'),'fields':[_0x9eac('0xe'),'subject'],'type':'FULLTEXT'}],'timestamps':!![],'hooks':{'beforeCreate':function(_0x4709d6,_0x517fd1,_0x2c50fe){if(_0x4709d6[_0x9eac('0xf')]){_0x4709d6['plainBody']=htmlToText[_0x9eac('0x10')](_0x4709d6['body'],{'preserveNewlines':!![],'singleNewLineParagraphs':!![],'uppercaseHeadings':![],'noLinkBrackets':!![],'ignoreImage':!![]});}_0x2c50fe(null,_0x517fd1);},'afterCreate':function(_0x4d6ebb,_0x18fec6,_0x224b45){var _0x157563=_0x3de328['models'];var _0x3fff90=_0x4d6ebb[_0x9eac('0x11')]({'plain':!![]});if(_0x3fff90[_0x9eac('0x12')][_0x9eac('0x13')]()==='in'||_0x3fff90['direction'][_0x9eac('0x13')]()===_0x9eac('0x14')&&!_0x3fff90['secret']&&!_[_0x9eac('0x15')](_0x3fff90[_0x9eac('0x16')])){_0x157563[_0x9eac('0x17')][_0x9eac('0x18')]({'where':{'id':_0x3fff90[_0x9eac('0x19')]}})[_0x9eac('0x1a')](function(_0x4884dd){if(_0x4884dd){_0x4884dd['update']({'lastMsgAt':_0x3fff90['createdAt'],'lastMsgDirection':_0x3fff90[_0x9eac('0x12')][_0x9eac('0x13')]()});}})[_0x9eac('0x1b')](function(_0x29b4a9){console[_0x9eac('0x1c')](_0x29b4a9);});}_0x224b45();}},'charset':_0x9eac('0x1d'),'collate':_0x9eac('0x1e')});};