c961a0df37eb087552f9c993a85156adee53aad7
[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 _0x75f0=['FULLTEXT','body','plainBody','fromString','models','get','toLowerCase','out','secret','UserId','MailInteraction','findOne','MailInteractionId','then','update','createdAt','direction','error','utf8mb4','utf8mb4_unicode_ci','lodash','../../config/logger','request-promise','html-to-text','rimraf','../../config/environment','./mailMessage.attributes','exports','define','MailMessage','mail_messages','messageId','fti_mail_messages','subject'];(function(_0x523dda,_0x282705){var _0x2db386=function(_0x28fa52){while(--_0x28fa52){_0x523dda['push'](_0x523dda['shift']());}};_0x2db386(++_0x282705);}(_0x75f0,0x1f0));var _0x075f=function(_0x465e84,_0x2ad6f8){_0x465e84=_0x465e84-0x0;var _0x29c6df=_0x75f0[_0x465e84];return _0x29c6df;};'use strict';var _=require(_0x075f('0x0'));var util=require('util');var logger=require(_0x075f('0x1'))('api');var moment=require('moment');var BPromise=require('bluebird');var rp=require(_0x075f('0x2'));var htmlToText=require(_0x075f('0x3'));var fs=require('fs');var path=require('path');var rimraf=require(_0x075f('0x4'));var config=require(_0x075f('0x5'));var attributes=require(_0x075f('0x6'));module[_0x075f('0x7')]=function(_0x461ee8,_0x11830f){return _0x461ee8[_0x075f('0x8')](_0x075f('0x9'),attributes,{'tableName':_0x075f('0xa'),'paranoid':![],'indexes':[{'name':_0x075f('0xb'),'fields':['messageId']},{'name':_0x075f('0xc'),'fields':['plainBody',_0x075f('0xd')],'type':_0x075f('0xe')}],'timestamps':!![],'hooks':{'beforeCreate':function(_0x32d32f,_0x558534,_0x15c2ab){if(_0x32d32f[_0x075f('0xf')]){_0x32d32f[_0x075f('0x10')]=htmlToText[_0x075f('0x11')](_0x32d32f[_0x075f('0xf')],{'preserveNewlines':!![],'singleNewLineParagraphs':!![],'uppercaseHeadings':![],'noLinkBrackets':!![],'ignoreImage':!![]});}_0x15c2ab(null,_0x558534);},'afterCreate':function(_0x1cb8c0,_0x56889f,_0x183650){var _0x5ca485=_0x461ee8[_0x075f('0x12')];var _0x3ec0b9=_0x1cb8c0[_0x075f('0x13')]({'plain':!![]});if(_0x3ec0b9['direction'][_0x075f('0x14')]()==='in'||_0x3ec0b9['direction']['toLowerCase']()===_0x075f('0x15')&&!_0x3ec0b9[_0x075f('0x16')]&&!_['isNil'](_0x3ec0b9[_0x075f('0x17')])){_0x5ca485[_0x075f('0x18')][_0x075f('0x19')]({'where':{'id':_0x3ec0b9[_0x075f('0x1a')]}})[_0x075f('0x1b')](function(_0x430db7){if(_0x430db7){_0x430db7[_0x075f('0x1c')]({'lastMsgAt':_0x3ec0b9[_0x075f('0x1d')],'lastMsgDirection':_0x3ec0b9[_0x075f('0x1e')][_0x075f('0x14')](),'lastMsgBody':_0x3ec0b9['body']});}})['catch'](function(_0x4fb8c4){console[_0x075f('0x1f')](_0x4fb8c4);});}_0x183650();}},'charset':_0x075f('0x20'),'collate':_0x075f('0x21')});};