Built motion from commit 9d7072cc.|2.5.39
[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 _0x8f20=['events','../../mysqldb','MailInteraction','setMaxListeners','save','update','getUsers','setDataValue','Users','map','findAll','then','unreadMessages','length','emit','catch','hasOwnProperty'];(function(_0x3dd15e,_0x1f0015){var _0x231fd0=function(_0x4f680a){while(--_0x4f680a){_0x3dd15e['push'](_0x3dd15e['shift']());}};_0x231fd0(++_0x1f0015);}(_0x8f20,0x1dc));var _0x08f2=function(_0xefd519,_0xc62635){_0xefd519=_0xefd519-0x0;var _0x4bb882=_0x8f20[_0xefd519];return _0x4bb882;};'use strict';var EventEmitter=require(_0x08f2('0x0'));var MailInteraction=require(_0x08f2('0x1'))['db'][_0x08f2('0x2')];var MailMessage=require(_0x08f2('0x1'))['db']['MailMessage'];var MailInteractionEvents=new EventEmitter();MailInteractionEvents[_0x08f2('0x3')](0x0);var events={'afterCreate':_0x08f2('0x4'),'afterUpdate':_0x08f2('0x5'),'afterDestroy':'remove'};function emitEvent(_0x431579){return function(_0x5cd86e,_0x34b311,_0x3fb6f3){_0x5cd86e[_0x08f2('0x6')]({'attributes':['id'],'raw':!![]})['then'](function(_0x1fc246){_0x5cd86e[_0x08f2('0x7')](_0x08f2('0x8'),_0x1fc246[_0x08f2('0x9')](function(_0xdba5b){return{'id':_0xdba5b['id']};}));return MailMessage[_0x08f2('0xa')]({'where':{'MailInteractionId':_0x5cd86e['id'],'direction':'in','read':![]},'raw':!![]});})[_0x08f2('0xb')](function(_0x5f549b){_0x5cd86e[_0x08f2('0x7')](_0x08f2('0xc'),_0x5f549b[_0x08f2('0xd')]);MailInteractionEvents[_0x08f2('0xe')](_0x431579+':'+_0x5cd86e['id'],_0x5cd86e);MailInteractionEvents[_0x08f2('0xe')](_0x431579,_0x5cd86e);_0x3fb6f3(null);})[_0x08f2('0xf')](_0x3fb6f3(null));};}for(var e in events){if(events[_0x08f2('0x10')](e)){var event=events[e];MailInteraction['hook'](e,emitEvent(event));}}module['exports']=MailInteractionEvents;