Built motion from commit 497d3d92.|2.5.43
[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 _0xe131=['toLowerCase','direction','out','secret','isNil','MailInteraction','findOne','MailInteractionId','then','update','createdAt','catch','error','utf8mb4_unicode_ci','lodash','util','../../config/logger','moment','bluebird','path','rimraf','../../config/environment','./mailMessage.attributes','exports','define','MailMessage','messageId','subject','plainBody','fromString','models','get'];(function(_0x3c6e80,_0xc729da){var _0x50e992=function(_0x46ea26){while(--_0x46ea26){_0x3c6e80['push'](_0x3c6e80['shift']());}};_0x50e992(++_0xc729da);}(_0xe131,0x8e));var _0x1e13=function(_0x2668be,_0x274c31){_0x2668be=_0x2668be-0x0;var _0x39299f=_0xe131[_0x2668be];return _0x39299f;};'use strict';var _=require(_0x1e13('0x0'));var util=require(_0x1e13('0x1'));var logger=require(_0x1e13('0x2'))('api');var moment=require(_0x1e13('0x3'));var BPromise=require(_0x1e13('0x4'));var rp=require('request-promise');var htmlToText=require('html-to-text');var fs=require('fs');var path=require(_0x1e13('0x5'));var rimraf=require(_0x1e13('0x6'));var config=require(_0x1e13('0x7'));var attributes=require(_0x1e13('0x8'));module[_0x1e13('0x9')]=function(_0x38c9ba,_0x1926ea){return _0x38c9ba[_0x1e13('0xa')](_0x1e13('0xb'),attributes,{'tableName':'mail_messages','paranoid':![],'indexes':[{'name':_0x1e13('0xc'),'fields':[_0x1e13('0xc')]},{'name':'fti_mail_messages','fields':['plainBody',_0x1e13('0xd')],'type':'FULLTEXT'}],'timestamps':!![],'hooks':{'beforeCreate':function(_0x1fabb8,_0x556e92,_0x544932){if(_0x1fabb8['body']){_0x1fabb8[_0x1e13('0xe')]=htmlToText[_0x1e13('0xf')](_0x1fabb8['body'],{'preserveNewlines':!![],'singleNewLineParagraphs':!![],'uppercaseHeadings':![],'noLinkBrackets':!![],'ignoreImage':!![]});}_0x544932(null,_0x556e92);},'afterCreate':function(_0x552cee,_0x28d0e8,_0x3fbb46){var _0x530ad7=_0x38c9ba[_0x1e13('0x10')];var _0x287eb4=_0x552cee[_0x1e13('0x11')]({'plain':!![]});if(_0x287eb4['direction'][_0x1e13('0x12')]()==='in'||_0x287eb4[_0x1e13('0x13')]['toLowerCase']()===_0x1e13('0x14')&&!_0x287eb4[_0x1e13('0x15')]&&!_[_0x1e13('0x16')](_0x287eb4['UserId'])){_0x530ad7[_0x1e13('0x17')][_0x1e13('0x18')]({'where':{'id':_0x287eb4[_0x1e13('0x19')]}})[_0x1e13('0x1a')](function(_0x53da80){if(_0x53da80){_0x53da80[_0x1e13('0x1b')]({'lastMsgAt':_0x287eb4[_0x1e13('0x1c')],'lastMsgDirection':_0x287eb4[_0x1e13('0x13')]['toLowerCase']()});}})[_0x1e13('0x1d')](function(_0x16efef){console[_0x1e13('0x1e')](_0x16efef);});}_0x3fbb46();}},'charset':'utf8mb4','collate':_0x1e13('0x1f')});};