d8758a36cc7cc45de8dcd5f9b2f313b17a4621a2
[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 _0x791f=['hasOwnProperty','hook','exports','events','MailInteraction','MailMessage','setMaxListeners','save','update','remove','getUsers','then','setDataValue','Users','map','findAll','length','emit','catch'];(function(_0x9b993d,_0x16efcc){var _0x2c30fb=function(_0x4c9abf){while(--_0x4c9abf){_0x9b993d['push'](_0x9b993d['shift']());}};_0x2c30fb(++_0x16efcc);}(_0x791f,0x16c));var _0xf791=function(_0x54b283,_0x5eb8a6){_0x54b283=_0x54b283-0x0;var _0x2462b3=_0x791f[_0x54b283];return _0x2462b3;};'use strict';var EventEmitter=require(_0xf791('0x0'));var MailInteraction=require('../../mysqldb')['db'][_0xf791('0x1')];var MailMessage=require('../../mysqldb')['db'][_0xf791('0x2')];var MailInteractionEvents=new EventEmitter();MailInteractionEvents[_0xf791('0x3')](0x0);var events={'afterCreate':_0xf791('0x4'),'afterUpdate':_0xf791('0x5'),'afterDestroy':_0xf791('0x6')};function emitEvent(_0x34b6cc){return function(_0x2df832,_0x1136b7,_0x4fba0){_0x2df832[_0xf791('0x7')]({'attributes':['id'],'raw':!![]})[_0xf791('0x8')](function(_0x414233){_0x2df832[_0xf791('0x9')](_0xf791('0xa'),_0x414233[_0xf791('0xb')](function(_0x4f0a70){return{'id':_0x4f0a70['id']};}));return MailMessage[_0xf791('0xc')]({'where':{'MailInteractionId':_0x2df832['id'],'direction':'in','read':![]},'raw':!![]});})[_0xf791('0x8')](function(_0x219e4f){_0x2df832[_0xf791('0x9')]('unreadMessages',_0x219e4f[_0xf791('0xd')]);MailInteractionEvents[_0xf791('0xe')](_0x34b6cc+':'+_0x2df832['id'],_0x2df832);MailInteractionEvents['emit'](_0x34b6cc,_0x2df832);_0x4fba0(null);})[_0xf791('0xf')](_0x4fba0(null));};}for(var e in events){if(events[_0xf791('0x10')](e)){var event=events[e];MailInteraction[_0xf791('0x11')](e,emitEvent(event));}}module[_0xf791('0x12')]=MailInteractionEvents;