Built motion from commit (unavailable).|2.4.20
[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 _0xc886=['then','setDataValue','Users','map','findAll','length','emit','catch','hasOwnProperty','exports','../../mysqldb','MailInteraction','MailMessage','setMaxListeners','save','update','remove'];(function(_0x360bcb,_0x212dfa){var _0x4dc433=function(_0x2872c6){while(--_0x2872c6){_0x360bcb['push'](_0x360bcb['shift']());}};_0x4dc433(++_0x212dfa);}(_0xc886,0x191));var _0x6c88=function(_0x336579,_0x5c63c0){_0x336579=_0x336579-0x0;var _0x4c46c0=_0xc886[_0x336579];return _0x4c46c0;};'use strict';var EventEmitter=require('events');var MailInteraction=require(_0x6c88('0x0'))['db'][_0x6c88('0x1')];var MailMessage=require('../../mysqldb')['db'][_0x6c88('0x2')];var MailInteractionEvents=new EventEmitter();MailInteractionEvents[_0x6c88('0x3')](0x0);var events={'afterCreate':_0x6c88('0x4'),'afterUpdate':_0x6c88('0x5'),'afterDestroy':_0x6c88('0x6')};function emitEvent(_0x467e82){return function(_0x27468b,_0x510af8,_0x1489da){_0x27468b['getUsers']({'attributes':['id'],'raw':!![]})[_0x6c88('0x7')](function(_0x36c14d){_0x27468b[_0x6c88('0x8')](_0x6c88('0x9'),_0x36c14d[_0x6c88('0xa')](function(_0x429818){return{'id':_0x429818['id']};}));return MailMessage[_0x6c88('0xb')]({'where':{'MailInteractionId':_0x27468b['id'],'direction':'in','read':![]},'raw':!![]});})['then'](function(_0x2c531f){_0x27468b[_0x6c88('0x8')]('unreadMessages',_0x2c531f[_0x6c88('0xc')]);MailInteractionEvents['emit'](_0x467e82+':'+_0x27468b['id'],_0x27468b);MailInteractionEvents[_0x6c88('0xd')](_0x467e82,_0x27468b);_0x1489da(null);})[_0x6c88('0xe')](_0x1489da(null));};}for(var e in events){if(events[_0x6c88('0xf')](e)){var event=events[e];MailInteraction['hook'](e,emitEvent(event));}}module[_0x6c88('0x10')]=MailInteractionEvents;