diff options
-rw-r--r-- | abaddon.cpp | 12 | ||||
-rw-r--r-- | components/chatmessage.cpp | 1 | ||||
-rw-r--r-- | components/chatwindow.cpp | 11 | ||||
-rw-r--r-- | components/chatwindow.hpp | 1 | ||||
-rw-r--r-- | components/memberlist.cpp | 5 | ||||
-rw-r--r-- | components/memberlist.hpp | 1 | ||||
-rw-r--r-- | windows/mainwindow.cpp | 16 | ||||
-rw-r--r-- | windows/mainwindow.hpp | 1 |
8 files changed, 46 insertions, 2 deletions
diff --git a/abaddon.cpp b/abaddon.cpp index 2b8ea4e..0fb189b 100644 --- a/abaddon.cpp +++ b/abaddon.cpp @@ -237,6 +237,18 @@ void Abaddon::ActionChatLoadHistory(Snowflake id) { if (m_channels_history_loading.find(id) != m_channels_history_loading.end()) return; + Snowflake before_id = m_main_window->GetChatOldestListedMessage(); + auto knownset = m_discord.GetMessagesForChannel(id); + std::vector<Snowflake> knownvec(knownset.begin(), knownset.end()); + std::sort(knownvec.begin(), knownvec.end()); + auto latest = std::find_if(knownvec.begin(), knownvec.end(), [&before_id](Snowflake x) -> bool { return x == before_id; }); + int distance = std::distance(knownvec.begin(), latest); + + if (distance >= 50) { + m_main_window->UpdateChatPrependHistory(std::vector<Snowflake>(knownvec.begin() + distance - 50, knownvec.begin() + distance)); + return; + } + m_channels_history_loading.insert(id); m_discord.FetchMessagesInChannelBefore(id, m_oldest_listed_message[id], [this, id](const std::vector<Snowflake> &msgs) { diff --git a/components/chatmessage.cpp b/components/chatmessage.cpp index ae1023d..99f391b 100644 --- a/components/chatmessage.cpp +++ b/components/chatmessage.cpp @@ -26,6 +26,7 @@ ChatMessageContainer::ChatMessageContainer(const Message *data) { get_style_context()->add_class("message-container"); m_author->get_style_context()->add_class("message-container-author"); m_timestamp->get_style_context()->add_class("message-container-timestamp"); + m_avatar->get_style_context()->add_class("message-container-avatar"); m_author->set_markup("<span weight=\"bold\">" + Glib::Markup::escape_text(data->Author.Username) + "</span>"); m_author->set_single_line_mode(true); diff --git a/components/chatwindow.cpp b/components/chatwindow.cpp index b7da92d..652844a 100644 --- a/components/chatwindow.cpp +++ b/components/chatwindow.cpp @@ -237,6 +237,17 @@ void ChatWindow::InsertChatInput(std::string text) { m_input->grab_focus(); } +Snowflake ChatWindow::GetOldestListedMessage() { + Snowflake m; + + for (const auto& [id, widget] : m_id_to_widget) { + if (id < m) + m = id; + } + + return m; +} + void ChatWindow::ScrollToBottom() { auto x = m_scroll->get_vadjustment(); x->set_value(x->get_upper()); diff --git a/components/chatwindow.hpp b/components/chatwindow.hpp index 00d5e2b..ba71d2b 100644 --- a/components/chatwindow.hpp +++ b/components/chatwindow.hpp @@ -21,6 +21,7 @@ public: void UpdateMessageContent(Snowflake id); void Clear(); void InsertChatInput(std::string text); + Snowflake GetOldestListedMessage(); protected: void ScrollToBottom(); diff --git a/components/memberlist.cpp b/components/memberlist.cpp index d1d0711..5d8d963 100644 --- a/components/memberlist.cpp +++ b/components/memberlist.cpp @@ -4,6 +4,7 @@ MemberListUserRow::MemberListUserRow(Snowflake guild_id, const User *data) { ID = data->ID; + m_ev = Gtk::manage(new Gtk::EventBox); m_box = Gtk::manage(new Gtk::Box(Gtk::ORIENTATION_HORIZONTAL)); m_label = Gtk::manage(new Gtk::Label); m_avatar = Gtk::manage(new Gtk::Image(Abaddon::Get().GetImageManager().GetPlaceholder(16))); @@ -11,6 +12,7 @@ MemberListUserRow::MemberListUserRow(Snowflake guild_id, const User *data) { get_style_context()->add_class("members-row"); get_style_context()->add_class("members-row-member"); m_label->get_style_context()->add_class("members-row-label"); + m_avatar->get_style_context()->add_class("members-row-avatar"); m_label->set_single_line_mode(true); m_label->set_ellipsize(Pango::ELLIPSIZE_END); @@ -32,7 +34,8 @@ MemberListUserRow::MemberListUserRow(Snowflake guild_id, const User *data) { m_label->set_halign(Gtk::ALIGN_START); m_box->add(*m_avatar); m_box->add(*m_label); - add(*m_box); + m_ev->add(*m_box); + add(*m_ev); show_all(); } diff --git a/components/memberlist.hpp b/components/memberlist.hpp index 3b64bce..2a727e5 100644 --- a/components/memberlist.hpp +++ b/components/memberlist.hpp @@ -12,6 +12,7 @@ public: Snowflake ID; private: + Gtk::EventBox *m_ev; Gtk::Box *m_box; Gtk::Image *m_avatar; Gtk::Label *m_label; diff --git a/windows/mainwindow.cpp b/windows/mainwindow.cpp index 30d52bb..d4453af 100644 --- a/windows/mainwindow.cpp +++ b/windows/mainwindow.cpp @@ -111,7 +111,17 @@ void MainWindow::UpdateChannelListing() { void MainWindow::UpdateChatWindowContents() { auto &discord = Abaddon::Get().GetDiscordClient(); - m_chat.SetMessages(discord.GetMessagesForChannel(m_chat.GetActiveChannel())); + auto allmsgs = discord.GetMessagesForChannel(m_chat.GetActiveChannel()); + if (allmsgs.size() > 50) { + std::vector<Snowflake> msgvec(allmsgs.begin(), allmsgs.end()); + std::vector<Snowflake> cutvec(msgvec.end() - 50, msgvec.end()); + std::set<Snowflake> msgs; + for (const auto s : cutvec) + msgs.insert(s); + m_chat.SetMessages(msgs); + } else { + m_chat.SetMessages(allmsgs); + } m_members.UpdateMemberList(); } @@ -151,6 +161,10 @@ void MainWindow::InsertChatInput(std::string text) { m_chat.InsertChatInput(text); } +Snowflake MainWindow::GetChatOldestListedMessage() { + return m_chat.GetOldestListedMessage(); +} + ChannelList *MainWindow::GetChannelList() { return &m_channel_list; } diff --git a/windows/mainwindow.hpp b/windows/mainwindow.hpp index e850fa2..7480346 100644 --- a/windows/mainwindow.hpp +++ b/windows/mainwindow.hpp @@ -19,6 +19,7 @@ public: void UpdateChatMessageEditContent(Snowflake id, Snowflake channel_id); void UpdateChatPrependHistory(const std::vector<Snowflake> &msgs); void InsertChatInput(std::string text); + Snowflake GetChatOldestListedMessage(); ChannelList *GetChannelList(); ChatWindow *GetChatWindow(); |