35c15b9cedd4234b33d2cbc5e43423699bb33564
[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 _0x9acd=['exports','MailMessage','mail_messages','messageId','plainBody','subject','FULLTEXT','body','models','toLowerCase','direction','secret','isNil','UserId','findOne','MailInteractionId','update','createdAt','utf8mb4_unicode_ci','util','moment','bluebird','html-to-text','path','rimraf'];(function(_0x5279d1,_0x420ba5){var _0x446adb=function(_0x2c6727){while(--_0x2c6727){_0x5279d1['push'](_0x5279d1['shift']());}};_0x446adb(++_0x420ba5);}(_0x9acd,0xc2));var _0xd9ac=function(_0x160c73,_0x2ee678){_0x160c73=_0x160c73-0x0;var _0xd9302=_0x9acd[_0x160c73];return _0xd9302;};'use strict';var _=require('lodash');var util=require(_0xd9ac('0x0'));var logger=require('../../config/logger')('api');var moment=require(_0xd9ac('0x1'));var BPromise=require(_0xd9ac('0x2'));var rp=require('request-promise');var htmlToText=require(_0xd9ac('0x3'));var fs=require('fs');var path=require(_0xd9ac('0x4'));var rimraf=require(_0xd9ac('0x5'));var config=require('../../config/environment');var attributes=require('./mailMessage.attributes');module[_0xd9ac('0x6')]=function(_0x5e12a3,_0x4aff68){return _0x5e12a3['define'](_0xd9ac('0x7'),attributes,{'tableName':_0xd9ac('0x8'),'paranoid':![],'indexes':[{'name':_0xd9ac('0x9'),'fields':[_0xd9ac('0x9')]},{'name':'fti_mail_messages','fields':[_0xd9ac('0xa'),_0xd9ac('0xb')],'type':_0xd9ac('0xc')}],'timestamps':!![],'hooks':{'beforeCreate':function(_0x2ce8eb,_0xf492f5,_0x547384){if(_0x2ce8eb[_0xd9ac('0xd')]){_0x2ce8eb['plainBody']=htmlToText['fromString'](_0x2ce8eb['body'],{'preserveNewlines':!![],'singleNewLineParagraphs':!![],'uppercaseHeadings':![],'noLinkBrackets':!![],'ignoreImage':!![]});}_0x547384(null,_0xf492f5);},'afterCreate':function(_0x12ee6f,_0x10cd23,_0x3a7f0f){var _0x27c854=_0x5e12a3[_0xd9ac('0xe')];var _0x34c79d=_0x12ee6f['get']({'plain':!![]});if(_0x34c79d['direction'][_0xd9ac('0xf')]()==='in'||_0x34c79d[_0xd9ac('0x10')][_0xd9ac('0xf')]()==='out'&&!_0x34c79d[_0xd9ac('0x11')]&&!_[_0xd9ac('0x12')](_0x34c79d[_0xd9ac('0x13')])){_0x27c854['MailInteraction'][_0xd9ac('0x14')]({'where':{'id':_0x34c79d[_0xd9ac('0x15')]}})['then'](function(_0x15d806){if(_0x15d806){_0x15d806[_0xd9ac('0x16')]({'lastMsgAt':_0x34c79d[_0xd9ac('0x17')],'lastMsgDirection':_0x34c79d[_0xd9ac('0x10')][_0xd9ac('0xf')](),'lastMsgBody':_0x34c79d[_0xd9ac('0xd')]});}})['catch'](function(_0x1e5034){console['error'](_0x1e5034);});}_0x3a7f0f();}},'charset':'utf8mb4','collate':_0xd9ac('0x18')});};