diff options
author | ouwou <26526779+ouwou@users.noreply.github.com> | 2023-02-28 20:23:34 -0500 |
---|---|---|
committer | ouwou <26526779+ouwou@users.noreply.github.com> | 2023-02-28 20:23:34 -0500 |
commit | e212b364b969b7918fbe9152dc4b7c04da303d12 (patch) | |
tree | 43a7ae7462cf5af50b3ef612bba57dd4ce14dce1 /src/notifications | |
parent | ba9d9997d4c4c4e9228632a962d6f0d3b1f35a6e (diff) | |
download | abaddon-portaudio-e212b364b969b7918fbe9152dc4b7c04da303d12.tar.gz abaddon-portaudio-e212b364b969b7918fbe9152dc4b7c04da303d12.zip |
rudimentary dm notifications
Diffstat (limited to 'src/notifications')
-rw-r--r-- | src/notifications/notifications.cpp | 33 | ||||
-rw-r--r-- | src/notifications/notifications.hpp | 18 | ||||
-rw-r--r-- | src/notifications/notifier.hpp | 10 | ||||
-rw-r--r-- | src/notifications/notifier_gio.cpp | 11 |
4 files changed, 72 insertions, 0 deletions
diff --git a/src/notifications/notifications.cpp b/src/notifications/notifications.cpp new file mode 100644 index 0000000..ed4a879 --- /dev/null +++ b/src/notifications/notifications.cpp @@ -0,0 +1,33 @@ +#include "notifications.hpp" +#include "discord/message.hpp" + +Notifications::Notifications() { +} + +void Notifications::CheckMessage(const Message &message) { + // ignore if our status is do not disturb + if (IsDND()) return; + auto &discord = Abaddon::Get().GetDiscordClient(); + // ignore if the channel is muted + if (discord.IsChannelMuted(message.ChannelID)) return; + // notify messages in DMs + const auto channel = discord.GetChannel(message.ChannelID); + if (channel->IsDM()) { + NotifyMessage(message); + } +} + +void Notifications::NotifyMessage(const Message &message) { + Glib::ustring default_action = "app.go-to-channel"; + default_action += "::"; + 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); +} + +bool Notifications::IsDND() const { + auto &discord = Abaddon::Get().GetDiscordClient(); + const auto status = discord.GetUserStatus(discord.GetUserData().ID); + return status == PresenceStatus::DND; +} diff --git a/src/notifications/notifications.hpp b/src/notifications/notifications.hpp new file mode 100644 index 0000000..fb71349 --- /dev/null +++ b/src/notifications/notifications.hpp @@ -0,0 +1,18 @@ +#pragma once +#include "notifier.hpp" + +class Message; + +class Notifications { +public: + Notifications(); + + void CheckMessage(const Message &message); + +private: + void NotifyMessage(const Message &message); + + [[nodiscard]] bool IsDND() const; + + Notifier m_notifier; +}; diff --git a/src/notifications/notifier.hpp b/src/notifications/notifier.hpp new file mode 100644 index 0000000..48e881f --- /dev/null +++ b/src/notifications/notifier.hpp @@ -0,0 +1,10 @@ +#pragma once +#include <glibmm/ustring.h> +#include <gdkmm/pixbuf.h> + +class Notifier { +public: + Notifier(); + + void Notify(const Glib::ustring &title, const Glib::ustring &text, const Glib::ustring &default_action); +}; diff --git a/src/notifications/notifier_gio.cpp b/src/notifications/notifier_gio.cpp new file mode 100644 index 0000000..6106114 --- /dev/null +++ b/src/notifications/notifier_gio.cpp @@ -0,0 +1,11 @@ +#include "notifier.hpp" +#include <giomm/notification.h> + +Notifier::Notifier() {} + +void Notifier::Notify(const Glib::ustring &title, const Glib::ustring &text, const Glib::ustring &default_action) { + auto n = Gio::Notification::create(title); + n->set_body(text); + n->set_default_action(default_action); + Abaddon::Get().GetApp()->send_notification(n); +} |