78ccb91b8a87ebdace7c0327e43669cf73eeb265
[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 _0x5ed1=['util','../../config/logger','moment','request-promise','html-to-text','path','rimraf','../../config/environment','./mailMessage.attributes','MailMessage','mail_messages','messageId','fti_mail_messages','plainBody','FULLTEXT','fromString','models','get','direction','toLowerCase','out','secret','isNil','UserId','MailInteraction','findOne','MailInteractionId','update','catch','utf8mb4','utf8mb4_unicode_ci','lodash'];(function(_0x330cd0,_0x3d2e2b){var _0x228a6d=function(_0x5c0b06){while(--_0x5c0b06){_0x330cd0['push'](_0x330cd0['shift']());}};_0x228a6d(++_0x3d2e2b);}(_0x5ed1,0x17f));var _0x15ed=function(_0x49d19d,_0x245cf5){_0x49d19d=_0x49d19d-0x0;var _0x4ebef1=_0x5ed1[_0x49d19d];return _0x4ebef1;};'use strict';var _=require(_0x15ed('0x0'));var util=require(_0x15ed('0x1'));var logger=require(_0x15ed('0x2'))('api');var moment=require(_0x15ed('0x3'));var BPromise=require('bluebird');var rp=require(_0x15ed('0x4'));var htmlToText=require(_0x15ed('0x5'));var fs=require('fs');var path=require(_0x15ed('0x6'));var rimraf=require(_0x15ed('0x7'));var config=require(_0x15ed('0x8'));var attributes=require(_0x15ed('0x9'));module['exports']=function(_0x5635c4,_0x3bf6da){return _0x5635c4['define'](_0x15ed('0xa'),attributes,{'tableName':_0x15ed('0xb'),'paranoid':![],'indexes':[{'name':_0x15ed('0xc'),'fields':[_0x15ed('0xc')]},{'name':_0x15ed('0xd'),'fields':[_0x15ed('0xe'),'subject'],'type':_0x15ed('0xf')}],'timestamps':!![],'hooks':{'beforeCreate':function(_0x254398,_0x3538af,_0x28ffc0){if(_0x254398['body']){_0x254398[_0x15ed('0xe')]=htmlToText[_0x15ed('0x10')](_0x254398['body'],{'preserveNewlines':!![],'singleNewLineParagraphs':!![],'uppercaseHeadings':![],'noLinkBrackets':!![],'ignoreImage':!![]});}_0x28ffc0(null,_0x3538af);},'afterCreate':function(_0x542489,_0x249fcf,_0x2ec63c){var _0x550faa=_0x5635c4[_0x15ed('0x11')];var _0x433588=_0x542489[_0x15ed('0x12')]({'plain':!![]});if(_0x433588[_0x15ed('0x13')][_0x15ed('0x14')]()==='in'||_0x433588[_0x15ed('0x13')]['toLowerCase']()===_0x15ed('0x15')&&!_0x433588[_0x15ed('0x16')]&&!_[_0x15ed('0x17')](_0x433588[_0x15ed('0x18')])){_0x550faa[_0x15ed('0x19')][_0x15ed('0x1a')]({'where':{'id':_0x433588[_0x15ed('0x1b')]}})['then'](function(_0x15cccf){if(_0x15cccf){_0x15cccf[_0x15ed('0x1c')]({'lastMsgAt':_0x433588['createdAt'],'lastMsgDirection':_0x433588[_0x15ed('0x13')][_0x15ed('0x14')]()});}})[_0x15ed('0x1d')](function(_0x17a169){console['error'](_0x17a169);});}_0x2ec63c();}},'charset':_0x15ed('0x1e'),'collate':_0x15ed('0x1f')});};