diff options
author | ouwou <26526779+ouwou@users.noreply.github.com> | 2020-08-28 18:21:08 -0400 |
---|---|---|
committer | ouwou <26526779+ouwou@users.noreply.github.com> | 2020-08-28 18:21:08 -0400 |
commit | 5b7d36bb7438f32b56d6ebdf043ee291332060f1 (patch) | |
tree | f243bab9cd2d845e9958353c2f89d9bc0aa42eec /abaddon.cpp | |
parent | 8699a547f3d51504cd0aa695f580315b8fe27678 (diff) | |
download | abaddon-portaudio-5b7d36bb7438f32b56d6ebdf043ee291332060f1.tar.gz abaddon-portaudio-5b7d36bb7438f32b56d6ebdf043ee291332060f1.zip |
scroll up to load more messages
Diffstat (limited to 'abaddon.cpp')
-rw-r--r-- | abaddon.cpp | 29 |
1 files changed, 27 insertions, 2 deletions
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<Snowflake> 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<MessageData> &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<MessageData> &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); } |