d1f6364c4b3ef9de5ba014d6c10679ed1b9e3541
[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 _0xe269=['isNil','UserId','MailInteraction','findOne','MailInteractionId','then','update','createdAt','error','utf8mb4','utf8mb4_unicode_ci','lodash','util','../../config/logger','api','moment','bluebird','request-promise','html-to-text','rimraf','../../config/environment','define','MailMessage','mail_messages','messageId','fti_mail_messages','plainBody','FULLTEXT','body','fromString','models','get','direction','toLowerCase','out','secret'];(function(_0x3be5d9,_0x2d8846){var _0xf077c=function(_0x131602){while(--_0x131602){_0x3be5d9['push'](_0x3be5d9['shift']());}};_0xf077c(++_0x2d8846);}(_0xe269,0x9b));var _0x9e26=function(_0x3a7072,_0x1a80d4){_0x3a7072=_0x3a7072-0x0;var _0x30e56a=_0xe269[_0x3a7072];return _0x30e56a;};'use strict';var _=require(_0x9e26('0x0'));var util=require(_0x9e26('0x1'));var logger=require(_0x9e26('0x2'))(_0x9e26('0x3'));var moment=require(_0x9e26('0x4'));var BPromise=require(_0x9e26('0x5'));var rp=require(_0x9e26('0x6'));var htmlToText=require(_0x9e26('0x7'));var fs=require('fs');var path=require('path');var rimraf=require(_0x9e26('0x8'));var config=require(_0x9e26('0x9'));var attributes=require('./mailMessage.attributes');module['exports']=function(_0x49b6d8,_0x3e692e){return _0x49b6d8[_0x9e26('0xa')](_0x9e26('0xb'),attributes,{'tableName':_0x9e26('0xc'),'paranoid':![],'indexes':[{'name':_0x9e26('0xd'),'fields':[_0x9e26('0xd')]},{'name':_0x9e26('0xe'),'fields':[_0x9e26('0xf'),'subject'],'type':_0x9e26('0x10')}],'timestamps':!![],'hooks':{'beforeCreate':function(_0x1d647b,_0x2e3ae0,_0x2c1f34){if(_0x1d647b[_0x9e26('0x11')]){_0x1d647b[_0x9e26('0xf')]=htmlToText[_0x9e26('0x12')](_0x1d647b['body'],{'preserveNewlines':!![],'singleNewLineParagraphs':!![],'uppercaseHeadings':![],'noLinkBrackets':!![],'ignoreImage':!![]});}_0x2c1f34(null,_0x2e3ae0);},'afterCreate':function(_0x126bed,_0x15038b,_0x51e034){var _0x596692=_0x49b6d8[_0x9e26('0x13')];var _0x3b63d4=_0x126bed[_0x9e26('0x14')]({'plain':!![]});if(_0x3b63d4[_0x9e26('0x15')][_0x9e26('0x16')]()==='in'||_0x3b63d4[_0x9e26('0x15')][_0x9e26('0x16')]()===_0x9e26('0x17')&&!_0x3b63d4[_0x9e26('0x18')]&&!_[_0x9e26('0x19')](_0x3b63d4[_0x9e26('0x1a')])){_0x596692[_0x9e26('0x1b')][_0x9e26('0x1c')]({'where':{'id':_0x3b63d4[_0x9e26('0x1d')]}})[_0x9e26('0x1e')](function(_0x27298a){if(_0x27298a){_0x27298a[_0x9e26('0x1f')]({'lastMsgAt':_0x3b63d4[_0x9e26('0x20')],'lastMsgDirection':_0x3b63d4[_0x9e26('0x15')][_0x9e26('0x16')]()});}})['catch'](function(_0x165681){console[_0x9e26('0x21')](_0x165681);});}_0x51e034();}},'charset':_0x9e26('0x22'),'collate':_0x9e26('0x23')});};