d04279d2f800110ef9e46e39175df671bdd4440e
[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 _0xf457=['utf8mb4','lodash','util','../../config/logger','api','moment','bluebird','request-promise','html-to-text','path','./mailMessage.attributes','define','MailMessage','mail_messages','messageId','fti_mail_messages','subject','FULLTEXT','body','plainBody','direction','toLowerCase','out','secret','UserId','findOne','MailInteractionId','update','createdAt','catch','error'];(function(_0x21f3bf,_0xfb0f59){var _0x249d08=function(_0x37e6c2){while(--_0x37e6c2){_0x21f3bf['push'](_0x21f3bf['shift']());}};_0x249d08(++_0xfb0f59);}(_0xf457,0x1f1));var _0x7f45=function(_0x321bb2,_0x202794){_0x321bb2=_0x321bb2-0x0;var _0x9c12ed=_0xf457[_0x321bb2];return _0x9c12ed;};'use strict';var _=require(_0x7f45('0x0'));var util=require(_0x7f45('0x1'));var logger=require(_0x7f45('0x2'))(_0x7f45('0x3'));var moment=require(_0x7f45('0x4'));var BPromise=require(_0x7f45('0x5'));var rp=require(_0x7f45('0x6'));var htmlToText=require(_0x7f45('0x7'));var fs=require('fs');var path=require(_0x7f45('0x8'));var rimraf=require('rimraf');var config=require('../../config/environment');var attributes=require(_0x7f45('0x9'));module['exports']=function(_0x1e52d1,_0x312ae7){return _0x1e52d1[_0x7f45('0xa')](_0x7f45('0xb'),attributes,{'tableName':_0x7f45('0xc'),'paranoid':![],'indexes':[{'name':_0x7f45('0xd'),'fields':[_0x7f45('0xd')]},{'name':_0x7f45('0xe'),'fields':['plainBody',_0x7f45('0xf')],'type':_0x7f45('0x10')}],'timestamps':!![],'hooks':{'beforeCreate':function(_0x568439,_0x49b18a,_0x2bee6b){if(_0x568439[_0x7f45('0x11')]){_0x568439[_0x7f45('0x12')]=htmlToText['fromString'](_0x568439[_0x7f45('0x11')],{'preserveNewlines':!![],'singleNewLineParagraphs':!![],'uppercaseHeadings':![],'noLinkBrackets':!![],'ignoreImage':!![]});}_0x2bee6b(null,_0x49b18a);},'afterCreate':function(_0x2fb934,_0x2e98ff,_0xec8bc1){var _0x4c10d5=_0x1e52d1['models'];var _0x5c7cd4=_0x2fb934['get']({'plain':!![]});if(_0x5c7cd4[_0x7f45('0x13')][_0x7f45('0x14')]()==='in'||_0x5c7cd4[_0x7f45('0x13')][_0x7f45('0x14')]()===_0x7f45('0x15')&&!_0x5c7cd4[_0x7f45('0x16')]&&!_['isNil'](_0x5c7cd4[_0x7f45('0x17')])){_0x4c10d5['MailInteraction'][_0x7f45('0x18')]({'where':{'id':_0x5c7cd4[_0x7f45('0x19')]}})['then'](function(_0x376824){if(_0x376824){_0x376824[_0x7f45('0x1a')]({'lastMsgAt':_0x5c7cd4[_0x7f45('0x1b')],'lastMsgDirection':_0x5c7cd4[_0x7f45('0x13')][_0x7f45('0x14')]()});}})[_0x7f45('0x1c')](function(_0x197260){console[_0x7f45('0x1d')](_0x197260);});}_0xec8bc1();}},'charset':_0x7f45('0x1e'),'collate':'utf8mb4_unicode_ci'});};