Built motion from commit 953226e6.|2.6.32
[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 _0x71e7=['events','MailInteraction','MailMessage','save','then','setDataValue','Users','map','findAll','unreadMessages','emit','catch','hasOwnProperty','exports'];(function(_0xc4d9ac,_0x313006){var _0x17f386=function(_0x273365){while(--_0x273365){_0xc4d9ac['push'](_0xc4d9ac['shift']());}};_0x17f386(++_0x313006);}(_0x71e7,0x188));var _0x771e=function(_0x5d7d2e,_0x197aab){_0x5d7d2e=_0x5d7d2e-0x0;var _0x5c96dd=_0x71e7[_0x5d7d2e];return _0x5c96dd;};'use strict';var EventEmitter=require(_0x771e('0x0'));var MailInteraction=require('../../mysqldb')['db'][_0x771e('0x1')];var MailMessage=require('../../mysqldb')['db'][_0x771e('0x2')];var MailInteractionEvents=new EventEmitter();MailInteractionEvents['setMaxListeners'](0x0);var events={'afterCreate':_0x771e('0x3'),'afterUpdate':'update','afterDestroy':'remove'};function emitEvent(_0x38e1cb){return function(_0x31b81b,_0x2e65d9,_0x18d262){_0x31b81b['getUsers']({'attributes':['id'],'raw':!![]})[_0x771e('0x4')](function(_0x5f5cd4){_0x31b81b[_0x771e('0x5')](_0x771e('0x6'),_0x5f5cd4[_0x771e('0x7')](function(_0x7b8e93){return{'id':_0x7b8e93['id']};}));return MailMessage[_0x771e('0x8')]({'where':{'MailInteractionId':_0x31b81b['id'],'direction':'in','read':![]},'raw':!![]});})[_0x771e('0x4')](function(_0x4b09cb){_0x31b81b[_0x771e('0x5')](_0x771e('0x9'),_0x4b09cb['length']);MailInteractionEvents[_0x771e('0xa')](_0x38e1cb+':'+_0x31b81b['id'],_0x31b81b);MailInteractionEvents['emit'](_0x38e1cb,_0x31b81b);_0x18d262(null);})[_0x771e('0xb')](_0x18d262(null));};}for(var e in events){if(events[_0x771e('0xc')](e)){var event=events[e];MailInteraction['hook'](e,emitEvent(event));}}module[_0x771e('0xd')]=MailInteractionEvents;