8f2d56f7e3fe4a3b651a26e051f3110cc8db8605
[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 _0x2c30=['./mailMessage.attributes','MailMessage','messageId','fti_mail_messages','subject','FULLTEXT','body','plainBody','fromString','models','toLowerCase','direction','secret','isNil','UserId','MailInteraction','findOne','MailInteractionId','then','update','createdAt','error','utf8mb4_unicode_ci','lodash','util','../../config/logger','api','bluebird','request-promise','html-to-text','path','rimraf','../../config/environment'];(function(_0x134c2e,_0x3573c4){var _0x2825db=function(_0x2a574d){while(--_0x2a574d){_0x134c2e['push'](_0x134c2e['shift']());}};_0x2825db(++_0x3573c4);}(_0x2c30,0x1a3));var _0x02c3=function(_0xdcb55,_0x12f025){_0xdcb55=_0xdcb55-0x0;var _0x24c193=_0x2c30[_0xdcb55];return _0x24c193;};'use strict';var _=require(_0x02c3('0x0'));var util=require(_0x02c3('0x1'));var logger=require(_0x02c3('0x2'))(_0x02c3('0x3'));var moment=require('moment');var BPromise=require(_0x02c3('0x4'));var rp=require(_0x02c3('0x5'));var htmlToText=require(_0x02c3('0x6'));var fs=require('fs');var path=require(_0x02c3('0x7'));var rimraf=require(_0x02c3('0x8'));var config=require(_0x02c3('0x9'));var attributes=require(_0x02c3('0xa'));module['exports']=function(_0x56dbcb,_0x36f6db){return _0x56dbcb['define'](_0x02c3('0xb'),attributes,{'tableName':'mail_messages','paranoid':![],'indexes':[{'name':_0x02c3('0xc'),'fields':[_0x02c3('0xc')]},{'name':_0x02c3('0xd'),'fields':['plainBody',_0x02c3('0xe')],'type':_0x02c3('0xf')}],'timestamps':!![],'hooks':{'beforeCreate':function(_0x2040a1,_0x5d302a,_0x395b5d){if(_0x2040a1[_0x02c3('0x10')]){_0x2040a1[_0x02c3('0x11')]=htmlToText[_0x02c3('0x12')](_0x2040a1[_0x02c3('0x10')],{'preserveNewlines':!![],'singleNewLineParagraphs':!![],'uppercaseHeadings':![],'noLinkBrackets':!![],'ignoreImage':!![]});}_0x395b5d(null,_0x5d302a);},'afterCreate':function(_0x4b2851,_0x1fe386,_0x2ae1fa){var _0x67ab38=_0x56dbcb[_0x02c3('0x13')];var _0x125b8b=_0x4b2851['get']({'plain':!![]});if(_0x125b8b['direction'][_0x02c3('0x14')]()==='in'||_0x125b8b[_0x02c3('0x15')]['toLowerCase']()==='out'&&!_0x125b8b[_0x02c3('0x16')]&&!_[_0x02c3('0x17')](_0x125b8b[_0x02c3('0x18')])){_0x67ab38[_0x02c3('0x19')][_0x02c3('0x1a')]({'where':{'id':_0x125b8b[_0x02c3('0x1b')]}})[_0x02c3('0x1c')](function(_0x459e0a){if(_0x459e0a){_0x459e0a[_0x02c3('0x1d')]({'lastMsgAt':_0x125b8b[_0x02c3('0x1e')],'lastMsgDirection':_0x125b8b[_0x02c3('0x15')][_0x02c3('0x14')](),'lastMsgBody':_0x125b8b[_0x02c3('0x10')]});}})['catch'](function(_0x59d7ce){console[_0x02c3('0x1f')](_0x59d7ce);});}_0x2ae1fa();}},'charset':'utf8mb4','collate':_0x02c3('0x20')});};