1 // *************************************************************************
3 // * xCALLY Motion - The Omnichannel Contact Center *
4 // * Copyright (c) Xenialab s.r.l. All Rights Reserved *
6 // *************************************************************************
8 // * Email: info@xcally.com *
9 // * Website: https://www.xcally.com *
11 // *************************************************************************
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. *
17 // *************************************************************************
18 var _0x52af=['../../mysqldb','MailMessage','setMaxListeners','update','remove','getUsers','setDataValue','Users','map','hasOwnProperty','hook','events','MailInteraction'];(function(_0x180a8d,_0x432a75){var _0xe5b5c8=function(_0x48a91d){while(--_0x48a91d){_0x180a8d['push'](_0x180a8d['shift']());}};_0xe5b5c8(++_0x432a75);}(_0x52af,0x102));var _0xf52a=function(_0x1cc8fe,_0x105328){_0x1cc8fe=_0x1cc8fe-0x0;var _0x230054=_0x52af[_0x1cc8fe];return _0x230054;};'use strict';var EventEmitter=require(_0xf52a('0x0'));var MailInteraction=require('../../mysqldb')['db'][_0xf52a('0x1')];var MailMessage=require(_0xf52a('0x2'))['db'][_0xf52a('0x3')];var MailInteractionEvents=new EventEmitter();MailInteractionEvents[_0xf52a('0x4')](0x0);var events={'afterCreate':'save','afterUpdate':_0xf52a('0x5'),'afterDestroy':_0xf52a('0x6')};function emitEvent(_0xce0c07){return function(_0x50cf54,_0xf977cb,_0x455ae8){_0x50cf54[_0xf52a('0x7')]({'attributes':['id'],'raw':!![]})['then'](function(_0x4c8ecc){_0x50cf54[_0xf52a('0x8')](_0xf52a('0x9'),_0x4c8ecc[_0xf52a('0xa')](function(_0x3c848c){return{'id':_0x3c848c['id']};}));return MailMessage['findAll']({'where':{'MailInteractionId':_0x50cf54['id'],'direction':'in','read':![]},'raw':!![]});})['then'](function(_0x2f5061){_0x50cf54[_0xf52a('0x8')]('unreadMessages',_0x2f5061['length']);MailInteractionEvents['emit'](_0xce0c07+':'+_0x50cf54['id'],_0x50cf54);MailInteractionEvents['emit'](_0xce0c07,_0x50cf54);_0x455ae8(null);})['catch'](_0x455ae8(null));};}for(var e in events){if(events[_0xf52a('0xb')](e)){var event=events[e];MailInteraction[_0xf52a('0xc')](e,emitEvent(event));}}module['exports']=MailInteractionEvents;