mirror of
https://github.com/celisej567/abaddon.git
synced 2026-09-19 20:11:59 +03:00
make avatar loading a bit better
This commit is contained in:
@@ -14,18 +14,16 @@ ChatMessageContainer::ChatMessageContainer(const Message *data) {
|
||||
m_author = Gtk::manage(new Gtk::Label);
|
||||
m_timestamp = Gtk::manage(new Gtk::Label);
|
||||
|
||||
static Glib::RefPtr<Gdk::Pixbuf> test = Gdk::Pixbuf::create_from_file("res/decamarks.png", 32, 32);
|
||||
m_avatar = Gtk::manage(new Gtk::Image(test));
|
||||
static auto placeholder = Gdk::Pixbuf::create_from_file("res/decamarks.png", 32, 32);
|
||||
auto buf = Abaddon::Get().GetImageManager().GetFromURLIfCached(data->Author.GetAvatarURL());
|
||||
if (buf)
|
||||
m_avatar = Gtk::manage(new Gtk::Image(buf));
|
||||
else
|
||||
m_avatar = Gtk::manage(new Gtk::Image(placeholder));
|
||||
|
||||
m_avatar->set_valign(Gtk::ALIGN_START);
|
||||
m_avatar->set_margin_right(10);
|
||||
|
||||
if (data->Author.HasAvatar()) {
|
||||
Abaddon::Get().GetCache().GetFileFromURL(data->Author.GetAvatarURL(), [this](std::string filepath) {
|
||||
auto buf = Gdk::Pixbuf::create_from_file(filepath, 32, 32);
|
||||
m_avatar->property_pixbuf() = buf;
|
||||
});
|
||||
}
|
||||
|
||||
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");
|
||||
@@ -67,6 +65,10 @@ ChatMessageContainer::ChatMessageContainer(const Message *data) {
|
||||
show();
|
||||
}
|
||||
|
||||
void ChatMessageContainer::SetAvatarFromPixbuf(Glib::RefPtr<Gdk::Pixbuf> pixbuf) {
|
||||
m_avatar->property_pixbuf() = pixbuf;
|
||||
}
|
||||
|
||||
void ChatMessageContainer::Update() {
|
||||
auto &discord = Abaddon::Get().GetDiscordClient();
|
||||
auto guild_id = discord.GetChannel(ChannelID)->GuildID;
|
||||
|
||||
@@ -19,6 +19,7 @@ public:
|
||||
|
||||
ChatMessageContainer(const Message *data);
|
||||
void AddNewContent(Gtk::Widget *widget, bool prepend = false);
|
||||
void SetAvatarFromPixbuf(Glib::RefPtr<Gdk::Pixbuf> pixbuf);
|
||||
void Update();
|
||||
|
||||
protected:
|
||||
|
||||
@@ -115,6 +115,25 @@ void ChatWindow::ProcessMessage(const Message *data, bool prepend) {
|
||||
} else {
|
||||
container = Gtk::manage(new ChatMessageContainer(data)); // only accesses timestamp and user
|
||||
container->Update();
|
||||
|
||||
auto user_id = data->Author.ID;
|
||||
const auto *user = Abaddon::Get().GetDiscordClient().GetUser(user_id);
|
||||
if (user == nullptr) return;
|
||||
Abaddon::Get().GetImageManager().LoadFromURL(user->GetAvatarURL(), [this, user_id](Glib::RefPtr<Gdk::Pixbuf> buf) {
|
||||
// am i retarded?
|
||||
Glib::signal_idle().connect([this, buf, user_id]() -> bool {
|
||||
auto children = m_listbox->get_children();
|
||||
for (auto child : children) {
|
||||
auto *row = dynamic_cast<ChatMessageContainer *>(child);
|
||||
if (row == nullptr) continue;
|
||||
if (row->UserID == user_id) {
|
||||
row->SetAvatarFromPixbuf(buf);
|
||||
}
|
||||
}
|
||||
|
||||
return false;
|
||||
});
|
||||
});
|
||||
m_num_rows++;
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user