d4791db5420a792dbd88e98b4dba8fa4b0164154
[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 _0xb28c=['subject','body','models','get','direction','toLowerCase','out','secret','isNil','UserId','MailInteraction','then','createdAt','error','utf8mb4','lodash','util','../../config/logger','moment','request-promise','html-to-text','path','./mailMessage.attributes','exports','define','MailMessage','mail_messages','messageId','fti_mail_messages','plainBody'];(function(_0x38ca2d,_0x32240f){var _0x3d8356=function(_0x14abb9){while(--_0x14abb9){_0x38ca2d['push'](_0x38ca2d['shift']());}};_0x3d8356(++_0x32240f);}(_0xb28c,0x177));var _0xcb28=function(_0x42befa,_0x571a1c){_0x42befa=_0x42befa-0x0;var _0x4d6b2e=_0xb28c[_0x42befa];return _0x4d6b2e;};'use strict';var _=require(_0xcb28('0x0'));var util=require(_0xcb28('0x1'));var logger=require(_0xcb28('0x2'))('api');var moment=require(_0xcb28('0x3'));var BPromise=require('bluebird');var rp=require(_0xcb28('0x4'));var htmlToText=require(_0xcb28('0x5'));var fs=require('fs');var path=require(_0xcb28('0x6'));var rimraf=require('rimraf');var config=require('../../config/environment');var attributes=require(_0xcb28('0x7'));module[_0xcb28('0x8')]=function(_0x4cdcce,_0x580d69){return _0x4cdcce[_0xcb28('0x9')](_0xcb28('0xa'),attributes,{'tableName':_0xcb28('0xb'),'paranoid':![],'indexes':[{'name':'messageId','fields':[_0xcb28('0xc')]},{'name':_0xcb28('0xd'),'fields':[_0xcb28('0xe'),_0xcb28('0xf')],'type':'FULLTEXT'}],'timestamps':!![],'hooks':{'beforeCreate':function(_0xbd9b37,_0x2616bb,_0x20a6fe){if(_0xbd9b37[_0xcb28('0x10')]){_0xbd9b37['plainBody']=htmlToText['fromString'](_0xbd9b37[_0xcb28('0x10')],{'preserveNewlines':!![],'singleNewLineParagraphs':!![],'uppercaseHeadings':![],'noLinkBrackets':!![],'ignoreImage':!![]});}_0x20a6fe(null,_0x2616bb);},'afterCreate':function(_0x438d64,_0x3bfe0b,_0x175e86){var _0x325ece=_0x4cdcce[_0xcb28('0x11')];var _0x5f47f4=_0x438d64[_0xcb28('0x12')]({'plain':!![]});if(_0x5f47f4[_0xcb28('0x13')][_0xcb28('0x14')]()==='in'||_0x5f47f4[_0xcb28('0x13')][_0xcb28('0x14')]()===_0xcb28('0x15')&&!_0x5f47f4[_0xcb28('0x16')]&&!_[_0xcb28('0x17')](_0x5f47f4[_0xcb28('0x18')])){_0x325ece[_0xcb28('0x19')]['findOne']({'where':{'id':_0x5f47f4['MailInteractionId']}})[_0xcb28('0x1a')](function(_0x3d563c){if(_0x3d563c){_0x3d563c['update']({'lastMsgAt':_0x5f47f4[_0xcb28('0x1b')],'lastMsgDirection':_0x5f47f4[_0xcb28('0x13')][_0xcb28('0x14')]()});}})['catch'](function(_0x354820){console[_0xcb28('0x1c')](_0x354820);});}_0x175e86();}},'charset':_0xcb28('0x1d'),'collate':'utf8mb4_unicode_ci'});};