diff options
Diffstat (limited to 'src/notifications')
-rw-r--r-- | src/notifications/notifications.cpp | 37 | ||||
-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 | ||||
-rw-r--r-- | src/notifications/notifier_null.cpp | 5 |
5 files changed, 81 insertions, 0 deletions
diff --git a/src/notifications/notifications.cpp b/src/notifications/notifications.cpp new file mode 100644 index 0000000..b1c4c2f --- /dev/null +++ b/src/notifications/notifications.cpp @@ -0,0 +1,37 @@ +#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; + // ignore if focused and message's channel is active + if (Abaddon::Get().IsMainWindowActive() && Abaddon::Get().GetActiveChannelID() == message.ChannelID) return; + // ignore if its our own message + if (message.Author.ID == Abaddon::Get().GetDiscordClient().GetUserData().ID) 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); +} diff --git a/src/notifications/notifier_null.cpp b/src/notifications/notifier_null.cpp new file mode 100644 index 0000000..98a7e16 --- /dev/null +++ b/src/notifications/notifier_null.cpp @@ -0,0 +1,5 @@ +#include "notifier.hpp" + +Notifier::Notifier() {} + +void Notifier::Notify(const Glib::ustring &title, const Glib::ustring &text, const Glib::ustring &default_action) {} |