ae7bdcea0dc9107dfa2e2f7aa2ced7c522fb2bd9
[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 _0xacb1=['toLowerCase','out','MailInteraction','findOne','MailInteractionId','update','catch','error','utf8mb4_unicode_ci','lodash','../../config/logger','api','moment','request-promise','html-to-text','path','rimraf','../../config/environment','./mailMessage.attributes','exports','MailMessage','mail_messages','messageId','plainBody','subject','body','models','get','direction'];(function(_0x5a7618,_0x3f44c2){var _0x12dc65=function(_0x3cc4cd){while(--_0x3cc4cd){_0x5a7618['push'](_0x5a7618['shift']());}};_0x12dc65(++_0x3f44c2);}(_0xacb1,0x148));var _0x1acb=function(_0x1f6a6f,_0x44acc6){_0x1f6a6f=_0x1f6a6f-0x0;var _0x2cea61=_0xacb1[_0x1f6a6f];return _0x2cea61;};'use strict';var _=require(_0x1acb('0x0'));var util=require('util');var logger=require(_0x1acb('0x1'))(_0x1acb('0x2'));var moment=require(_0x1acb('0x3'));var BPromise=require('bluebird');var rp=require(_0x1acb('0x4'));var htmlToText=require(_0x1acb('0x5'));var fs=require('fs');var path=require(_0x1acb('0x6'));var rimraf=require(_0x1acb('0x7'));var config=require(_0x1acb('0x8'));var attributes=require(_0x1acb('0x9'));module[_0x1acb('0xa')]=function(_0x34bbee,_0x34029d){return _0x34bbee['define'](_0x1acb('0xb'),attributes,{'tableName':_0x1acb('0xc'),'paranoid':![],'indexes':[{'name':_0x1acb('0xd'),'fields':[_0x1acb('0xd')]},{'name':'fti_mail_messages','fields':[_0x1acb('0xe'),_0x1acb('0xf')],'type':'FULLTEXT'}],'timestamps':!![],'hooks':{'beforeCreate':function(_0x223f17,_0x3cd7a6,_0x2769ea){if(_0x223f17[_0x1acb('0x10')]){_0x223f17['plainBody']=htmlToText['fromString'](_0x223f17[_0x1acb('0x10')],{'preserveNewlines':!![],'singleNewLineParagraphs':!![],'uppercaseHeadings':![],'noLinkBrackets':!![],'ignoreImage':!![]});}_0x2769ea(null,_0x3cd7a6);},'afterCreate':function(_0x969b26,_0x577e5e,_0x4be936){var _0xe5559e=_0x34bbee[_0x1acb('0x11')];var _0x50b94c=_0x969b26[_0x1acb('0x12')]({'plain':!![]});if(_0x50b94c[_0x1acb('0x13')][_0x1acb('0x14')]()==='in'||_0x50b94c[_0x1acb('0x13')]['toLowerCase']()===_0x1acb('0x15')&&!_0x50b94c['secret']&&!_['isNil'](_0x50b94c['UserId'])){_0xe5559e[_0x1acb('0x16')][_0x1acb('0x17')]({'where':{'id':_0x50b94c[_0x1acb('0x18')]}})['then'](function(_0x201df0){if(_0x201df0){_0x201df0[_0x1acb('0x19')]({'lastMsgAt':_0x50b94c['createdAt'],'lastMsgDirection':_0x50b94c['direction'][_0x1acb('0x14')](),'lastMsgBody':_0x50b94c['body']});}})[_0x1acb('0x1a')](function(_0x29ab8b){console[_0x1acb('0x1b')](_0x29ab8b);});}_0x4be936();}},'charset':'utf8mb4','collate':_0x1acb('0x1c')});};