forked from dedis/Dissent
-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathBuddiesService.cpp
45 lines (39 loc) · 1.12 KB
/
BuddiesService.cpp
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
#include "Anonymity/Round.hpp"
#include "Anonymity/Buddies/BuddyMonitor.hpp"
#include "BuddiesService.hpp"
namespace Dissent {
namespace Web {
BuddiesService::BuddiesService(SessionManager &sm) :
SessionService(sm)
{
}
void BuddiesService::HandleRequest(QHttpRequest *,
QHttpResponse *response)
{
QSharedPointer<Session> session = GetSession();
QVariantHash data;
bool session_active = !session.isNull();
data["buddies"] = false;
if(session_active) {
QSharedPointer<Anonymity::Round> round =
session->GetCurrentRound();
if(round) {
QSharedPointer<BuddyMonitor> bm = round->GetBuddyMonitor();
if(bm) {
data["buddies"] = true;
QVariantList members;
QVariantList pseudonyms;
for(int idx = 0; idx < bm->GetCount(); idx++) {
members.append(bm->GetMemberAnonymity(idx));
pseudonyms.append(bm->GetNymAnonymity(idx));
}
QVariantHash result;
data["members"] = members;
data["nyms"] = pseudonyms;
}
}
}
SendJsonResponse(response, data);
}
}
}