a7106718c47c44562a750faa6a19fbe5173431c9
[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 _0xd48f=['path','rimraf','../../config/environment','MailMessage','mail_messages','messageId','fti_mail_messages','plainBody','FULLTEXT','body','fromString','models','get','direction','toLowerCase','out','secret','isNil','UserId','findOne','MailInteractionId','catch','utf8mb4','lodash','util','../../config/logger','api','moment'];(function(_0x22b5fa,_0x5702d8){var _0x385ac0=function(_0x2b1ef1){while(--_0x2b1ef1){_0x22b5fa['push'](_0x22b5fa['shift']());}};_0x385ac0(++_0x5702d8);}(_0xd48f,0x87));var _0xfd48=function(_0x57b54c,_0x54ce0d){_0x57b54c=_0x57b54c-0x0;var _0x59cc19=_0xd48f[_0x57b54c];return _0x59cc19;};'use strict';var _=require(_0xfd48('0x0'));var util=require(_0xfd48('0x1'));var logger=require(_0xfd48('0x2'))(_0xfd48('0x3'));var moment=require(_0xfd48('0x4'));var BPromise=require('bluebird');var rp=require('request-promise');var htmlToText=require('html-to-text');var fs=require('fs');var path=require(_0xfd48('0x5'));var rimraf=require(_0xfd48('0x6'));var config=require(_0xfd48('0x7'));var attributes=require('./mailMessage.attributes');module['exports']=function(_0x417ddb,_0x37c242){return _0x417ddb['define'](_0xfd48('0x8'),attributes,{'tableName':_0xfd48('0x9'),'paranoid':![],'indexes':[{'name':_0xfd48('0xa'),'fields':['messageId']},{'name':_0xfd48('0xb'),'fields':[_0xfd48('0xc'),'subject'],'type':_0xfd48('0xd')}],'timestamps':!![],'hooks':{'beforeCreate':function(_0x380caf,_0x3e5455,_0x4bc0ec){if(_0x380caf[_0xfd48('0xe')]){_0x380caf[_0xfd48('0xc')]=htmlToText[_0xfd48('0xf')](_0x380caf[_0xfd48('0xe')],{'preserveNewlines':!![],'singleNewLineParagraphs':!![],'uppercaseHeadings':![],'noLinkBrackets':!![],'ignoreImage':!![]});}_0x4bc0ec(null,_0x3e5455);},'afterCreate':function(_0x41b264,_0x6744fd,_0x1be06a){var _0x122668=_0x417ddb[_0xfd48('0x10')];var _0x5f5c08=_0x41b264[_0xfd48('0x11')]({'plain':!![]});if(_0x5f5c08['direction']['toLowerCase']()==='in'||_0x5f5c08[_0xfd48('0x12')][_0xfd48('0x13')]()===_0xfd48('0x14')&&!_0x5f5c08[_0xfd48('0x15')]&&!_[_0xfd48('0x16')](_0x5f5c08[_0xfd48('0x17')])){_0x122668['MailInteraction'][_0xfd48('0x18')]({'where':{'id':_0x5f5c08[_0xfd48('0x19')]}})['then'](function(_0x139572){if(_0x139572){_0x139572['update']({'lastMsgAt':_0x5f5c08['createdAt'],'lastMsgDirection':_0x5f5c08[_0xfd48('0x12')]['toLowerCase']()});}})[_0xfd48('0x1a')](function(_0x335fa2){console['error'](_0x335fa2);});}_0x1be06a();}},'charset':_0xfd48('0x1b'),'collate':'utf8mb4_unicode_ci'});};