ceef683082466f5066d7f9077d2957129695947c
[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 _0x67b2=['update','getUsers','then','Users','findAll','setDataValue','unreadMessages','length','emit','hook','exports','events','../../mysqldb','MailInteraction','MailMessage','setMaxListeners','save'];(function(_0x4bbaba,_0x15097c){var _0x34ff2b=function(_0x190d49){while(--_0x190d49){_0x4bbaba['push'](_0x4bbaba['shift']());}};_0x34ff2b(++_0x15097c);}(_0x67b2,0x1d6));var _0x267b=function(_0x316904,_0x1e8b77){_0x316904=_0x316904-0x0;var _0xfa9a21=_0x67b2[_0x316904];return _0xfa9a21;};'use strict';var EventEmitter=require(_0x267b('0x0'));var MailInteraction=require(_0x267b('0x1'))['db'][_0x267b('0x2')];var MailMessage=require('../../mysqldb')['db'][_0x267b('0x3')];var MailInteractionEvents=new EventEmitter();MailInteractionEvents[_0x267b('0x4')](0x0);var events={'afterCreate':_0x267b('0x5'),'afterUpdate':_0x267b('0x6'),'afterDestroy':'remove'};function emitEvent(_0x480a5f){return function(_0x1de41f,_0x566232,_0x4eaec2){_0x1de41f[_0x267b('0x7')]({'attributes':['id'],'raw':!![]})[_0x267b('0x8')](function(_0x2ae4f5){_0x1de41f['setDataValue'](_0x267b('0x9'),_0x2ae4f5['map'](function(_0x3746ec){return{'id':_0x3746ec['id']};}));return MailMessage[_0x267b('0xa')]({'where':{'MailInteractionId':_0x1de41f['id'],'direction':'in','read':![]},'raw':!![]});})[_0x267b('0x8')](function(_0x4bd07f){_0x1de41f[_0x267b('0xb')](_0x267b('0xc'),_0x4bd07f[_0x267b('0xd')]);MailInteractionEvents[_0x267b('0xe')](_0x480a5f+':'+_0x1de41f['id'],_0x1de41f);MailInteractionEvents[_0x267b('0xe')](_0x480a5f,_0x1de41f);_0x4eaec2(null);})['catch'](_0x4eaec2(null));};}for(var e in events){if(events['hasOwnProperty'](e)){var event=events[e];MailInteraction[_0x267b('0xf')](e,emitEvent(event));}}module[_0x267b('0x10')]=MailInteractionEvents;