mirror of
https://github.com/celisej567/abaddon.git
synced 2026-09-13 20:18:50 +03:00
add user avatars to notifications
This commit is contained in:
@@ -101,3 +101,7 @@ Glib::RefPtr<Gdk::Pixbuf> ImageManager::GetPlaceholder(int size) {
|
||||
return Glib::RefPtr<Gdk::Pixbuf>(nullptr);
|
||||
}
|
||||
}
|
||||
|
||||
Cache &ImageManager::GetCache() {
|
||||
return m_cache;
|
||||
}
|
||||
|
||||
@@ -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);
|
||||
|
||||
@@ -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 {
|
||||
|
||||
@@ -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
|
||||
|
||||
@@ -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
|
||||
|
||||
Reference in New Issue
Block a user