add user avatars to notifications

This commit is contained in:
ouwou
2023-03-09 23:28:10 -05:00
parent 816f1a01ec
commit e06e574206
5 changed files with 24 additions and 4 deletions

View File

@@ -101,3 +101,7 @@ Glib::RefPtr<Gdk::Pixbuf> ImageManager::GetPlaceholder(int size) {
return Glib::RefPtr<Gdk::Pixbuf>(nullptr);
}
}
Cache &ImageManager::GetCache() {
return m_cache;
}

View File

@@ -18,6 +18,7 @@ public:
void LoadAnimationFromURL(const std::string &url, int w, int h, const callback_anim_type &cb);
void Prefetch(const std::string &url);
Glib::RefPtr<Gdk::Pixbuf> GetPlaceholder(int size);
Cache &GetCache();
private:
static Glib::RefPtr<Gdk::Pixbuf> ReadFileToPixbuf(std::string path);

View File

@@ -110,7 +110,10 @@ void Notifications::NotifyMessageDM(const Message &message) {
default_action += std::to_string(message.ChannelID);
const auto title = message.Author.Username;
const auto body = message.Content;
m_notifier.Notify(title, body, default_action);
Abaddon::Get().GetImageManager().GetCache().GetFileFromURL(message.Author.GetAvatarURL("png", "64"), [=](const std::string &path) {
m_notifier.Notify(title, body, default_action, path);
});
}
void Notifications::NotifyMessageGuild(const Message &message) {
@@ -131,7 +134,9 @@ void Notifications::NotifyMessageGuild(const Message &message) {
}
}
const auto body = message.Content;
m_notifier.Notify(title, body, default_action);
Abaddon::Get().GetImageManager().GetCache().GetFileFromURL(message.Author.GetAvatarURL("png", "64"), [=](const std::string &path) {
m_notifier.Notify(title, body, default_action, path);
});
}
bool Notifications::IsDND() const {

View File

@@ -11,7 +11,7 @@ public:
Notifier();
~Notifier();
void Notify(const Glib::ustring &title, const Glib::ustring &text, const Glib::ustring &default_action);
void Notify(const Glib::ustring &title, const Glib::ustring &text, const Glib::ustring &default_action, const std::string &icon_path);
private:
#ifdef WITH_MINIAUDIO

View File

@@ -18,12 +18,22 @@ Notifier::~Notifier() {
#endif
}
void Notifier::Notify(const Glib::ustring &title, const Glib::ustring &text, const Glib::ustring &default_action) {
void Notifier::Notify(const Glib::ustring &title, const Glib::ustring &text, const Glib::ustring &default_action, const std::string &icon_path) {
auto n = Gio::Notification::create(title);
n->set_body(text);
n->set_default_action(default_action);
// i dont think giomm provides an interface for this
auto *file = g_file_new_for_path(icon_path.c_str());
auto *icon = g_file_icon_new(file);
g_notification_set_icon(n->gobj(), icon);
Abaddon::Get().GetApp()->send_notification(n);
g_object_unref(icon);
g_object_unref(file);
#ifdef WITH_MINIAUDIO
ma_engine_play_sound(&m_engine, Abaddon::Get().GetResPath("/sound/message.mp3").c_str(), nullptr);
#endif