Built motion from commit 936e8062.|2.5.33
[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 _0x1f6c=['plainBody','subject','FULLTEXT','body','fromString','models','get','toLowerCase','direction','out','secret','UserId','MailInteraction','findOne','then','update','createdAt','catch','error','utf8mb4','utf8mb4_unicode_ci','lodash','util','../../config/logger','api','bluebird','html-to-text','path','rimraf','../../config/environment','./mailMessage.attributes','exports','define','MailMessage','mail_messages','messageId'];(function(_0x4c448b,_0x2ef11c){var _0x489f07=function(_0x5c5f51){while(--_0x5c5f51){_0x4c448b['push'](_0x4c448b['shift']());}};_0x489f07(++_0x2ef11c);}(_0x1f6c,0x1a1));var _0xc1f6=function(_0x4f2ea5,_0x470103){_0x4f2ea5=_0x4f2ea5-0x0;var _0x48e14c=_0x1f6c[_0x4f2ea5];return _0x48e14c;};'use strict';var _=require(_0xc1f6('0x0'));var util=require(_0xc1f6('0x1'));var logger=require(_0xc1f6('0x2'))(_0xc1f6('0x3'));var moment=require('moment');var BPromise=require(_0xc1f6('0x4'));var rp=require('request-promise');var htmlToText=require(_0xc1f6('0x5'));var fs=require('fs');var path=require(_0xc1f6('0x6'));var rimraf=require(_0xc1f6('0x7'));var config=require(_0xc1f6('0x8'));var attributes=require(_0xc1f6('0x9'));module[_0xc1f6('0xa')]=function(_0x33fd15,_0xb878c4){return _0x33fd15[_0xc1f6('0xb')](_0xc1f6('0xc'),attributes,{'tableName':_0xc1f6('0xd'),'paranoid':![],'indexes':[{'name':_0xc1f6('0xe'),'fields':['messageId']},{'name':'fti_mail_messages','fields':[_0xc1f6('0xf'),_0xc1f6('0x10')],'type':_0xc1f6('0x11')}],'timestamps':!![],'hooks':{'beforeCreate':function(_0x2eec19,_0x4d2ef6,_0xbc54b1){if(_0x2eec19[_0xc1f6('0x12')]){_0x2eec19[_0xc1f6('0xf')]=htmlToText[_0xc1f6('0x13')](_0x2eec19['body'],{'preserveNewlines':!![],'singleNewLineParagraphs':!![],'uppercaseHeadings':![],'noLinkBrackets':!![],'ignoreImage':!![]});}_0xbc54b1(null,_0x4d2ef6);},'afterCreate':function(_0x37c5be,_0x3fdf4b,_0x99db25){var _0x5db585=_0x33fd15[_0xc1f6('0x14')];var _0x5abb29=_0x37c5be[_0xc1f6('0x15')]({'plain':!![]});if(_0x5abb29['direction'][_0xc1f6('0x16')]()==='in'||_0x5abb29[_0xc1f6('0x17')][_0xc1f6('0x16')]()===_0xc1f6('0x18')&&!_0x5abb29[_0xc1f6('0x19')]&&!_['isNil'](_0x5abb29[_0xc1f6('0x1a')])){_0x5db585[_0xc1f6('0x1b')][_0xc1f6('0x1c')]({'where':{'id':_0x5abb29['MailInteractionId']}})[_0xc1f6('0x1d')](function(_0x116843){if(_0x116843){_0x116843[_0xc1f6('0x1e')]({'lastMsgAt':_0x5abb29[_0xc1f6('0x1f')],'lastMsgDirection':_0x5abb29['direction'][_0xc1f6('0x16')]()});}})[_0xc1f6('0x20')](function(_0x1e29c9){console[_0xc1f6('0x21')](_0x1e29c9);});}_0x99db25();}},'charset':_0xc1f6('0x22'),'collate':_0xc1f6('0x23')});};