Built motion from commit bab6f49e.|2.6.17
[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 _0x4aaf=['setDataValue','Users','unreadMessages','emit','catch','hasOwnProperty','events','../../mysqldb','MailMessage','setMaxListeners','save','remove','then'];(function(_0x359277,_0x5067bb){var _0x235a60=function(_0x949cf){while(--_0x949cf){_0x359277['push'](_0x359277['shift']());}};_0x235a60(++_0x5067bb);}(_0x4aaf,0x10a));var _0xf4aa=function(_0x886b04,_0x4598b3){_0x886b04=_0x886b04-0x0;var _0x18e6c2=_0x4aaf[_0x886b04];return _0x18e6c2;};'use strict';var EventEmitter=require(_0xf4aa('0x0'));var MailInteraction=require(_0xf4aa('0x1'))['db']['MailInteraction'];var MailMessage=require(_0xf4aa('0x1'))['db'][_0xf4aa('0x2')];var MailInteractionEvents=new EventEmitter();MailInteractionEvents[_0xf4aa('0x3')](0x0);var events={'afterCreate':_0xf4aa('0x4'),'afterUpdate':'update','afterDestroy':_0xf4aa('0x5')};function emitEvent(_0xc97b39){return function(_0x292db7,_0x4b96cd,_0x6a2cae){_0x292db7['getUsers']({'attributes':['id'],'raw':!![]})[_0xf4aa('0x6')](function(_0x13712e){_0x292db7[_0xf4aa('0x7')](_0xf4aa('0x8'),_0x13712e['map'](function(_0x24be73){return{'id':_0x24be73['id']};}));return MailMessage['findAll']({'where':{'MailInteractionId':_0x292db7['id'],'direction':'in','read':![]},'raw':!![]});})['then'](function(_0x1a2888){_0x292db7[_0xf4aa('0x7')](_0xf4aa('0x9'),_0x1a2888['length']);MailInteractionEvents[_0xf4aa('0xa')](_0xc97b39+':'+_0x292db7['id'],_0x292db7);MailInteractionEvents[_0xf4aa('0xa')](_0xc97b39,_0x292db7);_0x6a2cae(null);})[_0xf4aa('0xb')](_0x6a2cae(null));};}for(var e in events){if(events[_0xf4aa('0xc')](e)){var event=events[e];MailInteraction['hook'](e,emitEvent(event));}}module['exports']=MailInteractionEvents;