a3d673fe32caba220408b49b84bda745955fc37c
[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 _0x2952=['body','fromString','models','get','direction','toLowerCase','out','secret','isNil','UserId','findOne','MailInteractionId','createdAt','catch','error','utf8mb4_unicode_ci','lodash','util','api','moment','bluebird','path','rimraf','../../config/environment','./mailMessage.attributes','exports','define','MailMessage','mail_messages','messageId','plainBody','subject'];(function(_0x1e6659,_0x1f860c){var _0x4d16e4=function(_0x21c05a){while(--_0x21c05a){_0x1e6659['push'](_0x1e6659['shift']());}};_0x4d16e4(++_0x1f860c);}(_0x2952,0x190));var _0x2295=function(_0x5d6456,_0x58ecc7){_0x5d6456=_0x5d6456-0x0;var _0x4d66c1=_0x2952[_0x5d6456];return _0x4d66c1;};'use strict';var _=require(_0x2295('0x0'));var util=require(_0x2295('0x1'));var logger=require('../../config/logger')(_0x2295('0x2'));var moment=require(_0x2295('0x3'));var BPromise=require(_0x2295('0x4'));var rp=require('request-promise');var htmlToText=require('html-to-text');var fs=require('fs');var path=require(_0x2295('0x5'));var rimraf=require(_0x2295('0x6'));var config=require(_0x2295('0x7'));var attributes=require(_0x2295('0x8'));module[_0x2295('0x9')]=function(_0xe512b,_0x199b45){return _0xe512b[_0x2295('0xa')](_0x2295('0xb'),attributes,{'tableName':_0x2295('0xc'),'paranoid':![],'indexes':[{'name':_0x2295('0xd'),'fields':['messageId']},{'name':'fti_mail_messages','fields':[_0x2295('0xe'),_0x2295('0xf')],'type':'FULLTEXT'}],'timestamps':!![],'hooks':{'beforeCreate':function(_0x1d187e,_0x106154,_0x193be4){if(_0x1d187e[_0x2295('0x10')]){_0x1d187e[_0x2295('0xe')]=htmlToText[_0x2295('0x11')](_0x1d187e[_0x2295('0x10')],{'preserveNewlines':!![],'singleNewLineParagraphs':!![],'uppercaseHeadings':![],'noLinkBrackets':!![],'ignoreImage':!![]});}_0x193be4(null,_0x106154);},'afterCreate':function(_0x4a8aaf,_0x48034b,_0x4c308e){var _0x3d585a=_0xe512b[_0x2295('0x12')];var _0x3bc67c=_0x4a8aaf[_0x2295('0x13')]({'plain':!![]});if(_0x3bc67c[_0x2295('0x14')][_0x2295('0x15')]()==='in'||_0x3bc67c[_0x2295('0x14')]['toLowerCase']()===_0x2295('0x16')&&!_0x3bc67c[_0x2295('0x17')]&&!_[_0x2295('0x18')](_0x3bc67c[_0x2295('0x19')])){_0x3d585a['MailInteraction'][_0x2295('0x1a')]({'where':{'id':_0x3bc67c[_0x2295('0x1b')]}})['then'](function(_0x2759de){if(_0x2759de){_0x2759de['update']({'lastMsgAt':_0x3bc67c[_0x2295('0x1c')],'lastMsgDirection':_0x3bc67c[_0x2295('0x14')]['toLowerCase'](),'lastMsgBody':_0x3bc67c['body']});}})[_0x2295('0x1d')](function(_0x5e1d90){console[_0x2295('0x1e')](_0x5e1d90);});}_0x4c308e();}},'charset':'utf8mb4','collate':_0x2295('0x1f')});};