Built motion from commit 85328c08.|2.5.50
[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 _0x9ce7=['Users','findAll','unreadMessages','length','emit','catch','exports','events','../../mysqldb','MailInteraction','MailMessage','setMaxListeners','save','update','getUsers','setDataValue'];(function(_0x5d4607,_0x6b5e7b){var _0x5e4a86=function(_0x46891a){while(--_0x46891a){_0x5d4607['push'](_0x5d4607['shift']());}};_0x5e4a86(++_0x6b5e7b);}(_0x9ce7,0x1e7));var _0x79ce=function(_0x2b7566,_0x122e4e){_0x2b7566=_0x2b7566-0x0;var _0x44dc9d=_0x9ce7[_0x2b7566];return _0x44dc9d;};'use strict';var EventEmitter=require(_0x79ce('0x0'));var MailInteraction=require(_0x79ce('0x1'))['db'][_0x79ce('0x2')];var MailMessage=require(_0x79ce('0x1'))['db'][_0x79ce('0x3')];var MailInteractionEvents=new EventEmitter();MailInteractionEvents[_0x79ce('0x4')](0x0);var events={'afterCreate':_0x79ce('0x5'),'afterUpdate':_0x79ce('0x6'),'afterDestroy':'remove'};function emitEvent(_0x72f14c){return function(_0x310f72,_0x3c227a,_0x5b02f4){_0x310f72[_0x79ce('0x7')]({'attributes':['id'],'raw':!![]})['then'](function(_0x194870){_0x310f72[_0x79ce('0x8')](_0x79ce('0x9'),_0x194870['map'](function(_0x3d2f39){return{'id':_0x3d2f39['id']};}));return MailMessage[_0x79ce('0xa')]({'where':{'MailInteractionId':_0x310f72['id'],'direction':'in','read':![]},'raw':!![]});})['then'](function(_0x10b95d){_0x310f72[_0x79ce('0x8')](_0x79ce('0xb'),_0x10b95d[_0x79ce('0xc')]);MailInteractionEvents['emit'](_0x72f14c+':'+_0x310f72['id'],_0x310f72);MailInteractionEvents[_0x79ce('0xd')](_0x72f14c,_0x310f72);_0x5b02f4(null);})[_0x79ce('0xe')](_0x5b02f4(null));};}for(var e in events){if(events['hasOwnProperty'](e)){var event=events[e];MailInteraction['hook'](e,emitEvent(event));}}module[_0x79ce('0xf')]=MailInteractionEvents;