Built motion from commit (unavailable).|2.5.14
[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 _0xbf91=['length','emit','catch','exports','MailInteraction','../../mysqldb','MailMessage','setMaxListeners','remove','getUsers','map','findAll'];(function(_0x333714,_0x3370ac){var _0x4c211e=function(_0x34219b){while(--_0x34219b){_0x333714['push'](_0x333714['shift']());}};_0x4c211e(++_0x3370ac);}(_0xbf91,0x1e4));var _0x1bf9=function(_0x27a9c3,_0x57829c){_0x27a9c3=_0x27a9c3-0x0;var _0x464765=_0xbf91[_0x27a9c3];return _0x464765;};'use strict';var EventEmitter=require('events');var MailInteraction=require('../../mysqldb')['db'][_0x1bf9('0x0')];var MailMessage=require(_0x1bf9('0x1'))['db'][_0x1bf9('0x2')];var MailInteractionEvents=new EventEmitter();MailInteractionEvents[_0x1bf9('0x3')](0x0);var events={'afterCreate':'save','afterUpdate':'update','afterDestroy':_0x1bf9('0x4')};function emitEvent(_0x5f3d24){return function(_0x9e18a4,_0x2ad565,_0x299c11){_0x9e18a4[_0x1bf9('0x5')]({'attributes':['id'],'raw':!![]})['then'](function(_0x10764d){_0x9e18a4['setDataValue']('Users',_0x10764d[_0x1bf9('0x6')](function(_0x27cf1f){return{'id':_0x27cf1f['id']};}));return MailMessage[_0x1bf9('0x7')]({'where':{'MailInteractionId':_0x9e18a4['id'],'direction':'in','read':![]},'raw':!![]});})['then'](function(_0x9914e0){_0x9e18a4['setDataValue']('unreadMessages',_0x9914e0[_0x1bf9('0x8')]);MailInteractionEvents[_0x1bf9('0x9')](_0x5f3d24+':'+_0x9e18a4['id'],_0x9e18a4);MailInteractionEvents[_0x1bf9('0x9')](_0x5f3d24,_0x9e18a4);_0x299c11(null);})[_0x1bf9('0xa')](_0x299c11(null));};}for(var e in events){if(events['hasOwnProperty'](e)){var event=events[e];MailInteraction['hook'](e,emitEvent(event));}}module[_0x1bf9('0xb')]=MailInteractionEvents;