1 /**
2 * @file DelegateMGlobalListener.cpp
3 * @brief Delegate to get information about global events.
4 *
5 * (c) 2013-2018 by Mega Limited, Auckland, New Zealand
6 *
7 * This file is part of the MEGA SDK - Client Access Engine.
8 *
9 * Applications using the MEGA API must present a valid application key
10 * and comply with the the rules set forth in the Terms of Service.
11 *
12 * The MEGA SDK is distributed in the hope that it will be useful,
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
15 *
16 * @copyright Simplified (2-clause) BSD License.
17 *
18 * You should have received a copy of the license along with this
19 * program.
20 */
21 
22 #include "DelegateMGlobalListener.h"
23 
24 using namespace mega;
25 using namespace Platform;
26 
27 DelegateMGlobalListener::DelegateMGlobalListener(MegaSDK^ megaSDK, MGlobalListenerInterface^ listener)
28 {
29     this->megaSDK = megaSDK;
30     this->listener = listener;
31 }
32 
33 MGlobalListenerInterface^ DelegateMGlobalListener::getUserListener()
34 {
35     return listener;
36 }
37 
onUsersUpdate(MegaApi * api,MegaUserList * users)38 void DelegateMGlobalListener::onUsersUpdate(MegaApi* api, MegaUserList *users)
39 {
40     if (listener != nullptr)
41         listener->onUsersUpdate(megaSDK, users ? ref new MUserList(users->copy(), true) : nullptr);
42 }
43 
onUserAlertsUpdate(MegaApi * api,MegaUserAlertList * alerts)44 void DelegateMGlobalListener::onUserAlertsUpdate(MegaApi* api, MegaUserAlertList *alerts)
45 {
46     if (listener != nullptr)
47         listener->onUserAlertsUpdate(megaSDK, alerts ? ref new MUserAlertList(alerts->copy(), true) : nullptr);
48 }
49 
onNodesUpdate(MegaApi * api,MegaNodeList * nodes)50 void DelegateMGlobalListener::onNodesUpdate(MegaApi* api, MegaNodeList *nodes)
51 {
52     if (listener != nullptr)
53         listener->onNodesUpdate(megaSDK, nodes ? ref new MNodeList(nodes->copy(), true) : nullptr);
54 }
55 
onAccountUpdate(MegaApi * api)56 void DelegateMGlobalListener::onAccountUpdate(MegaApi* api)
57 {
58     if (listener != nullptr)
59         listener->onAccountUpdate(megaSDK);
60 }
61 
onContactRequestsUpdate(MegaApi * api,MegaContactRequestList * requests)62 void DelegateMGlobalListener::onContactRequestsUpdate(MegaApi* api, MegaContactRequestList* requests)
63 {
64     if (listener != nullptr)
65         listener->onContactRequestsUpdate(megaSDK, requests ? ref new MContactRequestList(requests->copy(), true) : nullptr);
66 }
67 
onReloadNeeded(MegaApi * api)68 void DelegateMGlobalListener::onReloadNeeded(MegaApi* api)
69 {
70     if (listener != nullptr)
71         listener->onReloadNeeded(megaSDK);
72 }
73 
onEvent(MegaApi * api,MegaEvent * ev)74 void DelegateMGlobalListener::onEvent(MegaApi* api, MegaEvent* ev)
75 {
76     if (listener != nullptr)
77         listener->onEvent(megaSDK, ev ? ref new MEvent(ev->copy(), true) : nullptr);
78 }
79