994945b4a53335809726dd3ab1c57ab3820aead5
[motion2.git] / server / api / mailInteraction / mailInteraction.events.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 _0xc630=['getUsers','then','setDataValue','Users','map','findAll','emit','hook','exports','events','../../mysqldb','MailInteraction','setMaxListeners','save','update'];(function(_0x2dadd3,_0x4556df){var _0x5a4221=function(_0x5b2dc8){while(--_0x5b2dc8){_0x2dadd3['push'](_0x2dadd3['shift']());}};_0x5a4221(++_0x4556df);}(_0xc630,0xea));var _0x0c63=function(_0x1e3b8c,_0x291f35){_0x1e3b8c=_0x1e3b8c-0x0;var _0x59c81e=_0xc630[_0x1e3b8c];return _0x59c81e;};'use strict';var EventEmitter=require(_0x0c63('0x0'));var MailInteraction=require(_0x0c63('0x1'))['db'][_0x0c63('0x2')];var MailMessage=require(_0x0c63('0x1'))['db']['MailMessage'];var MailInteractionEvents=new EventEmitter();MailInteractionEvents[_0x0c63('0x3')](0x0);var events={'afterCreate':_0x0c63('0x4'),'afterUpdate':_0x0c63('0x5'),'afterDestroy':'remove'};function emitEvent(_0x3a8aa9){return function(_0x5abd55,_0x4afcf6,_0x56c46b){_0x5abd55[_0x0c63('0x6')]({'attributes':['id'],'raw':!![]})[_0x0c63('0x7')](function(_0xa80f2f){_0x5abd55[_0x0c63('0x8')](_0x0c63('0x9'),_0xa80f2f[_0x0c63('0xa')](function(_0x48fcb9){return{'id':_0x48fcb9['id']};}));return MailMessage[_0x0c63('0xb')]({'where':{'MailInteractionId':_0x5abd55['id'],'direction':'in','read':![]},'raw':!![]});})['then'](function(_0x3cfb3d){_0x5abd55['setDataValue']('unreadMessages',_0x3cfb3d['length']);MailInteractionEvents[_0x0c63('0xc')](_0x3a8aa9+':'+_0x5abd55['id'],_0x5abd55);MailInteractionEvents[_0x0c63('0xc')](_0x3a8aa9,_0x5abd55);_0x56c46b(null);})['catch'](_0x56c46b(null));};}for(var e in events){if(events['hasOwnProperty'](e)){var event=events[e];MailInteraction[_0x0c63('0xd')](e,emitEvent(event));}}module[_0x0c63('0xe')]=MailInteractionEvents;