63cc6686c42ca95a2f6c4867242584df8efa74bf
[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 _0xc704=['MailInteraction','MailMessage','setMaxListeners','remove','getUsers','then','Users','findAll','setDataValue','emit','catch','hasOwnProperty','exports','events','../../mysqldb'];(function(_0x4e7186,_0x16e72c){var _0x1b5f8b=function(_0x5eddea){while(--_0x5eddea){_0x4e7186['push'](_0x4e7186['shift']());}};_0x1b5f8b(++_0x16e72c);}(_0xc704,0x11b));var _0x4c70=function(_0x3e514e,_0x45efa7){_0x3e514e=_0x3e514e-0x0;var _0x34c82c=_0xc704[_0x3e514e];return _0x34c82c;};'use strict';var EventEmitter=require(_0x4c70('0x0'));var MailInteraction=require(_0x4c70('0x1'))['db'][_0x4c70('0x2')];var MailMessage=require(_0x4c70('0x1'))['db'][_0x4c70('0x3')];var MailInteractionEvents=new EventEmitter();MailInteractionEvents[_0x4c70('0x4')](0x0);var events={'afterCreate':'save','afterUpdate':'update','afterDestroy':_0x4c70('0x5')};function emitEvent(_0x3fae55){return function(_0x562e6b,_0x27629a,_0x2dfe09){_0x562e6b[_0x4c70('0x6')]({'attributes':['id'],'raw':!![]})[_0x4c70('0x7')](function(_0x216523){_0x562e6b['setDataValue'](_0x4c70('0x8'),_0x216523['map'](function(_0x5f4d03){return{'id':_0x5f4d03['id']};}));return MailMessage[_0x4c70('0x9')]({'where':{'MailInteractionId':_0x562e6b['id'],'direction':'in','read':![]},'raw':!![]});})['then'](function(_0x2dd71b){_0x562e6b[_0x4c70('0xa')]('unreadMessages',_0x2dd71b['length']);MailInteractionEvents['emit'](_0x3fae55+':'+_0x562e6b['id'],_0x562e6b);MailInteractionEvents[_0x4c70('0xb')](_0x3fae55,_0x562e6b);_0x2dfe09(null);})[_0x4c70('0xc')](_0x2dfe09(null));};}for(var e in events){if(events[_0x4c70('0xd')](e)){var event=events[e];MailInteraction['hook'](e,emitEvent(event));}}module[_0x4c70('0xe')]=MailInteractionEvents;