Built motion from commit (unavailable).|2.5.2
[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 _0x2d94=['events','../../mysqldb','MailInteraction','MailMessage','setMaxListeners','save','update','remove','getUsers','then','setDataValue','unreadMessages','emit','catch','hasOwnProperty','exports'];(function(_0x3227c1,_0x4318c5){var _0x31fd48=function(_0x5c5850){while(--_0x5c5850){_0x3227c1['push'](_0x3227c1['shift']());}};_0x31fd48(++_0x4318c5);}(_0x2d94,0x100));var _0x42d9=function(_0x4bca7a,_0x36bc17){_0x4bca7a=_0x4bca7a-0x0;var _0x5e20e8=_0x2d94[_0x4bca7a];return _0x5e20e8;};'use strict';var EventEmitter=require(_0x42d9('0x0'));var MailInteraction=require(_0x42d9('0x1'))['db'][_0x42d9('0x2')];var MailMessage=require('../../mysqldb')['db'][_0x42d9('0x3')];var MailInteractionEvents=new EventEmitter();MailInteractionEvents[_0x42d9('0x4')](0x0);var events={'afterCreate':_0x42d9('0x5'),'afterUpdate':_0x42d9('0x6'),'afterDestroy':_0x42d9('0x7')};function emitEvent(_0x37d0dc){return function(_0x150559,_0x357a5b,_0x2f5716){_0x150559[_0x42d9('0x8')]({'attributes':['id'],'raw':!![]})[_0x42d9('0x9')](function(_0x596344){_0x150559[_0x42d9('0xa')]('Users',_0x596344['map'](function(_0x1f7ce1){return{'id':_0x1f7ce1['id']};}));return MailMessage['findAll']({'where':{'MailInteractionId':_0x150559['id'],'direction':'in','read':![]},'raw':!![]});})[_0x42d9('0x9')](function(_0x27d8cf){_0x150559[_0x42d9('0xa')](_0x42d9('0xb'),_0x27d8cf['length']);MailInteractionEvents['emit'](_0x37d0dc+':'+_0x150559['id'],_0x150559);MailInteractionEvents[_0x42d9('0xc')](_0x37d0dc,_0x150559);_0x2f5716(null);})[_0x42d9('0xd')](_0x2f5716(null));};}for(var e in events){if(events[_0x42d9('0xe')](e)){var event=events[e];MailInteraction['hook'](e,emitEvent(event));}}module[_0x42d9('0xf')]=MailInteractionEvents;