Built motion from commit 5b761a7b.|2.5.36
[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 _0x1b6b=['events','../../mysqldb','MailMessage','setMaxListeners','update','remove','getUsers','setDataValue','map','findAll','then','unreadMessages','length','emit','hasOwnProperty','hook','exports'];(function(_0x385823,_0x371119){var _0x473998=function(_0x17d9c4){while(--_0x17d9c4){_0x385823['push'](_0x385823['shift']());}};_0x473998(++_0x371119);}(_0x1b6b,0xdd));var _0xb1b6=function(_0x1895e8,_0x40cc0e){_0x1895e8=_0x1895e8-0x0;var _0x219e6d=_0x1b6b[_0x1895e8];return _0x219e6d;};'use strict';var EventEmitter=require(_0xb1b6('0x0'));var MailInteraction=require('../../mysqldb')['db']['MailInteraction'];var MailMessage=require(_0xb1b6('0x1'))['db'][_0xb1b6('0x2')];var MailInteractionEvents=new EventEmitter();MailInteractionEvents[_0xb1b6('0x3')](0x0);var events={'afterCreate':'save','afterUpdate':_0xb1b6('0x4'),'afterDestroy':_0xb1b6('0x5')};function emitEvent(_0x1952b4){return function(_0xfb9a97,_0x502539,_0x441213){_0xfb9a97[_0xb1b6('0x6')]({'attributes':['id'],'raw':!![]})['then'](function(_0x223e8e){_0xfb9a97[_0xb1b6('0x7')]('Users',_0x223e8e[_0xb1b6('0x8')](function(_0x40e41b){return{'id':_0x40e41b['id']};}));return MailMessage[_0xb1b6('0x9')]({'where':{'MailInteractionId':_0xfb9a97['id'],'direction':'in','read':![]},'raw':!![]});})[_0xb1b6('0xa')](function(_0x3ed48c){_0xfb9a97[_0xb1b6('0x7')](_0xb1b6('0xb'),_0x3ed48c[_0xb1b6('0xc')]);MailInteractionEvents[_0xb1b6('0xd')](_0x1952b4+':'+_0xfb9a97['id'],_0xfb9a97);MailInteractionEvents['emit'](_0x1952b4,_0xfb9a97);_0x441213(null);})['catch'](_0x441213(null));};}for(var e in events){if(events[_0xb1b6('0xe')](e)){var event=events[e];MailInteraction[_0xb1b6('0xf')](e,emitEvent(event));}}module[_0xb1b6('0x10')]=MailInteractionEvents;