Built motion from commit 9e1399f3.|2.5.37
[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 _0x2d67=['emit','catch','hook','events','../../mysqldb','MailInteraction','MailMessage','setMaxListeners','save','update','remove','getUsers','then','setDataValue','Users','findAll'];(function(_0x5a58af,_0x2fd0e0){var _0x40b593=function(_0x354331){while(--_0x354331){_0x5a58af['push'](_0x5a58af['shift']());}};_0x40b593(++_0x2fd0e0);}(_0x2d67,0xc3));var _0x72d6=function(_0x50c16c,_0x43b99e){_0x50c16c=_0x50c16c-0x0;var _0x24dc5f=_0x2d67[_0x50c16c];return _0x24dc5f;};'use strict';var EventEmitter=require(_0x72d6('0x0'));var MailInteraction=require(_0x72d6('0x1'))['db'][_0x72d6('0x2')];var MailMessage=require(_0x72d6('0x1'))['db'][_0x72d6('0x3')];var MailInteractionEvents=new EventEmitter();MailInteractionEvents[_0x72d6('0x4')](0x0);var events={'afterCreate':_0x72d6('0x5'),'afterUpdate':_0x72d6('0x6'),'afterDestroy':_0x72d6('0x7')};function emitEvent(_0x5c4070){return function(_0x46e469,_0x3260be,_0x4adc62){_0x46e469[_0x72d6('0x8')]({'attributes':['id'],'raw':!![]})[_0x72d6('0x9')](function(_0x36c3cc){_0x46e469[_0x72d6('0xa')](_0x72d6('0xb'),_0x36c3cc['map'](function(_0x32d724){return{'id':_0x32d724['id']};}));return MailMessage[_0x72d6('0xc')]({'where':{'MailInteractionId':_0x46e469['id'],'direction':'in','read':![]},'raw':!![]});})[_0x72d6('0x9')](function(_0x28c60e){_0x46e469['setDataValue']('unreadMessages',_0x28c60e['length']);MailInteractionEvents[_0x72d6('0xd')](_0x5c4070+':'+_0x46e469['id'],_0x46e469);MailInteractionEvents[_0x72d6('0xd')](_0x5c4070,_0x46e469);_0x4adc62(null);})[_0x72d6('0xe')](_0x4adc62(null));};}for(var e in events){if(events['hasOwnProperty'](e)){var event=events[e];MailInteraction[_0x72d6('0xf')](e,emitEvent(event));}}module['exports']=MailInteractionEvents;