4247726f818429d2569b99e22a7bdc29b7ea012b
[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 _0xe0b8=['then','setDataValue','Users','map','unreadMessages','length','emit','hasOwnProperty','hook','../../mysqldb','MailInteraction','MailMessage','save','update','remove','getUsers'];(function(_0x5119e3,_0x57f091){var _0x5d666c=function(_0xa3a5b2){while(--_0xa3a5b2){_0x5119e3['push'](_0x5119e3['shift']());}};_0x5d666c(++_0x57f091);}(_0xe0b8,0x69));var _0x8e0b=function(_0x3bf440,_0x3a9f01){_0x3bf440=_0x3bf440-0x0;var _0x2f468b=_0xe0b8[_0x3bf440];return _0x2f468b;};'use strict';var EventEmitter=require('events');var MailInteraction=require(_0x8e0b('0x0'))['db'][_0x8e0b('0x1')];var MailMessage=require('../../mysqldb')['db'][_0x8e0b('0x2')];var MailInteractionEvents=new EventEmitter();MailInteractionEvents['setMaxListeners'](0x0);var events={'afterCreate':_0x8e0b('0x3'),'afterUpdate':_0x8e0b('0x4'),'afterDestroy':_0x8e0b('0x5')};function emitEvent(_0x3496db){return function(_0x5dff12,_0x14919c,_0x15e3fb){_0x5dff12[_0x8e0b('0x6')]({'attributes':['id'],'raw':!![]})[_0x8e0b('0x7')](function(_0x3daf2d){_0x5dff12[_0x8e0b('0x8')](_0x8e0b('0x9'),_0x3daf2d[_0x8e0b('0xa')](function(_0x9e34c1){return{'id':_0x9e34c1['id']};}));return MailMessage['findAll']({'where':{'MailInteractionId':_0x5dff12['id'],'direction':'in','read':![]},'raw':!![]});})['then'](function(_0x32223d){_0x5dff12[_0x8e0b('0x8')](_0x8e0b('0xb'),_0x32223d[_0x8e0b('0xc')]);MailInteractionEvents['emit'](_0x3496db+':'+_0x5dff12['id'],_0x5dff12);MailInteractionEvents[_0x8e0b('0xd')](_0x3496db,_0x5dff12);_0x15e3fb(null);})['catch'](_0x15e3fb(null));};}for(var e in events){if(events[_0x8e0b('0xe')](e)){var event=events[e];MailInteraction[_0x8e0b('0xf')](e,emitEvent(event));}}module['exports']=MailInteractionEvents;