Built motion from commit (unavailable).|2.5.24
[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 _0xd0ef=['emit','catch','events','../../mysqldb','MailInteraction','MailMessage','setMaxListeners','save','update','getUsers','then','setDataValue','map','length'];(function(_0x122ef9,_0x451d2a){var _0x42fba0=function(_0x17c9d3){while(--_0x17c9d3){_0x122ef9['push'](_0x122ef9['shift']());}};_0x42fba0(++_0x451d2a);}(_0xd0ef,0x160));var _0xfd0e=function(_0x432233,_0x390b5e){_0x432233=_0x432233-0x0;var _0xb14fb0=_0xd0ef[_0x432233];return _0xb14fb0;};'use strict';var EventEmitter=require(_0xfd0e('0x0'));var MailInteraction=require(_0xfd0e('0x1'))['db'][_0xfd0e('0x2')];var MailMessage=require('../../mysqldb')['db'][_0xfd0e('0x3')];var MailInteractionEvents=new EventEmitter();MailInteractionEvents[_0xfd0e('0x4')](0x0);var events={'afterCreate':_0xfd0e('0x5'),'afterUpdate':_0xfd0e('0x6'),'afterDestroy':'remove'};function emitEvent(_0x2af543){return function(_0x1c68c0,_0x99bcb9,_0xd9d61c){_0x1c68c0[_0xfd0e('0x7')]({'attributes':['id'],'raw':!![]})[_0xfd0e('0x8')](function(_0x3fd27a){_0x1c68c0[_0xfd0e('0x9')]('Users',_0x3fd27a[_0xfd0e('0xa')](function(_0x52899e){return{'id':_0x52899e['id']};}));return MailMessage['findAll']({'where':{'MailInteractionId':_0x1c68c0['id'],'direction':'in','read':![]},'raw':!![]});})['then'](function(_0x5e26c1){_0x1c68c0[_0xfd0e('0x9')]('unreadMessages',_0x5e26c1[_0xfd0e('0xb')]);MailInteractionEvents[_0xfd0e('0xc')](_0x2af543+':'+_0x1c68c0['id'],_0x1c68c0);MailInteractionEvents[_0xfd0e('0xc')](_0x2af543,_0x1c68c0);_0xd9d61c(null);})[_0xfd0e('0xd')](_0xd9d61c(null));};}for(var e in events){if(events['hasOwnProperty'](e)){var event=events[e];MailInteraction['hook'](e,emitEvent(event));}}module['exports']=MailInteractionEvents;