CHANNEL_RECIPIENT_ADD, CHANNEL_RECIPIENT_REMOVE

This commit is contained in:
ouwou 2020-12-22 23:52:41 -05:00
parent cb18543c50
commit dbd8564af7
4 changed files with 55 additions and 0 deletions

View File

@ -584,6 +584,12 @@ void DiscordClient::HandleGatewayMessage(std::string str) {
case GatewayEvent::MESSAGE_REACTION_REMOVE: {
HandleGatewayMessageReactionRemove(m);
} break;
case GatewayEvent::CHANNEL_RECIPIENT_ADD: {
HandleGatewayChannelRecipientAdd(m);
} break;
case GatewayEvent::CHANNEL_RECIPIENT_REMOVE: {
HandleGatewayChannelRecipientRemove(m);
} break;
}
} break;
default:
@ -845,6 +851,25 @@ void DiscordClient::HandleGatewayMessageReactionRemove(const GatewayMessage &msg
m_signal_reaction_remove.emit(data.MessageID, std::to_string(data.Emoji.ID));
}
// todo: update channel list item and member list
void DiscordClient::HandleGatewayChannelRecipientAdd(const GatewayMessage &msg) {
ChannelRecipientAdd data = msg.Data;
auto cur = m_store.GetChannel(data.ChannelID);
if (!cur.has_value() || !cur->RecipientIDs.has_value()) return;
if (std::find(cur->RecipientIDs->begin(), cur->RecipientIDs->end(), data.User.ID) == cur->RecipientIDs->end())
cur->RecipientIDs->push_back(data.User.ID);
m_store.SetUser(data.User.ID, data.User);
m_store.SetChannel(cur->ID, *cur);
}
void DiscordClient::HandleGatewayChannelRecipientRemove(const GatewayMessage &msg) {
ChannelRecipientRemove data = msg.Data;
auto cur = m_store.GetChannel(data.ChannelID);
if (!cur.has_value() || !cur->RecipientIDs.has_value()) return;
cur->RecipientIDs->erase(std::remove(cur->RecipientIDs->begin(), cur->RecipientIDs->end(), data.User.ID));
m_store.SetChannel(cur->ID, *cur);
}
void DiscordClient::HandleGatewayReconnect(const GatewayMessage &msg) {
m_signal_disconnected.emit(true);
inflateEnd(&m_zstream);
@ -1055,6 +1080,8 @@ void DiscordClient::LoadEventMap() {
m_event_map["GUILD_ROLE_DELETE"] = GatewayEvent::GUILD_ROLE_DELETE;
m_event_map["MESSAGE_REACTION_ADD"] = GatewayEvent::MESSAGE_REACTION_ADD;
m_event_map["MESSAGE_REACTION_REMOVE"] = GatewayEvent::MESSAGE_REACTION_REMOVE;
m_event_map["CHANNEL_RECIPIENT_ADD"] = GatewayEvent::CHANNEL_RECIPIENT_ADD;
m_event_map["CHANNEL_RECIPIENT_REMOVE"] = GatewayEvent::CHANNEL_RECIPIENT_REMOVE;
}
DiscordClient::type_signal_gateway_ready DiscordClient::signal_gateway_ready() {

View File

@ -144,6 +144,8 @@ private:
void HandleGatewayGuildRoleDelete(const GatewayMessage &msg);
void HandleGatewayMessageReactionAdd(const GatewayMessage &msg);
void HandleGatewayMessageReactionRemove(const GatewayMessage &msg);
void HandleGatewayChannelRecipientAdd(const GatewayMessage &msg);
void HandleGatewayChannelRecipientRemove(const GatewayMessage &msg);
void HandleGatewayReconnect(const GatewayMessage &msg);
void HeartbeatThread();
void SendIdentify();

View File

@ -229,3 +229,13 @@ void from_json(const nlohmann::json &j, MessageReactionRemoveObject &m) {
JS_O("guild_id", m.GuildID);
JS_D("emoji", m.Emoji);
}
void from_json(const nlohmann::json &j, ChannelRecipientAdd &m) {
JS_D("user", m.User);
JS_D("channel_id", m.ChannelID);
}
void from_json(const nlohmann::json &j, ChannelRecipientRemove &m) {
JS_D("user", m.User);
JS_D("channel_id", m.ChannelID);
}

View File

@ -51,6 +51,8 @@ enum class GatewayEvent : int {
GUILD_ROLE_DELETE,
MESSAGE_REACTION_ADD,
MESSAGE_REACTION_REMOVE,
CHANNEL_RECIPIENT_ADD,
CHANNEL_RECIPIENT_REMOVE,
};
struct GatewayMessage {
@ -318,3 +320,17 @@ struct MessageReactionRemoveObject {
friend void from_json(const nlohmann::json &j, MessageReactionRemoveObject &m);
};
struct ChannelRecipientAdd {
User User;
Snowflake ChannelID;
friend void from_json(const nlohmann::json &j, ChannelRecipientAdd &m);
};
struct ChannelRecipientRemove {
User User;
Snowflake ChannelID;
friend void from_json(const nlohmann::json &j, ChannelRecipientRemove &m);
};