b6ac35ab7eed785a3647841f13ccc0317506a757
[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 _0xac2d=['fti_mail_messages','subject','FULLTEXT','plainBody','body','models','direction','toLowerCase','out','UserId','MailInteraction','MailInteractionId','then','createdAt','catch','utf8mb4','lodash','util','../../config/logger','api','moment','path','rimraf','../../config/environment','./mailMessage.attributes','exports','mail_messages','messageId'];(function(_0x10b2c4,_0x4b10ed){var _0xb10a8e=function(_0x58ff68){while(--_0x58ff68){_0x10b2c4['push'](_0x10b2c4['shift']());}};_0xb10a8e(++_0x4b10ed);}(_0xac2d,0x80));var _0xdac2=function(_0x12f644,_0x2935e6){_0x12f644=_0x12f644-0x0;var _0x4df795=_0xac2d[_0x12f644];return _0x4df795;};'use strict';var _=require(_0xdac2('0x0'));var util=require(_0xdac2('0x1'));var logger=require(_0xdac2('0x2'))(_0xdac2('0x3'));var moment=require(_0xdac2('0x4'));var BPromise=require('bluebird');var rp=require('request-promise');var htmlToText=require('html-to-text');var fs=require('fs');var path=require(_0xdac2('0x5'));var rimraf=require(_0xdac2('0x6'));var config=require(_0xdac2('0x7'));var attributes=require(_0xdac2('0x8'));module[_0xdac2('0x9')]=function(_0x413efe,_0x59ca03){return _0x413efe['define']('MailMessage',attributes,{'tableName':_0xdac2('0xa'),'paranoid':![],'indexes':[{'name':_0xdac2('0xb'),'fields':['messageId']},{'name':_0xdac2('0xc'),'fields':['plainBody',_0xdac2('0xd')],'type':_0xdac2('0xe')}],'timestamps':!![],'hooks':{'beforeCreate':function(_0x32662c,_0xc052d8,_0x54c8e3){if(_0x32662c['body']){_0x32662c[_0xdac2('0xf')]=htmlToText['fromString'](_0x32662c[_0xdac2('0x10')],{'preserveNewlines':!![],'singleNewLineParagraphs':!![],'uppercaseHeadings':![],'noLinkBrackets':!![],'ignoreImage':!![]});}_0x54c8e3(null,_0xc052d8);},'afterCreate':function(_0x295d05,_0x52f1a2,_0xa0b859){var _0x239bbb=_0x413efe[_0xdac2('0x11')];var _0x29abb9=_0x295d05['get']({'plain':!![]});if(_0x29abb9[_0xdac2('0x12')][_0xdac2('0x13')]()==='in'||_0x29abb9['direction'][_0xdac2('0x13')]()===_0xdac2('0x14')&&!_0x29abb9['secret']&&!_['isNil'](_0x29abb9[_0xdac2('0x15')])){_0x239bbb[_0xdac2('0x16')]['findOne']({'where':{'id':_0x29abb9[_0xdac2('0x17')]}})[_0xdac2('0x18')](function(_0x291b9a){if(_0x291b9a){_0x291b9a['update']({'lastMsgAt':_0x29abb9[_0xdac2('0x19')],'lastMsgDirection':_0x29abb9['direction']['toLowerCase']()});}})[_0xdac2('0x1a')](function(_0x519d0b){console['error'](_0x519d0b);});}_0xa0b859();}},'charset':_0xdac2('0x1b'),'collate':'utf8mb4_unicode_ci'});};