mirror of
https://github.com/uowuo/abaddon.git
synced 2025-08-05 05:30:09 +00:00
only load 50 messages on channel switch (also fix member menu)
This commit is contained in:
parent
2822add5fe
commit
e5a90b9461
12
abaddon.cpp
12
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) {
|
||||
|
@ -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);
|
||||
|
@ -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());
|
||||
|
@ -21,6 +21,7 @@ public:
|
||||
void UpdateMessageContent(Snowflake id);
|
||||
void Clear();
|
||||
void InsertChatInput(std::string text);
|
||||
Snowflake GetOldestListedMessage();
|
||||
|
||||
protected:
|
||||
void ScrollToBottom();
|
||||
|
@ -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();
|
||||
}
|
||||
|
||||
|
@ -12,6 +12,7 @@ public:
|
||||
Snowflake ID;
|
||||
|
||||
private:
|
||||
Gtk::EventBox *m_ev;
|
||||
Gtk::Box *m_box;
|
||||
Gtk::Image *m_avatar;
|
||||
Gtk::Label *m_label;
|
||||
|
@ -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;
|
||||
}
|
||||
|
@ -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();
|
||||
|
Loading…
Reference in New Issue
Block a user