6c70aaa359a20e872a2db82171189daeaf8845c7
[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 _0x10fb=['unreadMessages','length','emit','hook','events','MailInteraction','../../mysqldb','MailMessage','save','getUsers','then','setDataValue','Users','map','findAll'];(function(_0x14477e,_0x44d4da){var _0x5d4a05=function(_0x5e0fa3){while(--_0x5e0fa3){_0x14477e['push'](_0x14477e['shift']());}};_0x5d4a05(++_0x44d4da);}(_0x10fb,0xe5));var _0xb10f=function(_0x19c57a,_0x5c9c7c){_0x19c57a=_0x19c57a-0x0;var _0x576a08=_0x10fb[_0x19c57a];return _0x576a08;};'use strict';var EventEmitter=require(_0xb10f('0x0'));var MailInteraction=require('../../mysqldb')['db'][_0xb10f('0x1')];var MailMessage=require(_0xb10f('0x2'))['db'][_0xb10f('0x3')];var MailInteractionEvents=new EventEmitter();MailInteractionEvents['setMaxListeners'](0x0);var events={'afterCreate':_0xb10f('0x4'),'afterUpdate':'update','afterDestroy':'remove'};function emitEvent(_0x2bc420){return function(_0xa7e63a,_0x384203,_0x19a096){_0xa7e63a[_0xb10f('0x5')]({'attributes':['id'],'raw':!![]})[_0xb10f('0x6')](function(_0x4c5bc7){_0xa7e63a[_0xb10f('0x7')](_0xb10f('0x8'),_0x4c5bc7[_0xb10f('0x9')](function(_0x3da9e3){return{'id':_0x3da9e3['id']};}));return MailMessage[_0xb10f('0xa')]({'where':{'MailInteractionId':_0xa7e63a['id'],'direction':'in','read':![]},'raw':!![]});})[_0xb10f('0x6')](function(_0x25ff17){_0xa7e63a[_0xb10f('0x7')](_0xb10f('0xb'),_0x25ff17[_0xb10f('0xc')]);MailInteractionEvents[_0xb10f('0xd')](_0x2bc420+':'+_0xa7e63a['id'],_0xa7e63a);MailInteractionEvents['emit'](_0x2bc420,_0xa7e63a);_0x19a096(null);})['catch'](_0x19a096(null));};}for(var e in events){if(events['hasOwnProperty'](e)){var event=events[e];MailInteraction[_0xb10f('0xe')](e,emitEvent(event));}}module['exports']=MailInteractionEvents;