summaryrefslogtreecommitdiff
path: root/src/notifications
diff options
context:
space:
mode:
Diffstat (limited to 'src/notifications')
-rw-r--r--src/notifications/notifications.cpp33
-rw-r--r--src/notifications/notifications.hpp18
-rw-r--r--src/notifications/notifier.hpp10
-rw-r--r--src/notifications/notifier_gio.cpp11
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);
+}