Built motion from commit 9d0783e6.|2.6.13
[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 _0x85cc=['rimraf','../../config/environment','./mailMessage.attributes','exports','define','MailMessage','mail_messages','messageId','subject','FULLTEXT','plainBody','fromString','body','models','get','direction','toLowerCase','out','secret','isNil','UserId','MailInteraction','findOne','MailInteractionId','then','update','createdAt','catch','error','utf8mb4_unicode_ci','lodash','util','../../config/logger','api','moment','bluebird','request-promise','html-to-text','path'];(function(_0x14be19,_0x3067bb){var _0x240fb4=function(_0x58a3b9){while(--_0x58a3b9){_0x14be19['push'](_0x14be19['shift']());}};_0x240fb4(++_0x3067bb);}(_0x85cc,0x1cb));var _0xc85c=function(_0x46ba57,_0x4788c2){_0x46ba57=_0x46ba57-0x0;var _0x350bb9=_0x85cc[_0x46ba57];return _0x350bb9;};'use strict';var _=require(_0xc85c('0x0'));var util=require(_0xc85c('0x1'));var logger=require(_0xc85c('0x2'))(_0xc85c('0x3'));var moment=require(_0xc85c('0x4'));var BPromise=require(_0xc85c('0x5'));var rp=require(_0xc85c('0x6'));var htmlToText=require(_0xc85c('0x7'));var fs=require('fs');var path=require(_0xc85c('0x8'));var rimraf=require(_0xc85c('0x9'));var config=require(_0xc85c('0xa'));var attributes=require(_0xc85c('0xb'));module[_0xc85c('0xc')]=function(_0x2d3047,_0x49bea0){return _0x2d3047[_0xc85c('0xd')](_0xc85c('0xe'),attributes,{'tableName':_0xc85c('0xf'),'paranoid':![],'indexes':[{'name':_0xc85c('0x10'),'fields':['messageId']},{'name':'fti_mail_messages','fields':['plainBody',_0xc85c('0x11')],'type':_0xc85c('0x12')}],'timestamps':!![],'hooks':{'beforeCreate':function(_0x4d40cc,_0x2b187f,_0x469c39){if(_0x4d40cc['body']){_0x4d40cc[_0xc85c('0x13')]=htmlToText[_0xc85c('0x14')](_0x4d40cc[_0xc85c('0x15')],{'preserveNewlines':!![],'singleNewLineParagraphs':!![],'uppercaseHeadings':![],'noLinkBrackets':!![],'ignoreImage':!![]});}_0x469c39(null,_0x2b187f);},'afterCreate':function(_0x232c96,_0x58845b,_0x3f7827){var _0x55b974=_0x2d3047[_0xc85c('0x16')];var _0x2afc37=_0x232c96[_0xc85c('0x17')]({'plain':!![]});if(_0x2afc37[_0xc85c('0x18')][_0xc85c('0x19')]()==='in'||_0x2afc37[_0xc85c('0x18')][_0xc85c('0x19')]()===_0xc85c('0x1a')&&!_0x2afc37[_0xc85c('0x1b')]&&!_[_0xc85c('0x1c')](_0x2afc37[_0xc85c('0x1d')])){_0x55b974[_0xc85c('0x1e')][_0xc85c('0x1f')]({'where':{'id':_0x2afc37[_0xc85c('0x20')]}})[_0xc85c('0x21')](function(_0x144180){if(_0x144180){_0x144180[_0xc85c('0x22')]({'lastMsgAt':_0x2afc37[_0xc85c('0x23')],'lastMsgDirection':_0x2afc37[_0xc85c('0x18')][_0xc85c('0x19')]()});}})[_0xc85c('0x24')](function(_0x52f0ff){console[_0xc85c('0x25')](_0x52f0ff);});}_0x3f7827();}},'charset':'utf8mb4','collate':_0xc85c('0x26')});};