62b55421901be792d4618dadadbc775b7ca30126
[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 _0x123c=['utf8mb4','utf8mb4_unicode_ci','util','../../config/logger','api','moment','html-to-text','rimraf','./mailMessage.attributes','exports','MailMessage','mail_messages','messageId','fti_mail_messages','plainBody','FULLTEXT','body','fromString','models','direction','toLowerCase','secret','isNil','UserId','findOne','MailInteractionId','then','createdAt','catch','error'];(function(_0x5a28e5,_0x366872){var _0x5882f2=function(_0x41a40a){while(--_0x41a40a){_0x5a28e5['push'](_0x5a28e5['shift']());}};_0x5882f2(++_0x366872);}(_0x123c,0x98));var _0xc123=function(_0x5c4971,_0x343065){_0x5c4971=_0x5c4971-0x0;var _0x3e1a86=_0x123c[_0x5c4971];return _0x3e1a86;};'use strict';var _=require('lodash');var util=require(_0xc123('0x0'));var logger=require(_0xc123('0x1'))(_0xc123('0x2'));var moment=require(_0xc123('0x3'));var BPromise=require('bluebird');var rp=require('request-promise');var htmlToText=require(_0xc123('0x4'));var fs=require('fs');var path=require('path');var rimraf=require(_0xc123('0x5'));var config=require('../../config/environment');var attributes=require(_0xc123('0x6'));module[_0xc123('0x7')]=function(_0x5ee164,_0x59b65a){return _0x5ee164['define'](_0xc123('0x8'),attributes,{'tableName':_0xc123('0x9'),'paranoid':![],'indexes':[{'name':'messageId','fields':[_0xc123('0xa')]},{'name':_0xc123('0xb'),'fields':[_0xc123('0xc'),'subject'],'type':_0xc123('0xd')}],'timestamps':!![],'hooks':{'beforeCreate':function(_0x35ad9c,_0x3bb906,_0x41dcf4){if(_0x35ad9c[_0xc123('0xe')]){_0x35ad9c[_0xc123('0xc')]=htmlToText[_0xc123('0xf')](_0x35ad9c[_0xc123('0xe')],{'preserveNewlines':!![],'singleNewLineParagraphs':!![],'uppercaseHeadings':![],'noLinkBrackets':!![],'ignoreImage':!![]});}_0x41dcf4(null,_0x3bb906);},'afterCreate':function(_0x426039,_0x226d35,_0x560dea){var _0x47a5c0=_0x5ee164[_0xc123('0x10')];var _0x5561cc=_0x426039['get']({'plain':!![]});if(_0x5561cc[_0xc123('0x11')]['toLowerCase']()==='in'||_0x5561cc[_0xc123('0x11')][_0xc123('0x12')]()==='out'&&!_0x5561cc[_0xc123('0x13')]&&!_[_0xc123('0x14')](_0x5561cc[_0xc123('0x15')])){_0x47a5c0['MailInteraction'][_0xc123('0x16')]({'where':{'id':_0x5561cc[_0xc123('0x17')]}})[_0xc123('0x18')](function(_0x4cbc86){if(_0x4cbc86){_0x4cbc86['update']({'lastMsgAt':_0x5561cc[_0xc123('0x19')],'lastMsgDirection':_0x5561cc[_0xc123('0x11')][_0xc123('0x12')]()});}})[_0xc123('0x1a')](function(_0x2fafdc){console[_0xc123('0x1b')](_0x2fafdc);});}_0x560dea();}},'charset':_0xc123('0x1c'),'collate':_0xc123('0x1d')});};