handle UPDATE in GUILD_MEMBER_LIST_UPDATE

This commit is contained in:
ouwou 2021-02-28 01:44:31 -05:00
parent e81fdf1c36
commit 11358da24e
3 changed files with 19 additions and 6 deletions

View File

@ -1303,7 +1303,7 @@ void DiscordClient::HandleGatewayGuildMemberListUpdate(const GatewayMessage &msg
for (const auto &op : data.Ops) {
if (op.Op == "SYNC") {
has_sync = true;
for (const auto &item : op.Items) {
for (const auto &item : *op.Items) {
if (item->Type == "member") {
auto member = static_cast<const GuildMemberListUpdateMessage::MemberItem *>(item.get());
m_store.SetUser(member->User.ID, member->User);
@ -1322,6 +1322,12 @@ void DiscordClient::HandleGatewayGuildMemberListUpdate(const GatewayMessage &msg
}
}
}
} else if (op.Op == "UPDATE") {
if (op.OpItem.has_value() && op.OpItem.value()->Type == "member") {
const auto &m = static_cast<const GuildMemberListUpdateMessage::MemberItem *>(op.OpItem.value().get())->GetAsMemberData();
m_store.SetGuildMember(data.GuildID, m.User->ID, m);
m_signal_guild_member_update.emit(data.GuildID, m.User->ID); // cheeky
}
}
}

View File

@ -51,13 +51,19 @@ void from_json(const nlohmann::json &j, GuildMemberListUpdateMessage::MemberItem
void from_json(const nlohmann::json &j, GuildMemberListUpdateMessage::OpObject &m) {
JS_D("op", m.Op);
if (m.Op == "SYNC") {
m.Items.emplace();
JS_D("range", m.Range);
for (const auto &ij : j.at("items")) {
if (ij.contains("group"))
m.Items.push_back(std::make_unique<GuildMemberListUpdateMessage::GroupItem>(ij.at("group")));
m.Items->push_back(std::make_unique<GuildMemberListUpdateMessage::GroupItem>(ij.at("group")));
else if (ij.contains("member"))
m.Items.push_back(std::make_unique<GuildMemberListUpdateMessage::MemberItem>(ij.at("member")));
m.Items->push_back(std::make_unique<GuildMemberListUpdateMessage::MemberItem>(ij.at("member")));
}
} else if (m.Op == "UPDATE") {
JS_D("index", m.Index);
const auto &ij = j.at("item");
if (ij.contains("member"))
m.OpItem = std::make_unique<GuildMemberListUpdateMessage::MemberItem>(ij.at("member"));
}
}

View File

@ -152,9 +152,10 @@ struct GuildMemberListUpdateMessage {
struct OpObject {
std::string Op;
int Index;
std::vector<std::unique_ptr<Item>> Items; // SYNC
std::pair<int, int> Range; // SYNC
std::optional<int> Index;
std::optional<std::vector<std::unique_ptr<Item>>> Items; // SYNC
std::optional<std::pair<int, int>> Range; // SYNC
std::optional<std::unique_ptr<Item>> OpItem; // UPDATE
friend void from_json(const nlohmann::json &j, OpObject &m);
};