-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathFriendsViewModel.cpp
More file actions
129 lines (118 loc) · 2.59 KB
/
Copy pathFriendsViewModel.cpp
File metadata and controls
129 lines (118 loc) · 2.59 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
#include "FriendsViewModel.h"
#include "ViewModel.h"
#include "stormancer/IClientFactory.h"
#include "friends/Friends.hpp"
FriendsViewModel::FriendsViewModel(ClientViewModel* parent)
{
this->parent = parent;
}
std::shared_ptr<Stormancer::Friends::FriendsApi> FriendsViewModel::getFriendsApi()
{
auto client = Stormancer::IClientFactory::GetClient(parent->id);
return client->dependencyResolver().resolve<Stormancer::Friends::FriendsApi>();
}
void FriendsViewModel::initialize()
{
auto friendsApi = getFriendsApi();
subscription = friendsApi->subscribeFriendListUpdatedEvent([this](Stormancer::Friends::FriendListUpdatedEvent evt) {
});
}
Stormancer::Friends::FriendsResult FriendsViewModel::getFriends()
{
auto friendsApi = getFriendsApi();
return friendsApi->friends();
}
void FriendsViewModel::AnswerFriendRequest(const Stormancer::Users::UserId& userId, bool accept)
{
auto friendsApi = getFriendsApi();
if (friendsApi->isLoaded())
{
friendsApi->answerFriendInvitation(userId, accept)
.then([this](pplx::task<void> t) {
try
{
t.get();
}
catch (std::exception& ex)
{
this->parent->lastError = ex.what();
}
});
}
}
void FriendsViewModel::UnblockUser(const Stormancer::Users::UserId& userId)
{
auto friendsApi = getFriendsApi();
if (friendsApi->isLoaded())
{
friendsApi->unblock(userId)
.then([this](pplx::task<void> t) {
try
{
t.get();
}
catch (std::exception& ex)
{
this->parent->lastError = ex.what();
}
});
}
}
void FriendsViewModel::AddFriend(const Stormancer::Users::UserId& userId)
{
auto friendsApi = getFriendsApi();
if (friendsApi->isLoaded())
{
friendsApi->inviteFriend(userId)
.then([this](pplx::task<void> t) {
try
{
t.get();
}
catch (std::exception& ex)
{
this->parent->lastError = ex.what();
}
});
}
}
void FriendsViewModel::BlockUser(const Stormancer::Users::UserId& userId)
{
auto friendsApi = getFriendsApi();
if (friendsApi->isLoaded())
{
friendsApi->block(userId)
.then([this](pplx::task<void> t) {
try
{
t.get();
}
catch (std::exception& ex)
{
this->parent->lastError = ex.what();
}
});
}
}
void FriendsViewModel::RemoveFriend(const Stormancer::Users::UserId& userId)
{
auto friendsApi = getFriendsApi();
if (friendsApi->isLoaded())
{
friendsApi->removeFriend(userId)
.then([this](pplx::task<void> t) {
try
{
t.get();
}
catch (std::exception& ex)
{
this->parent->lastError = ex.what();
}
});
}
}
void FriendsViewModel::InvitePlayer(const Stormancer::Users::UserId& userId)
{
parent->party.InvitePlayerToParty(userId);
}