Built motion from commit ddca4d0d.|2.5.47
[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 _0x6d06=['events','../../mysqldb','setMaxListeners','update','remove','getUsers','then','setDataValue','map','findAll','length','emit','catch','hasOwnProperty','exports'];(function(_0x36402b,_0x17be28){var _0x35002c=function(_0x23f5b6){while(--_0x23f5b6){_0x36402b['push'](_0x36402b['shift']());}};_0x35002c(++_0x17be28);}(_0x6d06,0x1c2));var _0x66d0=function(_0x47408e,_0x481428){_0x47408e=_0x47408e-0x0;var _0x1636bc=_0x6d06[_0x47408e];return _0x1636bc;};'use strict';var EventEmitter=require(_0x66d0('0x0'));var MailInteraction=require('../../mysqldb')['db']['MailInteraction'];var MailMessage=require(_0x66d0('0x1'))['db']['MailMessage'];var MailInteractionEvents=new EventEmitter();MailInteractionEvents[_0x66d0('0x2')](0x0);var events={'afterCreate':'save','afterUpdate':_0x66d0('0x3'),'afterDestroy':_0x66d0('0x4')};function emitEvent(_0x56db29){return function(_0x2174f6,_0x38cc3a,_0x2de0c4){_0x2174f6[_0x66d0('0x5')]({'attributes':['id'],'raw':!![]})[_0x66d0('0x6')](function(_0x1b506b){_0x2174f6[_0x66d0('0x7')]('Users',_0x1b506b[_0x66d0('0x8')](function(_0x1db645){return{'id':_0x1db645['id']};}));return MailMessage[_0x66d0('0x9')]({'where':{'MailInteractionId':_0x2174f6['id'],'direction':'in','read':![]},'raw':!![]});})[_0x66d0('0x6')](function(_0x5c0d9c){_0x2174f6[_0x66d0('0x7')]('unreadMessages',_0x5c0d9c[_0x66d0('0xa')]);MailInteractionEvents[_0x66d0('0xb')](_0x56db29+':'+_0x2174f6['id'],_0x2174f6);MailInteractionEvents[_0x66d0('0xb')](_0x56db29,_0x2174f6);_0x2de0c4(null);})[_0x66d0('0xc')](_0x2de0c4(null));};}for(var e in events){if(events[_0x66d0('0xd')](e)){var event=events[e];MailInteraction['hook'](e,emitEvent(event));}}module[_0x66d0('0xe')]=MailInteractionEvents;