summaryrefslogtreecommitdiff
path: root/discord/discord.cpp
diff options
context:
space:
mode:
authorouwou <26526779+ouwou@users.noreply.github.com>2020-09-04 00:48:38 -0400
committerouwou <26526779+ouwou@users.noreply.github.com>2020-09-04 00:48:38 -0400
commitf69b0e61558680d9fdcaafd5c184b2c45fc06fce (patch)
tree87499f456700f365eb04cb19772f75f08eed614b /discord/discord.cpp
parent6c04a0a86d832217dc6d08652430cd84b09ff1db (diff)
downloadabaddon-portaudio-f69b0e61558680d9fdcaafd5c184b2c45fc06fce.tar.gz
abaddon-portaudio-f69b0e61558680d9fdcaafd5c184b2c45fc06fce.zip
pass around snowflake instead of MessageData
Diffstat (limited to 'discord/discord.cpp')
-rw-r--r--discord/discord.cpp31
1 files changed, 22 insertions, 9 deletions
diff --git a/discord/discord.cpp b/discord/discord.cpp
index f04c136..ed919df 100644
--- a/discord/discord.cpp
+++ b/discord/discord.cpp
@@ -110,11 +110,16 @@ std::vector<std::pair<Snowflake, GuildData>> DiscordClient::GetUserSortedGuilds(
return sorted_guilds;
}
-std::unordered_set<const MessageData *> DiscordClient::GetMessagesForChannel(Snowflake id) const {
+std::set<Snowflake> DiscordClient::GetMessagesForChannel(Snowflake id) const {
auto it = m_chan_to_message_map.find(id);
if (it == m_chan_to_message_map.end())
- return std::unordered_set<const MessageData *>();
- return it->second;
+ return std::set<Snowflake>();
+
+ std::set<Snowflake> ret;
+ for (const auto &msg : it->second)
+ ret.insert(msg->ID);
+
+ return ret;
}
void DiscordClient::UpdateSettingsGuildPositions(const std::vector<Snowflake> &pos) {
@@ -127,27 +132,35 @@ void DiscordClient::UpdateSettingsGuildPositions(const std::vector<Snowflake> &p
});
}
-void DiscordClient::FetchMessagesInChannel(Snowflake id, std::function<void(const std::vector<MessageData> &)> cb) {
+void DiscordClient::FetchMessagesInChannel(Snowflake id, std::function<void(const std::vector<Snowflake> &)> cb) {
std::string path = "/channels/" + std::to_string(id) + "/messages?limit=50";
m_http.MakeGET(path, [this, id, cb](cpr::Response r) {
std::vector<MessageData> msgs;
+ std::vector<Snowflake> ids;
+
nlohmann::json::parse(r.text).get_to(msgs);
- for (const auto &msg : msgs)
+ for (const auto &msg : msgs) {
StoreMessage(msg.ID, msg);
+ ids.push_back(msg.ID);
+ }
- cb(msgs);
+ cb(ids);
});
}
-void DiscordClient::FetchMessagesInChannelBefore(Snowflake channel_id, Snowflake before_id, std::function<void(const std::vector<MessageData> &)> cb) {
+void DiscordClient::FetchMessagesInChannelBefore(Snowflake channel_id, Snowflake before_id, std::function<void(const std::vector<Snowflake> &)> cb) {
std::string path = "/channels/" + std::to_string(channel_id) + "/messages?limit=50&before=" + std::to_string(before_id);
m_http.MakeGET(path, [this, channel_id, cb](cpr::Response r) {
std::vector<MessageData> msgs;
+ std::vector<Snowflake> ids;
+
nlohmann::json::parse(r.text).get_to(msgs);
- for (const auto &msg : msgs)
+ for (const auto &msg : msgs) {
StoreMessage(msg.ID, msg);
+ ids.push_back(msg.ID);
+ }
- cb(msgs);
+ cb(ids);
});
}