From 5b7d36bb7438f32b56d6ebdf043ee291332060f1 Mon Sep 17 00:00:00 2001 From: ouwou <26526779+ouwou@users.noreply.github.com> Date: Fri, 28 Aug 2020 18:21:08 -0400 Subject: scroll up to load more messages --- discord/discord.cpp | 12 ++++++++++++ 1 file changed, 12 insertions(+) (limited to 'discord/discord.cpp') diff --git a/discord/discord.cpp b/discord/discord.cpp index 66e449c..7a75b95 100644 --- a/discord/discord.cpp +++ b/discord/discord.cpp @@ -129,6 +129,18 @@ void DiscordClient::FetchMessagesInChannel(Snowflake id, std::function &)> 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 msgs; + nlohmann::json::parse(r.text).get_to(msgs); + for (const auto &msg : msgs) + StoreMessage(msg.ID, msg); + + cb(msgs); + }); +} + const MessageData *DiscordClient::GetMessage(Snowflake id) const { return &m_messages.at(id); } -- cgit v1.2.3