mirror of
https://github.com/uowuo/abaddon.git
synced 2024-09-20 23:11:51 +00:00
move avatar stuff out of chatwindow
This commit is contained in:
parent
a0ece884d0
commit
1463d8da9e
|
@ -731,11 +731,14 @@ ChatMessageHeader::ChatMessageHeader(const Message *data) {
|
||||||
m_timestamp = Gtk::manage(new Gtk::Label);
|
m_timestamp = Gtk::manage(new Gtk::Label);
|
||||||
m_avatar_ev = Gtk::manage(new Gtk::EventBox);
|
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)
|
if (buf)
|
||||||
m_avatar = Gtk::manage(new Gtk::Image(buf));
|
m_avatar = Gtk::manage(new Gtk::Image(buf));
|
||||||
else
|
else {
|
||||||
m_avatar = Gtk::manage(new Gtk::Image(Abaddon::Get().GetImageManager().GetPlaceholder(32)));
|
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");
|
get_style_context()->add_class("message-container");
|
||||||
m_author->get_style_context()->add_class("message-container-author");
|
m_author->get_style_context()->add_class("message-container-author");
|
||||||
|
@ -824,6 +827,10 @@ void ChatMessageHeader::UpdateNameColor() {
|
||||||
m_author->set_markup(md);
|
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) {
|
void ChatMessageHeader::AttachUserMenuHandler(Gtk::Widget &widget) {
|
||||||
widget.signal_button_press_event().connect([this](GdkEventButton *ev) -> bool {
|
widget.signal_button_press_event().connect([this](GdkEventButton *ev) -> bool {
|
||||||
if (ev->type == GDK_BUTTON_PRESS && ev->button == GDK_BUTTON_SECONDARY) {
|
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)
|
if (prepend)
|
||||||
m_content_box->reorder_child(*widget, 1);
|
m_content_box->reorder_child(*widget, 1);
|
||||||
}
|
}
|
||||||
|
|
||||||
void ChatMessageHeader::SetAvatarFromPixbuf(Glib::RefPtr<Gdk::Pixbuf> pixbuf) {
|
|
||||||
m_avatar->property_pixbuf() = pixbuf;
|
|
||||||
}
|
|
||||||
|
|
|
@ -101,11 +101,12 @@ public:
|
||||||
Snowflake ChannelID;
|
Snowflake ChannelID;
|
||||||
|
|
||||||
ChatMessageHeader(const Message *data);
|
ChatMessageHeader(const Message *data);
|
||||||
void SetAvatarFromPixbuf(Glib::RefPtr<Gdk::Pixbuf> pixbuf);
|
|
||||||
void AddContent(Gtk::Widget *widget, bool prepend);
|
void AddContent(Gtk::Widget *widget, bool prepend);
|
||||||
void UpdateNameColor();
|
void UpdateNameColor();
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
|
void OnAvatarLoad(const Glib::RefPtr<Gdk::Pixbuf> &pixbuf);
|
||||||
|
|
||||||
void AttachUserMenuHandler(Gtk::Widget &widget);
|
void AttachUserMenuHandler(Gtk::Widget &widget);
|
||||||
|
|
||||||
bool on_author_button_press(GdkEventButton *ev);
|
bool on_author_button_press(GdkEventButton *ev);
|
||||||
|
|
|
@ -192,19 +192,6 @@ void ChatWindow::ProcessNewMessage(Snowflake id, bool prepend) {
|
||||||
});
|
});
|
||||||
|
|
||||||
m_num_rows++;
|
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);
|
auto *content = CreateMessageComponent(id);
|
||||||
|
|
Loading…
Reference in New Issue
Block a user