Built motion from commit 06eb8eb0.|2.6.31
[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 _0x2f65=['unreadMessages','emit','hasOwnProperty','hook','exports','events','../../mysqldb','MailInteraction','MailMessage','update','remove','getUsers','then','map'];(function(_0x1c76e4,_0x700b6a){var _0x117e4e=function(_0x4b8836){while(--_0x4b8836){_0x1c76e4['push'](_0x1c76e4['shift']());}};_0x117e4e(++_0x700b6a);}(_0x2f65,0xf3));var _0x52f6=function(_0x46ad00,_0x4a1e49){_0x46ad00=_0x46ad00-0x0;var _0x54736b=_0x2f65[_0x46ad00];return _0x54736b;};'use strict';var EventEmitter=require(_0x52f6('0x0'));var MailInteraction=require(_0x52f6('0x1'))['db'][_0x52f6('0x2')];var MailMessage=require(_0x52f6('0x1'))['db'][_0x52f6('0x3')];var MailInteractionEvents=new EventEmitter();MailInteractionEvents['setMaxListeners'](0x0);var events={'afterCreate':'save','afterUpdate':_0x52f6('0x4'),'afterDestroy':_0x52f6('0x5')};function emitEvent(_0xa6aa1){return function(_0x285cae,_0x2c27b8,_0x199e5d){_0x285cae[_0x52f6('0x6')]({'attributes':['id'],'raw':!![]})[_0x52f6('0x7')](function(_0x4643ec){_0x285cae['setDataValue']('Users',_0x4643ec[_0x52f6('0x8')](function(_0x4e134f){return{'id':_0x4e134f['id']};}));return MailMessage['findAll']({'where':{'MailInteractionId':_0x285cae['id'],'direction':'in','read':![]},'raw':!![]});})[_0x52f6('0x7')](function(_0x4cce33){_0x285cae['setDataValue'](_0x52f6('0x9'),_0x4cce33['length']);MailInteractionEvents[_0x52f6('0xa')](_0xa6aa1+':'+_0x285cae['id'],_0x285cae);MailInteractionEvents[_0x52f6('0xa')](_0xa6aa1,_0x285cae);_0x199e5d(null);})['catch'](_0x199e5d(null));};}for(var e in events){if(events[_0x52f6('0xb')](e)){var event=events[e];MailInteraction[_0x52f6('0xc')](e,emitEvent(event));}}module[_0x52f6('0xd')]=MailInteractionEvents;