use discord's default avatars instead of placeholder

This commit is contained in:
ouwou 2021-04-07 20:42:53 -04:00
parent 0faff42e17
commit 1251d89ef0
9 changed files with 54 additions and 67 deletions

View File

@ -86,15 +86,11 @@ ChannelListRowDMChannel::ChannelListRowDMChannel(const ChannelData *data) {
m_status = Gtk::manage(new StatusIndicator(top_recipient->ID));
m_status->set_margin_start(5);
if (top_recipient->HasAvatar()) {
m_icon = Gtk::manage(new Gtk::Image(Abaddon::Get().GetImageManager().GetPlaceholder(24)));
auto cb = [this](const Glib::RefPtr<Gdk::Pixbuf> &pb) {
m_icon->property_pixbuf() = pb->scale_simple(24, 24, Gdk::INTERP_BILINEAR);
};
Abaddon::Get().GetImageManager().LoadFromURL(top_recipient->GetAvatarURL("png", "16"), sigc::track_obj(cb, *this));
} else {
m_icon = Gtk::manage(new Gtk::Image(Abaddon::Get().GetImageManager().GetPlaceholder(24)));
}
m_icon = Gtk::manage(new Gtk::Image(Abaddon::Get().GetImageManager().GetPlaceholder(24)));
auto cb = [this](const Glib::RefPtr<Gdk::Pixbuf> &pb) {
m_icon->property_pixbuf() = pb->scale_simple(24, 24, Gdk::INTERP_BILINEAR);
};
Abaddon::Get().GetImageManager().LoadFromURL(top_recipient->GetAvatarURL("png", "16"), sigc::track_obj(cb, *this));
}
auto buf = m_lbl->get_buffer();

View File

@ -1042,13 +1042,11 @@ ChatMessageHeader::ChatMessageHeader(const Message *data) {
auto &img = Abaddon::Get().GetImageManager();
m_avatar = Gtk::manage(new Gtk::Image(img.GetPlaceholder(AvatarSize)));
if (author->HasAvatar()) {
auto cb = [this](const Glib::RefPtr<Gdk::Pixbuf> &pb) {
m_static_avatar = pb->scale_simple(AvatarSize, AvatarSize, Gdk::INTERP_BILINEAR);
m_avatar->property_pixbuf() = m_static_avatar;
};
img.LoadFromURL(author->GetAvatarURL(), sigc::track_obj(cb, *this));
}
auto cb = [this](const Glib::RefPtr<Gdk::Pixbuf> &pb) {
m_static_avatar = pb->scale_simple(AvatarSize, AvatarSize, Gdk::INTERP_BILINEAR);
m_avatar->property_pixbuf() = m_static_avatar;
};
img.LoadFromURL(author->GetAvatarURL(), sigc::track_obj(cb, *this));
if (author->HasAnimatedAvatar()) {
auto cb = [this](const Glib::RefPtr<Gdk::PixbufAnimation> &pb) {

View File

@ -137,8 +137,7 @@ void Completer::CompleteMentions(const Glib::ustring &term) {
}
}
if (author->HasAvatar())
entry->SetImage(author->GetAvatarURL());
entry->SetImage(author->GetAvatarURL());
}
}

View File

