Built motion from commit 355702c8.|2.5.41
[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 _0x4e89=['utf8mb4_unicode_ci','lodash','util','../../config/logger','api','moment','bluebird','html-to-text','path','rimraf','../../config/environment','./mailMessage.attributes','exports','define','mail_messages','messageId','fti_mail_messages','plainBody','FULLTEXT','body','models','get','direction','toLowerCase','out','secret','isNil','UserId','MailInteraction','findOne','MailInteractionId','then','update','createdAt','catch','error','utf8mb4'];(function(_0x2a02d8,_0xc06f89){var _0x57f332=function(_0x2b2192){while(--_0x2b2192){_0x2a02d8['push'](_0x2a02d8['shift']());}};_0x57f332(++_0xc06f89);}(_0x4e89,0x104));var _0x94e8=function(_0x7eae07,_0x5063fd){_0x7eae07=_0x7eae07-0x0;var _0xf37c8a=_0x4e89[_0x7eae07];return _0xf37c8a;};'use strict';var _=require(_0x94e8('0x0'));var util=require(_0x94e8('0x1'));var logger=require(_0x94e8('0x2'))(_0x94e8('0x3'));var moment=require(_0x94e8('0x4'));var BPromise=require(_0x94e8('0x5'));var rp=require('request-promise');var htmlToText=require(_0x94e8('0x6'));var fs=require('fs');var path=require(_0x94e8('0x7'));var rimraf=require(_0x94e8('0x8'));var config=require(_0x94e8('0x9'));var attributes=require(_0x94e8('0xa'));module[_0x94e8('0xb')]=function(_0x4ea7e9,_0x10a3c1){return _0x4ea7e9[_0x94e8('0xc')]('MailMessage',attributes,{'tableName':_0x94e8('0xd'),'paranoid':![],'indexes':[{'name':_0x94e8('0xe'),'fields':[_0x94e8('0xe')]},{'name':_0x94e8('0xf'),'fields':[_0x94e8('0x10'),'subject'],'type':_0x94e8('0x11')}],'timestamps':!![],'hooks':{'beforeCreate':function(_0x53b5dd,_0x27d9e0,_0x1a2183){if(_0x53b5dd['body']){_0x53b5dd['plainBody']=htmlToText['fromString'](_0x53b5dd[_0x94e8('0x12')],{'preserveNewlines':!![],'singleNewLineParagraphs':!![],'uppercaseHeadings':![],'noLinkBrackets':!![],'ignoreImage':!![]});}_0x1a2183(null,_0x27d9e0);},'afterCreate':function(_0x1016bc,_0x3fb3b3,_0x170867){var _0x740408=_0x4ea7e9[_0x94e8('0x13')];var _0x141c14=_0x1016bc[_0x94e8('0x14')]({'plain':!![]});if(_0x141c14[_0x94e8('0x15')]['toLowerCase']()==='in'||_0x141c14['direction'][_0x94e8('0x16')]()===_0x94e8('0x17')&&!_0x141c14[_0x94e8('0x18')]&&!_[_0x94e8('0x19')](_0x141c14[_0x94e8('0x1a')])){_0x740408[_0x94e8('0x1b')][_0x94e8('0x1c')]({'where':{'id':_0x141c14[_0x94e8('0x1d')]}})[_0x94e8('0x1e')](function(_0x2fbc5f){if(_0x2fbc5f){_0x2fbc5f[_0x94e8('0x1f')]({'lastMsgAt':_0x141c14[_0x94e8('0x20')],'lastMsgDirection':_0x141c14[_0x94e8('0x15')]['toLowerCase']()});}})[_0x94e8('0x21')](function(_0x32f304){console[_0x94e8('0x22')](_0x32f304);});}_0x170867();}},'charset':_0x94e8('0x23'),'collate':_0x94e8('0x24')});};