Built motion from commit e1760111.|2.6.18
[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 _0xfe31=['FULLTEXT','body','plainBody','fromString','models','get','direction','toLowerCase','out','secret','isNil','UserId','MailInteraction','findOne','MailInteractionId','then','createdAt','catch','error','utf8mb4','utf8mb4_unicode_ci','lodash','util','../../config/logger','api','bluebird','request-promise','rimraf','../../config/environment','./mailMessage.attributes','exports','define','MailMessage','mail_messages','messageId'];(function(_0x3d6d1c,_0x2576d4){var _0x36463f=function(_0x2e2454){while(--_0x2e2454){_0x3d6d1c['push'](_0x3d6d1c['shift']());}};_0x36463f(++_0x2576d4);}(_0xfe31,0x196));var _0x1fe3=function(_0x1c51a9,_0x44cec4){_0x1c51a9=_0x1c51a9-0x0;var _0x411a4b=_0xfe31[_0x1c51a9];return _0x411a4b;};'use strict';var _=require(_0x1fe3('0x0'));var util=require(_0x1fe3('0x1'));var logger=require(_0x1fe3('0x2'))(_0x1fe3('0x3'));var moment=require('moment');var BPromise=require(_0x1fe3('0x4'));var rp=require(_0x1fe3('0x5'));var htmlToText=require('html-to-text');var fs=require('fs');var path=require('path');var rimraf=require(_0x1fe3('0x6'));var config=require(_0x1fe3('0x7'));var attributes=require(_0x1fe3('0x8'));module[_0x1fe3('0x9')]=function(_0x4065a7,_0x15de7a){return _0x4065a7[_0x1fe3('0xa')](_0x1fe3('0xb'),attributes,{'tableName':_0x1fe3('0xc'),'paranoid':![],'indexes':[{'name':_0x1fe3('0xd'),'fields':[_0x1fe3('0xd')]},{'name':'fti_mail_messages','fields':['plainBody','subject'],'type':_0x1fe3('0xe')}],'timestamps':!![],'hooks':{'beforeCreate':function(_0x4a1f84,_0x267067,_0x5eb1b6){if(_0x4a1f84[_0x1fe3('0xf')]){_0x4a1f84[_0x1fe3('0x10')]=htmlToText[_0x1fe3('0x11')](_0x4a1f84['body'],{'preserveNewlines':!![],'singleNewLineParagraphs':!![],'uppercaseHeadings':![],'noLinkBrackets':!![],'ignoreImage':!![]});}_0x5eb1b6(null,_0x267067);},'afterCreate':function(_0x2a8a25,_0x53d562,_0x52c23a){var _0x17418f=_0x4065a7[_0x1fe3('0x12')];var _0x436921=_0x2a8a25[_0x1fe3('0x13')]({'plain':!![]});if(_0x436921[_0x1fe3('0x14')][_0x1fe3('0x15')]()==='in'||_0x436921['direction']['toLowerCase']()===_0x1fe3('0x16')&&!_0x436921[_0x1fe3('0x17')]&&!_[_0x1fe3('0x18')](_0x436921[_0x1fe3('0x19')])){_0x17418f[_0x1fe3('0x1a')][_0x1fe3('0x1b')]({'where':{'id':_0x436921[_0x1fe3('0x1c')]}})[_0x1fe3('0x1d')](function(_0x208a6a){if(_0x208a6a){_0x208a6a['update']({'lastMsgAt':_0x436921[_0x1fe3('0x1e')],'lastMsgDirection':_0x436921[_0x1fe3('0x14')][_0x1fe3('0x15')]()});}})[_0x1fe3('0x1f')](function(_0x13a6d4){console[_0x1fe3('0x20')](_0x13a6d4);});}_0x52c23a();}},'charset':_0x1fe3('0x21'),'collate':_0x1fe3('0x22')});};