c204d61ec9729a0308d9cba1c9a7a6193800a32a
[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 _0x4fe5=['../../config/environment','./mailMessage.attributes','exports','MailMessage','mail_messages','messageId','fti_mail_messages','subject','FULLTEXT','body','plainBody','models','toLowerCase','direction','out','secret','isNil','MailInteraction','findOne','then','update','createdAt','error','utf8mb4','utf8mb4_unicode_ci','util','../../config/logger','bluebird','html-to-text','path'];(function(_0x204c1e,_0x58eaf8){var _0x227434=function(_0x540a16){while(--_0x540a16){_0x204c1e['push'](_0x204c1e['shift']());}};_0x227434(++_0x58eaf8);}(_0x4fe5,0x145));var _0x54fe=function(_0x25d0d3,_0x13e99d){_0x25d0d3=_0x25d0d3-0x0;var _0x578b61=_0x4fe5[_0x25d0d3];return _0x578b61;};'use strict';var _=require('lodash');var util=require(_0x54fe('0x0'));var logger=require(_0x54fe('0x1'))('api');var moment=require('moment');var BPromise=require(_0x54fe('0x2'));var rp=require('request-promise');var htmlToText=require(_0x54fe('0x3'));var fs=require('fs');var path=require(_0x54fe('0x4'));var rimraf=require('rimraf');var config=require(_0x54fe('0x5'));var attributes=require(_0x54fe('0x6'));module[_0x54fe('0x7')]=function(_0x214e38,_0xed9c8e){return _0x214e38['define'](_0x54fe('0x8'),attributes,{'tableName':_0x54fe('0x9'),'paranoid':![],'indexes':[{'name':_0x54fe('0xa'),'fields':[_0x54fe('0xa')]},{'name':_0x54fe('0xb'),'fields':['plainBody',_0x54fe('0xc')],'type':_0x54fe('0xd')}],'timestamps':!![],'hooks':{'beforeCreate':function(_0x175743,_0x3cc803,_0xfc9e03){if(_0x175743[_0x54fe('0xe')]){_0x175743[_0x54fe('0xf')]=htmlToText['fromString'](_0x175743['body'],{'preserveNewlines':!![],'singleNewLineParagraphs':!![],'uppercaseHeadings':![],'noLinkBrackets':!![],'ignoreImage':!![]});}_0xfc9e03(null,_0x3cc803);},'afterCreate':function(_0x224b97,_0x46b6c8,_0x1657df){var _0x68f59f=_0x214e38[_0x54fe('0x10')];var _0x23398b=_0x224b97['get']({'plain':!![]});if(_0x23398b['direction'][_0x54fe('0x11')]()==='in'||_0x23398b[_0x54fe('0x12')][_0x54fe('0x11')]()===_0x54fe('0x13')&&!_0x23398b[_0x54fe('0x14')]&&!_[_0x54fe('0x15')](_0x23398b['UserId'])){_0x68f59f[_0x54fe('0x16')][_0x54fe('0x17')]({'where':{'id':_0x23398b['MailInteractionId']}})[_0x54fe('0x18')](function(_0x6bc215){if(_0x6bc215){_0x6bc215[_0x54fe('0x19')]({'lastMsgAt':_0x23398b[_0x54fe('0x1a')],'lastMsgDirection':_0x23398b['direction'][_0x54fe('0x11')]()});}})['catch'](function(_0x5151e8){console[_0x54fe('0x1b')](_0x5151e8);});}_0x1657df();}},'charset':_0x54fe('0x1c'),'collate':_0x54fe('0x1d')});};