summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorouwou <26526779+ouwou@users.noreply.github.com>2023-03-09 23:28:10 -0500
committerouwou <26526779+ouwou@users.noreply.github.com>2023-03-09 23:28:10 -0500
commite06e574206990c5d0a57d526214f9bf482120412 (patch)
tree6d77ef3b479152b761a8607abeaf2abfd33e197b /src
parent816f1a01ecc3155ad410d1ff34510b558e2d8cbf (diff)
downloadabaddon-portaudio-e06e574206990c5d0a57d526214f9bf482120412.tar.gz
abaddon-portaudio-e06e574206990c5d0a57d526214f9bf482120412.zip
add user avatars to notifications
Diffstat (limited to 'src')
-rw-r--r--src/imgmanager.cpp4
-rw-r--r--src/imgmanager.hpp1
-rw-r--r--src/notifications/notifications.cpp9
-rw-r--r--src/notifications/notifier.hpp2
-rw-r--r--src/notifications/notifier_gio.cpp12
5 files changed, 24 insertions, 4 deletions
diff --git a/src/imgmanager.cpp b/src/imgmanager.cpp
index d681222..43793c0 100644
--- a/src/imgmanager.cpp
+++ b/src/imgmanager.cpp
@@ -101,3 +101,7 @@ Glib::RefPtr<Gdk::Pixbuf> ImageManager::GetPlaceholder(int size) {
return Glib::RefPtr<Gdk::Pixbuf>(nullptr);
}
}
+
+Cache &ImageManager::GetCache() {
+ return m_cache;
+}
diff --git a/src/imgmanager.hpp b/src/imgmanager.hpp
index 3bc0f4e..2eeb756 100644
--- a/src/imgmanager.hpp
+++ b/src/imgmanager.hpp
@@ -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);
diff --git a/src/notifications/notifications.cpp b/src/notifications/notifications.cpp
index db06651..78ba53c 100644
--- a/src/notifications/notifications.cpp
+++ b/src/notifications/notifications.cpp
@@ -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 {
diff --git a/src/notifications/notifier.hpp b/src/notifications/notifier.hpp
index 9007dc8..869b918 100644
--- a/src/notifications/notifier.hpp
+++ b/src/notifications/notifier.hpp
@@ -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
diff --git a/src/notifications/notifier_gio.cpp b/src/notifications/notifier_gio.cpp
index f28735c..f09b002 100644
--- a/src/notifications/notifier_gio.cpp
+++ b/src/notifications/notifier_gio.cpp
@@ -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