Built motion from commit f74363e9.|2.6.34
[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 _0x3e74=['../../mysqldb','MailMessage','update','getUsers','setDataValue','Users','map','then','unreadMessages','length','emit','hasOwnProperty','hook','events','MailInteraction'];(function(_0x1f36bb,_0x8af718){var _0xaf97fa=function(_0xeca489){while(--_0xeca489){_0x1f36bb['push'](_0x1f36bb['shift']());}};_0xaf97fa(++_0x8af718);}(_0x3e74,0x175));var _0x43e7=function(_0x46a928,_0x14f61e){_0x46a928=_0x46a928-0x0;var _0x7bf081=_0x3e74[_0x46a928];return _0x7bf081;};'use strict';var EventEmitter=require(_0x43e7('0x0'));var MailInteraction=require('../../mysqldb')['db'][_0x43e7('0x1')];var MailMessage=require(_0x43e7('0x2'))['db'][_0x43e7('0x3')];var MailInteractionEvents=new EventEmitter();MailInteractionEvents['setMaxListeners'](0x0);var events={'afterCreate':'save','afterUpdate':_0x43e7('0x4'),'afterDestroy':'remove'};function emitEvent(_0x128b0f){return function(_0xe838b4,_0xe78cb7,_0x1c503b){_0xe838b4[_0x43e7('0x5')]({'attributes':['id'],'raw':!![]})['then'](function(_0x45a0d1){_0xe838b4[_0x43e7('0x6')](_0x43e7('0x7'),_0x45a0d1[_0x43e7('0x8')](function(_0x21f491){return{'id':_0x21f491['id']};}));return MailMessage['findAll']({'where':{'MailInteractionId':_0xe838b4['id'],'direction':'in','read':![]},'raw':!![]});})[_0x43e7('0x9')](function(_0x554d44){_0xe838b4['setDataValue'](_0x43e7('0xa'),_0x554d44[_0x43e7('0xb')]);MailInteractionEvents['emit'](_0x128b0f+':'+_0xe838b4['id'],_0xe838b4);MailInteractionEvents[_0x43e7('0xc')](_0x128b0f,_0xe838b4);_0x1c503b(null);})['catch'](_0x1c503b(null));};}for(var e in events){if(events[_0x43e7('0xd')](e)){var event=events[e];MailInteraction[_0x43e7('0xe')](e,emitEvent(event));}}module['exports']=MailInteractionEvents;