43295dc5e977be7037699161623e812b6de19564
[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 _0x5738=['plainBody','subject','FULLTEXT','body','fromString','get','direction','toLowerCase','secret','findOne','then','update','createdAt','catch','error','utf8mb4','utf8mb4_unicode_ci','lodash','util','../../config/logger','moment','request-promise','html-to-text','../../config/environment','exports','MailMessage','mail_messages','messageId'];(function(_0x3dd15e,_0x1f0015){var _0x231fd0=function(_0x4f680a){while(--_0x4f680a){_0x3dd15e['push'](_0x3dd15e['shift']());}};_0x231fd0(++_0x1f0015);}(_0x5738,0x9d));var _0x8573=function(_0x37ef22,_0x348c92){_0x37ef22=_0x37ef22-0x0;var _0x49eeb3=_0x5738[_0x37ef22];return _0x49eeb3;};'use strict';var _=require(_0x8573('0x0'));var util=require(_0x8573('0x1'));var logger=require(_0x8573('0x2'))('api');var moment=require(_0x8573('0x3'));var BPromise=require('bluebird');var rp=require(_0x8573('0x4'));var htmlToText=require(_0x8573('0x5'));var fs=require('fs');var path=require('path');var rimraf=require('rimraf');var config=require(_0x8573('0x6'));var attributes=require('./mailMessage.attributes');module[_0x8573('0x7')]=function(_0xa23ffc,_0x261786){return _0xa23ffc['define'](_0x8573('0x8'),attributes,{'tableName':_0x8573('0x9'),'paranoid':![],'indexes':[{'name':_0x8573('0xa'),'fields':[_0x8573('0xa')]},{'name':'fti_mail_messages','fields':[_0x8573('0xb'),_0x8573('0xc')],'type':_0x8573('0xd')}],'timestamps':!![],'hooks':{'beforeCreate':function(_0x23426b,_0x5ebc2f,_0x3b2972){if(_0x23426b[_0x8573('0xe')]){_0x23426b[_0x8573('0xb')]=htmlToText[_0x8573('0xf')](_0x23426b[_0x8573('0xe')],{'preserveNewlines':!![],'singleNewLineParagraphs':!![],'uppercaseHeadings':![],'noLinkBrackets':!![],'ignoreImage':!![]});}_0x3b2972(null,_0x5ebc2f);},'afterCreate':function(_0x20b179,_0x2c0d0e,_0x3ab932){var _0x3469cf=_0xa23ffc['models'];var _0xa4ec6e=_0x20b179[_0x8573('0x10')]({'plain':!![]});if(_0xa4ec6e[_0x8573('0x11')][_0x8573('0x12')]()==='in'||_0xa4ec6e[_0x8573('0x11')]['toLowerCase']()==='out'&&!_0xa4ec6e[_0x8573('0x13')]&&!_['isNil'](_0xa4ec6e['UserId'])){_0x3469cf['MailInteraction'][_0x8573('0x14')]({'where':{'id':_0xa4ec6e['MailInteractionId']}})[_0x8573('0x15')](function(_0x3d9dba){if(_0x3d9dba){_0x3d9dba[_0x8573('0x16')]({'lastMsgAt':_0xa4ec6e[_0x8573('0x17')],'lastMsgDirection':_0xa4ec6e['direction']['toLowerCase']()});}})[_0x8573('0x18')](function(_0x15c454){console[_0x8573('0x19')](_0x15c454);});}_0x3ab932();}},'charset':_0x8573('0x1a'),'collate':_0x8573('0x1b')});};