9bc3e5a8d4b41693b34c94b428c1dcd586ef9ce7
[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 _0xf630=['FULLTEXT','fromString','body','models','get','toLowerCase','out','secret','UserId','MailInteraction','findOne','MailInteractionId','update','direction','catch','error','utf8mb4','utf8mb4_unicode_ci','lodash','util','../../config/logger','moment','bluebird','html-to-text','path','rimraf','../../config/environment','./mailMessage.attributes','exports','define','messageId','fti_mail_messages','plainBody','subject'];(function(_0x1f1837,_0x4b304e){var _0x25ab57=function(_0x4dec8c){while(--_0x4dec8c){_0x1f1837['push'](_0x1f1837['shift']());}};_0x25ab57(++_0x4b304e);}(_0xf630,0x1ee));var _0x0f63=function(_0x2402cf,_0x1dfd43){_0x2402cf=_0x2402cf-0x0;var _0x4a789a=_0xf630[_0x2402cf];return _0x4a789a;};'use strict';var _=require(_0x0f63('0x0'));var util=require(_0x0f63('0x1'));var logger=require(_0x0f63('0x2'))('api');var moment=require(_0x0f63('0x3'));var BPromise=require(_0x0f63('0x4'));var rp=require('request-promise');var htmlToText=require(_0x0f63('0x5'));var fs=require('fs');var path=require(_0x0f63('0x6'));var rimraf=require(_0x0f63('0x7'));var config=require(_0x0f63('0x8'));var attributes=require(_0x0f63('0x9'));module[_0x0f63('0xa')]=function(_0x3f14f5,_0x453f54){return _0x3f14f5[_0x0f63('0xb')]('MailMessage',attributes,{'tableName':'mail_messages','paranoid':![],'indexes':[{'name':'messageId','fields':[_0x0f63('0xc')]},{'name':_0x0f63('0xd'),'fields':[_0x0f63('0xe'),_0x0f63('0xf')],'type':_0x0f63('0x10')}],'timestamps':!![],'hooks':{'beforeCreate':function(_0x3e436e,_0x4c1f47,_0x3935a7){if(_0x3e436e['body']){_0x3e436e[_0x0f63('0xe')]=htmlToText[_0x0f63('0x11')](_0x3e436e[_0x0f63('0x12')],{'preserveNewlines':!![],'singleNewLineParagraphs':!![],'uppercaseHeadings':![],'noLinkBrackets':!![],'ignoreImage':!![]});}_0x3935a7(null,_0x4c1f47);},'afterCreate':function(_0x24a8b1,_0x295fec,_0x465a2e){var _0x175020=_0x3f14f5[_0x0f63('0x13')];var _0xadc1a1=_0x24a8b1[_0x0f63('0x14')]({'plain':!![]});if(_0xadc1a1['direction']['toLowerCase']()==='in'||_0xadc1a1['direction'][_0x0f63('0x15')]()===_0x0f63('0x16')&&!_0xadc1a1[_0x0f63('0x17')]&&!_['isNil'](_0xadc1a1[_0x0f63('0x18')])){_0x175020[_0x0f63('0x19')][_0x0f63('0x1a')]({'where':{'id':_0xadc1a1[_0x0f63('0x1b')]}})['then'](function(_0x1fbf6c){if(_0x1fbf6c){_0x1fbf6c[_0x0f63('0x1c')]({'lastMsgAt':_0xadc1a1['createdAt'],'lastMsgDirection':_0xadc1a1[_0x0f63('0x1d')][_0x0f63('0x15')]()});}})[_0x0f63('0x1e')](function(_0xe8d541){console[_0x0f63('0x1f')](_0xe8d541);});}_0x465a2e();}},'charset':_0x0f63('0x20'),'collate':_0x0f63('0x21')});};