cdb16c1ea1b08c8a72e8321e70a302c87b07ca46
[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 _0x13fd=['html-to-text','path','./mailMessage.attributes','exports','define','MailMessage','mail_messages','messageId','fti_mail_messages','subject','FULLTEXT','body','plainBody','models','get','toLowerCase','direction','out','secret','isNil','UserId','MailInteraction','findOne','MailInteractionId','then','createdAt','catch','error','lodash','util','../../config/logger','api','moment','bluebird','request-promise'];(function(_0x2be838,_0x2d98cf){var _0x4e9828=function(_0x1b3cc7){while(--_0x1b3cc7){_0x2be838['push'](_0x2be838['shift']());}};_0x4e9828(++_0x2d98cf);}(_0x13fd,0x1e3));var _0xd13f=function(_0x268142,_0x5c5dbe){_0x268142=_0x268142-0x0;var _0x312eb6=_0x13fd[_0x268142];return _0x312eb6;};'use strict';var _=require(_0xd13f('0x0'));var util=require(_0xd13f('0x1'));var logger=require(_0xd13f('0x2'))(_0xd13f('0x3'));var moment=require(_0xd13f('0x4'));var BPromise=require(_0xd13f('0x5'));var rp=require(_0xd13f('0x6'));var htmlToText=require(_0xd13f('0x7'));var fs=require('fs');var path=require(_0xd13f('0x8'));var rimraf=require('rimraf');var config=require('../../config/environment');var attributes=require(_0xd13f('0x9'));module[_0xd13f('0xa')]=function(_0x1baa6d,_0x4e2f12){return _0x1baa6d[_0xd13f('0xb')](_0xd13f('0xc'),attributes,{'tableName':_0xd13f('0xd'),'paranoid':![],'indexes':[{'name':'messageId','fields':[_0xd13f('0xe')]},{'name':_0xd13f('0xf'),'fields':['plainBody',_0xd13f('0x10')],'type':_0xd13f('0x11')}],'timestamps':!![],'hooks':{'beforeCreate':function(_0x8d3176,_0x481706,_0x424c03){if(_0x8d3176[_0xd13f('0x12')]){_0x8d3176[_0xd13f('0x13')]=htmlToText['fromString'](_0x8d3176[_0xd13f('0x12')],{'preserveNewlines':!![],'singleNewLineParagraphs':!![],'uppercaseHeadings':![],'noLinkBrackets':!![],'ignoreImage':!![]});}_0x424c03(null,_0x481706);},'afterCreate':function(_0x4210da,_0x550c0e,_0x4ff2e6){var _0x597686=_0x1baa6d[_0xd13f('0x14')];var _0x12c299=_0x4210da[_0xd13f('0x15')]({'plain':!![]});if(_0x12c299['direction'][_0xd13f('0x16')]()==='in'||_0x12c299[_0xd13f('0x17')][_0xd13f('0x16')]()===_0xd13f('0x18')&&!_0x12c299[_0xd13f('0x19')]&&!_[_0xd13f('0x1a')](_0x12c299[_0xd13f('0x1b')])){_0x597686[_0xd13f('0x1c')][_0xd13f('0x1d')]({'where':{'id':_0x12c299[_0xd13f('0x1e')]}})[_0xd13f('0x1f')](function(_0x3cc012){if(_0x3cc012){_0x3cc012['update']({'lastMsgAt':_0x12c299[_0xd13f('0x20')],'lastMsgDirection':_0x12c299[_0xd13f('0x17')][_0xd13f('0x16')]()});}})[_0xd13f('0x21')](function(_0xfc0b6e){console[_0xd13f('0x22')](_0xfc0b6e);});}_0x4ff2e6();}},'charset':'utf8mb4','collate':'utf8mb4_unicode_ci'});};