Built motion from commit e02f907f.|2.6.14
[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 _0xb627=['fromString','get','toLowerCase','direction','secret','UserId','MailInteraction','findOne','then','createdAt','error','utf8mb4_unicode_ci','lodash','../../config/logger','api','bluebird','request-promise','path','rimraf','./mailMessage.attributes','exports','define','MailMessage','mail_messages','messageId','fti_mail_messages','plainBody','subject','FULLTEXT','body'];(function(_0x223a7c,_0x11ebdc){var _0x22e78a=function(_0x1dce57){while(--_0x1dce57){_0x223a7c['push'](_0x223a7c['shift']());}};_0x22e78a(++_0x11ebdc);}(_0xb627,0x192));var _0x7b62=function(_0x3e08bf,_0x50a03f){_0x3e08bf=_0x3e08bf-0x0;var _0x170f36=_0xb627[_0x3e08bf];return _0x170f36;};'use strict';var _=require(_0x7b62('0x0'));var util=require('util');var logger=require(_0x7b62('0x1'))(_0x7b62('0x2'));var moment=require('moment');var BPromise=require(_0x7b62('0x3'));var rp=require(_0x7b62('0x4'));var htmlToText=require('html-to-text');var fs=require('fs');var path=require(_0x7b62('0x5'));var rimraf=require(_0x7b62('0x6'));var config=require('../../config/environment');var attributes=require(_0x7b62('0x7'));module[_0x7b62('0x8')]=function(_0x275b04,_0x3953b5){return _0x275b04[_0x7b62('0x9')](_0x7b62('0xa'),attributes,{'tableName':_0x7b62('0xb'),'paranoid':![],'indexes':[{'name':_0x7b62('0xc'),'fields':[_0x7b62('0xc')]},{'name':_0x7b62('0xd'),'fields':[_0x7b62('0xe'),_0x7b62('0xf')],'type':_0x7b62('0x10')}],'timestamps':!![],'hooks':{'beforeCreate':function(_0xf75795,_0x4e8e93,_0x171937){if(_0xf75795[_0x7b62('0x11')]){_0xf75795[_0x7b62('0xe')]=htmlToText[_0x7b62('0x12')](_0xf75795[_0x7b62('0x11')],{'preserveNewlines':!![],'singleNewLineParagraphs':!![],'uppercaseHeadings':![],'noLinkBrackets':!![],'ignoreImage':!![]});}_0x171937(null,_0x4e8e93);},'afterCreate':function(_0x1a2bc7,_0x4d35be,_0x3797f2){var _0x17697c=_0x275b04['models'];var _0x2eb8cf=_0x1a2bc7[_0x7b62('0x13')]({'plain':!![]});if(_0x2eb8cf['direction'][_0x7b62('0x14')]()==='in'||_0x2eb8cf[_0x7b62('0x15')]['toLowerCase']()==='out'&&!_0x2eb8cf[_0x7b62('0x16')]&&!_['isNil'](_0x2eb8cf[_0x7b62('0x17')])){_0x17697c[_0x7b62('0x18')][_0x7b62('0x19')]({'where':{'id':_0x2eb8cf['MailInteractionId']}})[_0x7b62('0x1a')](function(_0x299f0c){if(_0x299f0c){_0x299f0c['update']({'lastMsgAt':_0x2eb8cf[_0x7b62('0x1b')],'lastMsgDirection':_0x2eb8cf[_0x7b62('0x15')][_0x7b62('0x14')]()});}})['catch'](function(_0x5cff15){console[_0x7b62('0x1c')](_0x5cff15);});}_0x3797f2();}},'charset':'utf8mb4','collate':_0x7b62('0x1d')});};