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 _0xf6a9=['catch','error','utf8mb4','utf8mb4_unicode_ci','../../config/logger','api','request-promise','html-to-text','rimraf','../../config/environment','./mailMessage.attributes','exports','define','mail_messages','messageId','fti_mail_messages','plainBody','subject','FULLTEXT','body','fromString','models','get','direction','toLowerCase','secret','isNil','UserId','MailInteraction','findOne','MailInteractionId','then','update','createdAt'];(function(_0x2641f9,_0x26715f){var _0x585741=function(_0x2d1462){while(--_0x2d1462){_0x2641f9['push'](_0x2641f9['shift']());}};_0x585741(++_0x26715f);}(_0xf6a9,0x158));var _0x9f6a=function(_0x2ae8bb,_0x422843){_0x2ae8bb=_0x2ae8bb-0x0;var _0x3a38a3=_0xf6a9[_0x2ae8bb];return _0x3a38a3;};'use strict';var _=require('lodash');var util=require('util');var logger=require(_0x9f6a('0x0'))(_0x9f6a('0x1'));var moment=require('moment');var BPromise=require('bluebird');var rp=require(_0x9f6a('0x2'));var htmlToText=require(_0x9f6a('0x3'));var fs=require('fs');var path=require('path');var rimraf=require(_0x9f6a('0x4'));var config=require(_0x9f6a('0x5'));var attributes=require(_0x9f6a('0x6'));module[_0x9f6a('0x7')]=function(_0x365ebe,_0x39f8d5){return _0x365ebe[_0x9f6a('0x8')]('MailMessage',attributes,{'tableName':_0x9f6a('0x9'),'paranoid':![],'indexes':[{'name':_0x9f6a('0xa'),'fields':[_0x9f6a('0xa')]},{'name':_0x9f6a('0xb'),'fields':[_0x9f6a('0xc'),_0x9f6a('0xd')],'type':_0x9f6a('0xe')}],'timestamps':!![],'hooks':{'beforeCreate':function(_0x40c088,_0x371c0b,_0x48dad1){if(_0x40c088[_0x9f6a('0xf')]){_0x40c088[_0x9f6a('0xc')]=htmlToText[_0x9f6a('0x10')](_0x40c088[_0x9f6a('0xf')],{'preserveNewlines':!![],'singleNewLineParagraphs':!![],'uppercaseHeadings':![],'noLinkBrackets':!![],'ignoreImage':!![]});}_0x48dad1(null,_0x371c0b);},'afterCreate':function(_0xf21867,_0x5b24bf,_0x5873c1){var _0x3a6795=_0x365ebe[_0x9f6a('0x11')];var _0x5b2e39=_0xf21867[_0x9f6a('0x12')]({'plain':!![]});if(_0x5b2e39[_0x9f6a('0x13')][_0x9f6a('0x14')]()==='in'||_0x5b2e39[_0x9f6a('0x13')]['toLowerCase']()==='out'&&!_0x5b2e39[_0x9f6a('0x15')]&&!_[_0x9f6a('0x16')](_0x5b2e39[_0x9f6a('0x17')])){_0x3a6795[_0x9f6a('0x18')][_0x9f6a('0x19')]({'where':{'id':_0x5b2e39[_0x9f6a('0x1a')]}})[_0x9f6a('0x1b')](function(_0x2b58f1){if(_0x2b58f1){_0x2b58f1[_0x9f6a('0x1c')]({'lastMsgAt':_0x5b2e39[_0x9f6a('0x1d')],'lastMsgDirection':_0x5b2e39[_0x9f6a('0x13')][_0x9f6a('0x14')]()});}})[_0x9f6a('0x1e')](function(_0x347225){console[_0x9f6a('0x1f')](_0x347225);});}_0x5873c1();}},'charset':_0x9f6a('0x20'),'collate':_0x9f6a('0x21')});};