move avatar stuff out of chatwindow

This commit is contained in:
ouwou 2020-11-18 16:25:10 -05:00
parent a0ece884d0
commit 1463d8da9e
3 changed files with 12 additions and 21 deletions

View File

@ -731,11 +731,14 @@ ChatMessageHeader::ChatMessageHeader(const Message *data) {
m_timestamp = Gtk::manage(new Gtk::Label);
m_avatar_ev = Gtk::manage(new Gtk::EventBox);
auto buf = Abaddon::Get().GetImageManager().GetFromURLIfCached(data->Author.GetAvatarURL());
auto &img = Abaddon::Get().GetImageManager();
auto buf = img.GetFromURLIfCached(data->Author.GetAvatarURL());
if (buf)
m_avatar = Gtk::manage(new Gtk::Image(buf));
else
m_avatar = Gtk::manage(new Gtk::Image(Abaddon::Get().GetImageManager().GetPlaceholder(32)));
else {
m_avatar = Gtk::manage(new Gtk::Image(img.GetPlaceholder(32)));
img.LoadFromURL(data->Author.GetAvatarURL(), sigc::mem_fun(*this, &ChatMessageHeader::OnAvatarLoad));
}
get_style_context()->add_class("message-container");
m_author->get_style_context()->add_class("message-container-author");
@ -824,6 +827,10 @@ void ChatMessageHeader::UpdateNameColor() {
m_author->set_markup(md);
}
void ChatMessageHeader::OnAvatarLoad(const Glib::RefPtr<Gdk::Pixbuf> &pixbuf) {
m_avatar->property_pixbuf() = pixbuf;
}
void ChatMessageHeader::AttachUserMenuHandler(Gtk::Widget &widget) {
widget.signal_button_press_event().connect([this](GdkEventButton *ev) -> bool {
if (ev->type == GDK_BUTTON_PRESS && ev->button == GDK_BUTTON_SECONDARY) {
@ -857,7 +864,3 @@ void ChatMessageHeader::AddContent(Gtk::Widget *widget, bool prepend) {
if (prepend)
m_content_box->reorder_child(*widget, 1);
}
void ChatMessageHeader::SetAvatarFromPixbuf(Glib::RefPtr<Gdk::Pixbuf> pixbuf) {
m_avatar->property_pixbuf() = pixbuf;
}

View File

@ -101,11 +101,12 @@ public:
Snowflake ChannelID;
ChatMessageHeader(const Message *data);
void SetAvatarFromPixbuf(Glib::RefPtr<Gdk::Pixbuf> pixbuf);
void AddContent(Gtk::Widget *widget, bool prepend);
void UpdateNameColor();
protected:
void OnAvatarLoad(const Glib::RefPtr<Gdk::Pixbuf> &pixbuf);
void AttachUserMenuHandler(Gtk::Widget &widget);
bool on_author_button_press(GdkEventButton *ev);

View File

@ -192,19 +192,6 @@ void ChatWindow::ProcessNewMessage(Snowflake id, bool prepend) {
});
m_num_rows++;
Abaddon::Get().GetImageManager().LoadFromURL(user->GetAvatarURL("png", "32"), [this, user_id](Glib::RefPtr<Gdk::Pixbuf> buf) {
Glib::signal_idle().connect([this, buf, user_id]() -> bool {
auto children = m_list->get_children();
for (auto child : children) {
auto *row = dynamic_cast<ChatMessageHeader *>(child);
if (row == nullptr) continue;
if (row->UserID == user_id)
row->SetAvatarFromPixbuf(buf);
}
return false;
});
});
}
auto *content = CreateMessageComponent(id);