a0a19d9980b260c20cb55a7a412ae6695e2d1271
[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 _0xdac5=['length','emit','catch','exports','events','../../mysqldb','MailInteraction','setMaxListeners','remove','getUsers','then','setDataValue','Users','map','findAll','unreadMessages'];(function(_0x49052b,_0x3ba709){var _0x48c045=function(_0x41ac38){while(--_0x41ac38){_0x49052b['push'](_0x49052b['shift']());}};_0x48c045(++_0x3ba709);}(_0xdac5,0x64));var _0x5dac=function(_0x61318e,_0x257bc9){_0x61318e=_0x61318e-0x0;var _0x1c575b=_0xdac5[_0x61318e];return _0x1c575b;};'use strict';var EventEmitter=require(_0x5dac('0x0'));var MailInteraction=require(_0x5dac('0x1'))['db'][_0x5dac('0x2')];var MailMessage=require(_0x5dac('0x1'))['db']['MailMessage'];var MailInteractionEvents=new EventEmitter();MailInteractionEvents[_0x5dac('0x3')](0x0);var events={'afterCreate':'save','afterUpdate':'update','afterDestroy':_0x5dac('0x4')};function emitEvent(_0x18466a){return function(_0x43a864,_0x824906,_0x369ddd){_0x43a864[_0x5dac('0x5')]({'attributes':['id'],'raw':!![]})[_0x5dac('0x6')](function(_0x29d49f){_0x43a864[_0x5dac('0x7')](_0x5dac('0x8'),_0x29d49f[_0x5dac('0x9')](function(_0x470e31){return{'id':_0x470e31['id']};}));return MailMessage[_0x5dac('0xa')]({'where':{'MailInteractionId':_0x43a864['id'],'direction':'in','read':![]},'raw':!![]});})[_0x5dac('0x6')](function(_0x5f2b23){_0x43a864['setDataValue'](_0x5dac('0xb'),_0x5f2b23[_0x5dac('0xc')]);MailInteractionEvents[_0x5dac('0xd')](_0x18466a+':'+_0x43a864['id'],_0x43a864);MailInteractionEvents[_0x5dac('0xd')](_0x18466a,_0x43a864);_0x369ddd(null);})[_0x5dac('0xe')](_0x369ddd(null));};}for(var e in events){if(events['hasOwnProperty'](e)){var event=events[e];MailInteraction['hook'](e,emitEvent(event));}}module[_0x5dac('0xf')]=MailInteractionEvents;