d42e296c94ac43c7b16afc05136beaf7d28d985d
[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 _0xe3ff=['save','update','remove','getUsers','then','Users','map','setDataValue','unreadMessages','length','emit','hasOwnProperty','hook','exports','events','../../mysqldb','MailInteraction','MailMessage'];(function(_0x1d50f2,_0x3c3ec6){var _0x3769b8=function(_0x50926a){while(--_0x50926a){_0x1d50f2['push'](_0x1d50f2['shift']());}};_0x3769b8(++_0x3c3ec6);}(_0xe3ff,0x1d0));var _0xfe3f=function(_0x243a15,_0x286934){_0x243a15=_0x243a15-0x0;var _0x50868b=_0xe3ff[_0x243a15];return _0x50868b;};'use strict';var EventEmitter=require(_0xfe3f('0x0'));var MailInteraction=require(_0xfe3f('0x1'))['db'][_0xfe3f('0x2')];var MailMessage=require(_0xfe3f('0x1'))['db'][_0xfe3f('0x3')];var MailInteractionEvents=new EventEmitter();MailInteractionEvents['setMaxListeners'](0x0);var events={'afterCreate':_0xfe3f('0x4'),'afterUpdate':_0xfe3f('0x5'),'afterDestroy':_0xfe3f('0x6')};function emitEvent(_0x55f9fe){return function(_0x31ca7a,_0x40a70c,_0x12f684){_0x31ca7a[_0xfe3f('0x7')]({'attributes':['id'],'raw':!![]})[_0xfe3f('0x8')](function(_0x5863a1){_0x31ca7a['setDataValue'](_0xfe3f('0x9'),_0x5863a1[_0xfe3f('0xa')](function(_0x299dd9){return{'id':_0x299dd9['id']};}));return MailMessage['findAll']({'where':{'MailInteractionId':_0x31ca7a['id'],'direction':'in','read':![]},'raw':!![]});})['then'](function(_0x3d9703){_0x31ca7a[_0xfe3f('0xb')](_0xfe3f('0xc'),_0x3d9703[_0xfe3f('0xd')]);MailInteractionEvents[_0xfe3f('0xe')](_0x55f9fe+':'+_0x31ca7a['id'],_0x31ca7a);MailInteractionEvents[_0xfe3f('0xe')](_0x55f9fe,_0x31ca7a);_0x12f684(null);})['catch'](_0x12f684(null));};}for(var e in events){if(events[_0xfe3f('0xf')](e)){var event=events[e];MailInteraction[_0xfe3f('0x10')](e,emitEvent(event));}}module[_0xfe3f('0x11')]=MailInteractionEvents;