Built motion from commit 3c2ce842.|2.6.31
[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 _0x3ea9=['setDataValue','Users','findAll','length','emit','catch','hasOwnProperty','events','MailInteraction','MailMessage','setMaxListeners','save','update','getUsers','then'];(function(_0x2ddd63,_0xb39e2e){var _0x43e1ed=function(_0x2e1ddf){while(--_0x2e1ddf){_0x2ddd63['push'](_0x2ddd63['shift']());}};_0x43e1ed(++_0xb39e2e);}(_0x3ea9,0x1d8));var _0x93ea=function(_0xa42745,_0x436be0){_0xa42745=_0xa42745-0x0;var _0x49c702=_0x3ea9[_0xa42745];return _0x49c702;};'use strict';var EventEmitter=require(_0x93ea('0x0'));var MailInteraction=require('../../mysqldb')['db'][_0x93ea('0x1')];var MailMessage=require('../../mysqldb')['db'][_0x93ea('0x2')];var MailInteractionEvents=new EventEmitter();MailInteractionEvents[_0x93ea('0x3')](0x0);var events={'afterCreate':_0x93ea('0x4'),'afterUpdate':_0x93ea('0x5'),'afterDestroy':'remove'};function emitEvent(_0x220648){return function(_0x359168,_0xd0f754,_0x4d8186){_0x359168[_0x93ea('0x6')]({'attributes':['id'],'raw':!![]})[_0x93ea('0x7')](function(_0x416b18){_0x359168[_0x93ea('0x8')](_0x93ea('0x9'),_0x416b18['map'](function(_0x4d2951){return{'id':_0x4d2951['id']};}));return MailMessage[_0x93ea('0xa')]({'where':{'MailInteractionId':_0x359168['id'],'direction':'in','read':![]},'raw':!![]});})['then'](function(_0x3b9d35){_0x359168[_0x93ea('0x8')]('unreadMessages',_0x3b9d35[_0x93ea('0xb')]);MailInteractionEvents[_0x93ea('0xc')](_0x220648+':'+_0x359168['id'],_0x359168);MailInteractionEvents[_0x93ea('0xc')](_0x220648,_0x359168);_0x4d8186(null);})[_0x93ea('0xd')](_0x4d8186(null));};}for(var e in events){if(events[_0x93ea('0xe')](e)){var event=events[e];MailInteraction['hook'](e,emitEvent(event));}}module['exports']=MailInteractionEvents;