scroll up to load more messages

This commit is contained in:
ouwou
2020-08-28 18:21:08 -04:00
parent 8699a547f3
commit 5b7d36bb74
10 changed files with 121 additions and 8 deletions

View File

@@ -129,6 +129,18 @@ void DiscordClient::FetchMessagesInChannel(Snowflake id, std::function<void(cons
});
}
void DiscordClient::FetchMessagesInChannelBefore(Snowflake channel_id, Snowflake before_id, std::function<void(const std::vector<MessageData> &)> 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;
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);
}