d6d2e557ef5bd32027bb3d020414b0be1611e000
[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 _0x75c7=['setDataValue','Users','findAll','unreadMessages','length','emit','catch','hasOwnProperty','exports','events','../../mysqldb','MailInteraction','MailMessage','setMaxListeners','update','getUsers','then'];(function(_0x1531be,_0x261ec9){var _0x3ab22c=function(_0x38bdd7){while(--_0x38bdd7){_0x1531be['push'](_0x1531be['shift']());}};_0x3ab22c(++_0x261ec9);}(_0x75c7,0x91));var _0x775c=function(_0x22b39b,_0x2b7d63){_0x22b39b=_0x22b39b-0x0;var _0x280e1d=_0x75c7[_0x22b39b];return _0x280e1d;};'use strict';var EventEmitter=require(_0x775c('0x0'));var MailInteraction=require(_0x775c('0x1'))['db'][_0x775c('0x2')];var MailMessage=require(_0x775c('0x1'))['db'][_0x775c('0x3')];var MailInteractionEvents=new EventEmitter();MailInteractionEvents[_0x775c('0x4')](0x0);var events={'afterCreate':'save','afterUpdate':_0x775c('0x5'),'afterDestroy':'remove'};function emitEvent(_0x17672d){return function(_0x5cbfdb,_0x49b253,_0x5096ba){_0x5cbfdb[_0x775c('0x6')]({'attributes':['id'],'raw':!![]})[_0x775c('0x7')](function(_0xe816be){_0x5cbfdb[_0x775c('0x8')](_0x775c('0x9'),_0xe816be['map'](function(_0x451f3a){return{'id':_0x451f3a['id']};}));return MailMessage[_0x775c('0xa')]({'where':{'MailInteractionId':_0x5cbfdb['id'],'direction':'in','read':![]},'raw':!![]});})['then'](function(_0x27a002){_0x5cbfdb[_0x775c('0x8')](_0x775c('0xb'),_0x27a002[_0x775c('0xc')]);MailInteractionEvents['emit'](_0x17672d+':'+_0x5cbfdb['id'],_0x5cbfdb);MailInteractionEvents[_0x775c('0xd')](_0x17672d,_0x5cbfdb);_0x5096ba(null);})[_0x775c('0xe')](_0x5096ba(null));};}for(var e in events){if(events[_0x775c('0xf')](e)){var event=events[e];MailInteraction['hook'](e,emitEvent(event));}}module[_0x775c('0x10')]=MailInteractionEvents;