summaryrefslogtreecommitdiff
path: root/src/discord/invite.cpp
blob: 63043a10b1100f616934b92af107153e67a00774 (plain)
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
#include "invite.hpp"

void from_json(const nlohmann::json &j, InviteChannelData &m) {
    JS_D("id", m.ID);
    JS_D("type", m.Type);
    JS_ON("name", m.Name);
    if (j.contains("recipients") && j.at("recipients").is_null()) {
        m.RecipientUsernames.emplace();
        for (const auto &x : j.at("recipients"))
            m.RecipientUsernames->push_back(x.at("username").get<std::string>());
    }
}

void from_json(const nlohmann::json &j, InviteData &m) {
    JS_D("code", m.Code);
    JS_O("guild", m.Guild);
    JS_O("channel", m.Channel);
    JS_O("inviter", m.Inviter);
    JS_O("target_user", m.TargetUser);
    JS_O("target_user_type", m.TargetUserType);
    JS_O("approximate_presence_count", m.PresenceCount);
    JS_O("approximate_member_count", m.MemberCount);
    JS_O("uses", m.Uses);
    JS_O("max_uses", m.MaxUses);
    JS_O("max_age", m.MaxAge);
    JS_O("temporary", m.IsTemporary);
    JS_O("created_at", m.CreatedAt);
}

InviteChannelData::InviteChannelData(const ChannelData &c) {
    ID = c.ID;
    Type = c.Type;
    Name = c.Name;
    if (Type == ChannelType::GROUP_DM) {
        RecipientUsernames.emplace();
        for (const auto &r : c.GetDMRecipients())
            RecipientUsernames->push_back(r.Username);
    }
}