db2cded2b8732d757339c0f52d6d012650d847d6
[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 _0x5f79=['length','emit','catch','hook','exports','../../mysqldb','MailInteraction','setMaxListeners','update','remove','getUsers','setDataValue','Users','map','findAll','then','unreadMessages'];(function(_0x317f30,_0x38db95){var _0x2b2751=function(_0x2909f2){while(--_0x2909f2){_0x317f30['push'](_0x317f30['shift']());}};_0x2b2751(++_0x38db95);}(_0x5f79,0x126));var _0x95f7=function(_0x2c18a8,_0x24eaa5){_0x2c18a8=_0x2c18a8-0x0;var _0x1e009a=_0x5f79[_0x2c18a8];return _0x1e009a;};'use strict';var EventEmitter=require('events');var MailInteraction=require(_0x95f7('0x0'))['db'][_0x95f7('0x1')];var MailMessage=require('../../mysqldb')['db']['MailMessage'];var MailInteractionEvents=new EventEmitter();MailInteractionEvents[_0x95f7('0x2')](0x0);var events={'afterCreate':'save','afterUpdate':_0x95f7('0x3'),'afterDestroy':_0x95f7('0x4')};function emitEvent(_0x4e2b38){return function(_0x4d1578,_0x4b9023,_0x1936c3){_0x4d1578[_0x95f7('0x5')]({'attributes':['id'],'raw':!![]})['then'](function(_0x255f83){_0x4d1578[_0x95f7('0x6')](_0x95f7('0x7'),_0x255f83[_0x95f7('0x8')](function(_0x349d3b){return{'id':_0x349d3b['id']};}));return MailMessage[_0x95f7('0x9')]({'where':{'MailInteractionId':_0x4d1578['id'],'direction':'in','read':![]},'raw':!![]});})[_0x95f7('0xa')](function(_0x3f8b51){_0x4d1578['setDataValue'](_0x95f7('0xb'),_0x3f8b51[_0x95f7('0xc')]);MailInteractionEvents[_0x95f7('0xd')](_0x4e2b38+':'+_0x4d1578['id'],_0x4d1578);MailInteractionEvents['emit'](_0x4e2b38,_0x4d1578);_0x1936c3(null);})[_0x95f7('0xe')](_0x1936c3(null));};}for(var e in events){if(events['hasOwnProperty'](e)){var event=events[e];MailInteraction[_0x95f7('0xf')](e,emitEvent(event));}}module[_0x95f7('0x10')]=MailInteractionEvents;