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 --- abaddon.cpp | 29 +++++++++++++++++++++++++++-- 1 file changed, 27 insertions(+), 2 deletions(-) (limited to 'abaddon.cpp') diff --git a/abaddon.cpp b/abaddon.cpp index 04d80ac..48ba1fd 100644 --- a/abaddon.cpp +++ b/abaddon.cpp @@ -121,7 +121,7 @@ void Abaddon::ActionMoveGuildUp(Snowflake id) { std::swap(*left, *target_iter); std::vector new_sort; - for (const auto& x : order) + for (const auto &x : order) new_sort.push_back(x.first); m_discord.UpdateSettingsGuildPositions(new_sort); @@ -156,14 +156,39 @@ void Abaddon::ActionListChannelItemClick(Snowflake id) { m_main_window->UpdateChatActiveChannel(id); if (m_channels_requested.find(id) == m_channels_requested.end()) { m_discord.FetchMessagesInChannel(id, [this, id](const std::vector &msgs) { + if (msgs.size() > 0) { + m_oldest_listed_message[id] = msgs.back().ID; + m_main_window->UpdateChatWindowContents(); + } + m_channels_requested.insert(id); - m_main_window->UpdateChatWindowContents(); }); } else { m_main_window->UpdateChatWindowContents(); } } +void Abaddon::ActionChatLoadHistory(Snowflake id) { + if (m_channels_history_loaded.find(id) != m_channels_history_loaded.end()) + return; + + if (m_channels_history_loading.find(id) != m_channels_history_loading.end()) + return; + + m_channels_history_loading.insert(id); + + m_discord.FetchMessagesInChannelBefore(id, m_oldest_listed_message[id], [this, id](const std::vector &msgs) { + m_channels_history_loading.erase(id); + + if (msgs.size() == 0) { + m_channels_history_loaded.insert(id); + } else { + m_oldest_listed_message[id] = msgs.back().ID; + m_main_window->UpdateChatPrependHistory(msgs); + } + }); +} + void Abaddon::ActionChatInputSubmit(std::string msg, Snowflake channel) { m_discord.SendChatMessage(msg, channel); } -- cgit v1.2.3