@ -26,8 +26,7 @@ MemberListUserRow::MemberListUserRow(const GuildData *guild, const UserData &dat
m_status_indicator->set_margin_start(3);
if (data.HasAvatar())
m_avatar->SetURL(data.GetAvatarURL("png"));
m_avatar->SetURL(data.GetAvatarURL("png"));
get_style_context()->add_class("members-row");
get_style_context()->add_class("members-row-member");

View File

@ -67,18 +67,16 @@ FriendPickerDialogItem::FriendPickerDialogItem(Snowflake user_id)
m_name.set_single_line_mode(true);
m_avatar.property_pixbuf() = Abaddon::Get().GetImageManager().GetPlaceholder(32);
if (user.HasAvatar()) {
if (user.HasAnimatedAvatar() && Abaddon::Get().GetSettings().GetShowAnimations()) {
auto cb = [this](const Glib::RefPtr<Gdk::PixbufAnimation> &pb) {
m_avatar.property_pixbuf_animation() = pb;
};
Abaddon::Get().GetImageManager().LoadAnimationFromURL(user.GetAvatarURL("gif", "32"), 32, 32, sigc::track_obj(cb, *this));
} else {
auto cb = [this](const Glib::RefPtr<Gdk::Pixbuf> &pb) {
m_avatar.property_pixbuf() = pb->scale_simple(32, 32, Gdk::INTERP_BILINEAR);
};
Abaddon::Get().GetImageManager().LoadFromURL(user.GetAvatarURL("png", "32"), sigc::track_obj(cb, *this));
}
if (user.HasAnimatedAvatar() && Abaddon::Get().GetSettings().GetShowAnimations()) {
auto cb = [this](const Glib::RefPtr<Gdk::PixbufAnimation> &pb) {
m_avatar.property_pixbuf_animation() = pb;
};
Abaddon::Get().GetImageManager().LoadAnimationFromURL(user.GetAvatarURL("gif", "32"), 32, 32, sigc::track_obj(cb, *this));
} else {
auto cb = [this](const Glib::RefPtr<Gdk::Pixbuf> &pb) {
m_avatar.property_pixbuf() = pb->scale_simple(32, 32, Gdk::INTERP_BILINEAR);
};
Abaddon::Get().GetImageManager().LoadFromURL(user.GetAvatarURL("png", "32"), sigc::track_obj(cb, *this));
}
m_avatar.set_margin_end(5);

View File

@ -14,7 +14,10 @@ bool UserData::HasAnimatedAvatar() const {
}
std::string UserData::GetAvatarURL(std::string ext, std::string size) const {
return "https://cdn.discordapp.com/avatars/" + std::to_string(ID) + "/" + Avatar + "." + ext + "?size=" + size;
if (HasAvatar())
return "https://cdn.discordapp.com/avatars/" + std::to_string(ID) + "/" + Avatar + "." + ext + "?size=" + size;
else
return "https://cdn.discordapp.com/embed/avatars/" + std::to_string(std::stoul(Discriminator) % 5) + ".png"; // size isn't respected by the cdn
}
Snowflake UserData::GetHoistedRole(Snowflake guild_id, bool with_color) const {

View File

@ -98,12 +98,10 @@ GuildSettingsMembersListItem::GuildSettingsMembersListItem(const GuildData &guil
auto &discord = Abaddon::Get().GetDiscordClient();
if (member.User->HasAvatar()) {
if (member.User->HasAnimatedAvatar() && Abaddon::Get().GetSettings().GetShowAnimations())
m_avatar.SetURL(member.User->GetAvatarURL("gif", "32"));
else
m_avatar.SetURL(member.User->GetAvatarURL("png", "32"));
}
if (member.User->HasAnimatedAvatar() && Abaddon::Get().GetSettings().GetShowAnimations())
m_avatar.SetURL(member.User->GetAvatarURL("gif", "32"));
else
m_avatar.SetURL(member.User->GetAvatarURL("png", "32"));
DisplayTerm = member.User->Username + "#" + member.User->Discriminator;

View File

@ -12,18 +12,16 @@ MutualFriendItem::MutualFriendItem(const UserData &user)
const auto show_animations = Abaddon::Get().GetSettings().GetShowAnimations();
auto &img = Abaddon::Get().GetImageManager();
m_avatar.property_pixbuf() = img.GetPlaceholder(24);
if (user.HasAvatar()) {
if (user.HasAnimatedAvatar() && show_animations) {
auto cb = [this](const Glib::RefPtr<Gdk::PixbufAnimation> &pb) {
m_avatar.property_pixbuf_animation() = pb;
};
img.LoadAnimationFromURL(user.GetAvatarURL("gif", "32"), 24, 24, sigc::track_obj(cb, *this));
} else {
auto cb = [this](const Glib::RefPtr<Gdk::Pixbuf> &pb) {
m_avatar.property_pixbuf() = pb->scale_simple(24, 24, Gdk::INTERP_BILINEAR);
};
img.LoadFromURL(user.GetAvatarURL("png", "32"), sigc::track_obj(cb, *this));
}
if (user.HasAnimatedAvatar() && show_animations) {
auto cb = [this](const Glib::RefPtr<Gdk::PixbufAnimation> &pb) {
m_avatar.property_pixbuf_animation() = pb;
};
img.LoadAnimationFromURL(user.GetAvatarURL("gif", "32"), 24, 24, sigc::track_obj(cb, *this));
} else {
auto cb = [this](const Glib::RefPtr<Gdk::Pixbuf> &pb) {
m_avatar.property_pixbuf() = pb->scale_simple(24, 24, Gdk::INTERP_BILINEAR);
};
img.LoadFromURL(user.GetAvatarURL("png", "32"), sigc::track_obj(cb, *this));
}
m_name.set_markup(user.GetEscapedBoldString<false>());

View File

@ -47,23 +47,21 @@ ProfileWindow::ProfileWindow(Snowflake user_id)
static const bool show_animations = Abaddon::Get().GetSettings().GetShowAnimations();
auto &img = Abaddon::Get().GetImageManager();
m_avatar.property_pixbuf() = img.GetPlaceholder(64);
if (user.HasAvatar()) {
auto icon_cb = [this](const Glib::RefPtr<Gdk::Pixbuf> &pb) {
set_icon(pb);
};
img.LoadFromURL(user.GetAvatarURL("png", "64"), sigc::track_obj(icon_cb, *this));
auto icon_cb = [this](const Glib::RefPtr<Gdk::Pixbuf> &pb) {
set_icon(pb);
};
img.LoadFromURL(user.GetAvatarURL("png", "64"), sigc::track_obj(icon_cb, *this));
if (show_animations && user.HasAnimatedAvatar()) {
auto cb = [this](const Glib::RefPtr<Gdk::PixbufAnimation> &pb) {
m_avatar.property_pixbuf_animation() = pb;
};
img.LoadAnimationFromURL(user.GetAvatarURL("gif", "64"), 64, 64, sigc::track_obj(cb, *this));
} else {
auto cb = [this](const Glib::RefPtr<Gdk::Pixbuf> &pb) {
m_avatar.property_pixbuf() = pb->scale_simple(64, 64, Gdk::INTERP_BILINEAR);
};
img.LoadFromURL(user.GetAvatarURL("png", "64"), sigc::track_obj(cb, *this));
}
if (show_animations && user.HasAnimatedAvatar()) {
auto cb = [this](const Glib::RefPtr<Gdk::PixbufAnimation> &pb) {
m_avatar.property_pixbuf_animation() = pb;
};
img.LoadAnimationFromURL(user.GetAvatarURL("gif", "64"), 64, 64, sigc::track_obj(cb, *this));
} else {
auto cb = [this](const Glib::RefPtr<Gdk::Pixbuf> &pb) {
m_avatar.property_pixbuf() = pb->scale_simple(64, 64, Gdk::INTERP_BILINEAR);
};
img.LoadFromURL(user.GetAvatarURL("png", "64"), sigc::track_obj(cb, *this));
}
m_username.set_markup(user.GetEscapedString());