bcb4666b2e746d544e114a2fb2425ee119515a28
[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 _0x187b=['mail_messages','messageId','fti_mail_messages','plainBody','FULLTEXT','body','fromString','get','direction','toLowerCase','out','secret','isNil','UserId','MailInteraction','MailInteractionId','then','update','createdAt','catch','error','utf8mb4_unicode_ci','lodash','../../config/logger','api','moment','bluebird','request-promise','path','rimraf','./mailMessage.attributes','define','MailMessage'];(function(_0x4e99db,_0x153907){var _0x111db7=function(_0x54daf9){while(--_0x54daf9){_0x4e99db['push'](_0x4e99db['shift']());}};_0x111db7(++_0x153907);}(_0x187b,0xfd));var _0xb187=function(_0x41a9f1,_0x5ebe71){_0x41a9f1=_0x41a9f1-0x0;var _0x4440da=_0x187b[_0x41a9f1];return _0x4440da;};'use strict';var _=require(_0xb187('0x0'));var util=require('util');var logger=require(_0xb187('0x1'))(_0xb187('0x2'));var moment=require(_0xb187('0x3'));var BPromise=require(_0xb187('0x4'));var rp=require(_0xb187('0x5'));var htmlToText=require('html-to-text');var fs=require('fs');var path=require(_0xb187('0x6'));var rimraf=require(_0xb187('0x7'));var config=require('../../config/environment');var attributes=require(_0xb187('0x8'));module['exports']=function(_0x389737,_0x9aa306){return _0x389737[_0xb187('0x9')](_0xb187('0xa'),attributes,{'tableName':_0xb187('0xb'),'paranoid':![],'indexes':[{'name':_0xb187('0xc'),'fields':[_0xb187('0xc')]},{'name':_0xb187('0xd'),'fields':[_0xb187('0xe'),'subject'],'type':_0xb187('0xf')}],'timestamps':!![],'hooks':{'beforeCreate':function(_0x3588b7,_0x446828,_0x16b4f3){if(_0x3588b7[_0xb187('0x10')]){_0x3588b7[_0xb187('0xe')]=htmlToText[_0xb187('0x11')](_0x3588b7[_0xb187('0x10')],{'preserveNewlines':!![],'singleNewLineParagraphs':!![],'uppercaseHeadings':![],'noLinkBrackets':!![],'ignoreImage':!![]});}_0x16b4f3(null,_0x446828);},'afterCreate':function(_0x47ecdc,_0x5caa82,_0x1adce0){var _0x4f98d7=_0x389737['models'];var _0x21f193=_0x47ecdc[_0xb187('0x12')]({'plain':!![]});if(_0x21f193[_0xb187('0x13')][_0xb187('0x14')]()==='in'||_0x21f193[_0xb187('0x13')]['toLowerCase']()===_0xb187('0x15')&&!_0x21f193[_0xb187('0x16')]&&!_[_0xb187('0x17')](_0x21f193[_0xb187('0x18')])){_0x4f98d7[_0xb187('0x19')]['findOne']({'where':{'id':_0x21f193[_0xb187('0x1a')]}})[_0xb187('0x1b')](function(_0x4ca631){if(_0x4ca631){_0x4ca631[_0xb187('0x1c')]({'lastMsgAt':_0x21f193[_0xb187('0x1d')],'lastMsgDirection':_0x21f193[_0xb187('0x13')][_0xb187('0x14')](),'lastMsgBody':_0x21f193[_0xb187('0x10')]});}})[_0xb187('0x1e')](function(_0xc61ef4){console[_0xb187('0x1f')](_0xc61ef4);});}_0x1adce0();}},'charset':'utf8mb4','collate':_0xb187('0x20')});};