Built motion from commit 838c2833.|2.6.24
[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 _0x3d5e=['setMaxListeners','update','remove','Users','map','findAll','then','setDataValue','length','emit','hasOwnProperty','exports','events','../../mysqldb','MailInteraction','MailMessage'];(function(_0x43dc7e,_0x49a390){var _0x21e12d=function(_0x15cc1a){while(--_0x15cc1a){_0x43dc7e['push'](_0x43dc7e['shift']());}};_0x21e12d(++_0x49a390);}(_0x3d5e,0x7c));var _0xe3d5=function(_0x286c9f,_0x549a3b){_0x286c9f=_0x286c9f-0x0;var _0x551bb2=_0x3d5e[_0x286c9f];return _0x551bb2;};'use strict';var EventEmitter=require(_0xe3d5('0x0'));var MailInteraction=require(_0xe3d5('0x1'))['db'][_0xe3d5('0x2')];var MailMessage=require(_0xe3d5('0x1'))['db'][_0xe3d5('0x3')];var MailInteractionEvents=new EventEmitter();MailInteractionEvents[_0xe3d5('0x4')](0x0);var events={'afterCreate':'save','afterUpdate':_0xe3d5('0x5'),'afterDestroy':_0xe3d5('0x6')};function emitEvent(_0x561b49){return function(_0x449b77,_0x358cb7,_0x53b62f){_0x449b77['getUsers']({'attributes':['id'],'raw':!![]})['then'](function(_0x42817f){_0x449b77['setDataValue'](_0xe3d5('0x7'),_0x42817f[_0xe3d5('0x8')](function(_0x477115){return{'id':_0x477115['id']};}));return MailMessage[_0xe3d5('0x9')]({'where':{'MailInteractionId':_0x449b77['id'],'direction':'in','read':![]},'raw':!![]});})[_0xe3d5('0xa')](function(_0xb65b7){_0x449b77[_0xe3d5('0xb')]('unreadMessages',_0xb65b7[_0xe3d5('0xc')]);MailInteractionEvents[_0xe3d5('0xd')](_0x561b49+':'+_0x449b77['id'],_0x449b77);MailInteractionEvents[_0xe3d5('0xd')](_0x561b49,_0x449b77);_0x53b62f(null);})['catch'](_0x53b62f(null));};}for(var e in events){if(events[_0xe3d5('0xe')](e)){var event=events[e];MailInteraction['hook'](e,emitEvent(event));}}module[_0xe3d5('0xf')]=MailInteractionEvents;