36d28a534402853dc41f6c933a58aa89f33ab9ab
[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 _0xe55d=['then','setDataValue','map','findAll','unreadMessages','emit','hasOwnProperty','hook','exports','../../mysqldb','MailInteraction','MailMessage','save','remove','getUsers'];(function(_0x3141f8,_0xc7e547){var _0x5b3d1f=function(_0x493866){while(--_0x493866){_0x3141f8['push'](_0x3141f8['shift']());}};_0x5b3d1f(++_0xc7e547);}(_0xe55d,0x81));var _0xde55=function(_0x1b1211,_0x25a3ec){_0x1b1211=_0x1b1211-0x0;var _0x458eea=_0xe55d[_0x1b1211];return _0x458eea;};'use strict';var EventEmitter=require('events');var MailInteraction=require(_0xde55('0x0'))['db'][_0xde55('0x1')];var MailMessage=require(_0xde55('0x0'))['db'][_0xde55('0x2')];var MailInteractionEvents=new EventEmitter();MailInteractionEvents['setMaxListeners'](0x0);var events={'afterCreate':_0xde55('0x3'),'afterUpdate':'update','afterDestroy':_0xde55('0x4')};function emitEvent(_0x3097a3){return function(_0x48b6ab,_0x5b7168,_0x1b5471){_0x48b6ab[_0xde55('0x5')]({'attributes':['id'],'raw':!![]})[_0xde55('0x6')](function(_0x5c0382){_0x48b6ab[_0xde55('0x7')]('Users',_0x5c0382[_0xde55('0x8')](function(_0x4bc355){return{'id':_0x4bc355['id']};}));return MailMessage[_0xde55('0x9')]({'where':{'MailInteractionId':_0x48b6ab['id'],'direction':'in','read':![]},'raw':!![]});})[_0xde55('0x6')](function(_0x2141c1){_0x48b6ab[_0xde55('0x7')](_0xde55('0xa'),_0x2141c1['length']);MailInteractionEvents[_0xde55('0xb')](_0x3097a3+':'+_0x48b6ab['id'],_0x48b6ab);MailInteractionEvents[_0xde55('0xb')](_0x3097a3,_0x48b6ab);_0x1b5471(null);})['catch'](_0x1b5471(null));};}for(var e in events){if(events[_0xde55('0xc')](e)){var event=events[e];MailInteraction[_0xde55('0xd')](e,emitEvent(event));}}module[_0xde55('0xe')]=MailInteractionEvents;