cce2780b28529573228fa20aebec099e47acebc4
[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 _0x33fd=['path','rimraf','../../config/environment','./mailMessage.attributes','exports','MailMessage','mail_messages','messageId','fti_mail_messages','plainBody','FULLTEXT','fromString','models','get','direction','toLowerCase','out','secret','UserId','MailInteraction','MailInteractionId','body','error','utf8mb4','utf8mb4_unicode_ci','lodash','util','api','moment','bluebird','html-to-text'];(function(_0x45138b,_0xec2bd6){var _0x398884=function(_0x408309){while(--_0x408309){_0x45138b['push'](_0x45138b['shift']());}};_0x398884(++_0xec2bd6);}(_0x33fd,0x111));var _0xd33f=function(_0x148287,_0x18fdc6){_0x148287=_0x148287-0x0;var _0x511244=_0x33fd[_0x148287];return _0x511244;};'use strict';var _=require(_0xd33f('0x0'));var util=require(_0xd33f('0x1'));var logger=require('../../config/logger')(_0xd33f('0x2'));var moment=require(_0xd33f('0x3'));var BPromise=require(_0xd33f('0x4'));var rp=require('request-promise');var htmlToText=require(_0xd33f('0x5'));var fs=require('fs');var path=require(_0xd33f('0x6'));var rimraf=require(_0xd33f('0x7'));var config=require(_0xd33f('0x8'));var attributes=require(_0xd33f('0x9'));module[_0xd33f('0xa')]=function(_0x55f9ce,_0x58f74e){return _0x55f9ce['define'](_0xd33f('0xb'),attributes,{'tableName':_0xd33f('0xc'),'paranoid':![],'indexes':[{'name':'messageId','fields':[_0xd33f('0xd')]},{'name':_0xd33f('0xe'),'fields':[_0xd33f('0xf'),'subject'],'type':_0xd33f('0x10')}],'timestamps':!![],'hooks':{'beforeCreate':function(_0x2810c7,_0x100347,_0x2594c6){if(_0x2810c7['body']){_0x2810c7[_0xd33f('0xf')]=htmlToText[_0xd33f('0x11')](_0x2810c7['body'],{'preserveNewlines':!![],'singleNewLineParagraphs':!![],'uppercaseHeadings':![],'noLinkBrackets':!![],'ignoreImage':!![]});}_0x2594c6(null,_0x100347);},'afterCreate':function(_0x924ef,_0x5ad6c4,_0x3b2507){var _0x161bca=_0x55f9ce[_0xd33f('0x12')];var _0x21ffc7=_0x924ef[_0xd33f('0x13')]({'plain':!![]});if(_0x21ffc7[_0xd33f('0x14')][_0xd33f('0x15')]()==='in'||_0x21ffc7['direction']['toLowerCase']()===_0xd33f('0x16')&&!_0x21ffc7[_0xd33f('0x17')]&&!_['isNil'](_0x21ffc7[_0xd33f('0x18')])){_0x161bca[_0xd33f('0x19')]['findOne']({'where':{'id':_0x21ffc7[_0xd33f('0x1a')]}})['then'](function(_0x5421ea){if(_0x5421ea){_0x5421ea['update']({'lastMsgAt':_0x21ffc7['createdAt'],'lastMsgDirection':_0x21ffc7[_0xd33f('0x14')][_0xd33f('0x15')](),'lastMsgBody':_0x21ffc7[_0xd33f('0x1b')]});}})['catch'](function(_0x13ecee){console[_0xd33f('0x1c')](_0x13ecee);});}_0x3b2507();}},'charset':_0xd33f('0x1d'),'collate':_0xd33f('0x1e')});};