85a13847165d27a87154a3ad8a90de942556bf4f
[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 _0xea8d=['./mailMessage.attributes','exports','define','MailMessage','messageId','fti_mail_messages','plainBody','subject','FULLTEXT','body','fromString','models','get','toLowerCase','out','secret','isNil','MailInteraction','findOne','then','update','createdAt','direction','catch','error','utf8mb4','utf8mb4_unicode_ci','util','../../config/logger','bluebird','path','rimraf','../../config/environment'];(function(_0x304320,_0x232a69){var _0xe607da=function(_0x2eb451){while(--_0x2eb451){_0x304320['push'](_0x304320['shift']());}};_0xe607da(++_0x232a69);}(_0xea8d,0x102));var _0xdea8=function(_0x2264cc,_0x5b4181){_0x2264cc=_0x2264cc-0x0;var _0x8a36e=_0xea8d[_0x2264cc];return _0x8a36e;};'use strict';var _=require('lodash');var util=require(_0xdea8('0x0'));var logger=require(_0xdea8('0x1'))('api');var moment=require('moment');var BPromise=require(_0xdea8('0x2'));var rp=require('request-promise');var htmlToText=require('html-to-text');var fs=require('fs');var path=require(_0xdea8('0x3'));var rimraf=require(_0xdea8('0x4'));var config=require(_0xdea8('0x5'));var attributes=require(_0xdea8('0x6'));module[_0xdea8('0x7')]=function(_0x45a274,_0x2a7bac){return _0x45a274[_0xdea8('0x8')](_0xdea8('0x9'),attributes,{'tableName':'mail_messages','paranoid':![],'indexes':[{'name':'messageId','fields':[_0xdea8('0xa')]},{'name':_0xdea8('0xb'),'fields':[_0xdea8('0xc'),_0xdea8('0xd')],'type':_0xdea8('0xe')}],'timestamps':!![],'hooks':{'beforeCreate':function(_0x4e6c94,_0x94fa22,_0x4c2890){if(_0x4e6c94[_0xdea8('0xf')]){_0x4e6c94[_0xdea8('0xc')]=htmlToText[_0xdea8('0x10')](_0x4e6c94[_0xdea8('0xf')],{'preserveNewlines':!![],'singleNewLineParagraphs':!![],'uppercaseHeadings':![],'noLinkBrackets':!![],'ignoreImage':!![]});}_0x4c2890(null,_0x94fa22);},'afterCreate':function(_0x4d2cc2,_0x440280,_0xe008d3){var _0x1f13e0=_0x45a274[_0xdea8('0x11')];var _0x2c2860=_0x4d2cc2[_0xdea8('0x12')]({'plain':!![]});if(_0x2c2860['direction'][_0xdea8('0x13')]()==='in'||_0x2c2860['direction'][_0xdea8('0x13')]()===_0xdea8('0x14')&&!_0x2c2860[_0xdea8('0x15')]&&!_[_0xdea8('0x16')](_0x2c2860['UserId'])){_0x1f13e0[_0xdea8('0x17')][_0xdea8('0x18')]({'where':{'id':_0x2c2860['MailInteractionId']}})[_0xdea8('0x19')](function(_0xab64c1){if(_0xab64c1){_0xab64c1[_0xdea8('0x1a')]({'lastMsgAt':_0x2c2860[_0xdea8('0x1b')],'lastMsgDirection':_0x2c2860[_0xdea8('0x1c')][_0xdea8('0x13')](),'lastMsgBody':_0x2c2860[_0xdea8('0xf')]});}})[_0xdea8('0x1d')](function(_0x4c64fc){console[_0xdea8('0x1e')](_0x4c64fc);});}_0xe008d3();}},'charset':_0xdea8('0x1f'),'collate':_0xdea8('0x20')});};