From e212b364b969b7918fbe9152dc4b7c04da303d12 Mon Sep 17 00:00:00 2001 From: ouwou <26526779+ouwou@users.noreply.github.com> Date: Tue, 28 Feb 2023 20:23:34 -0500 Subject: rudimentary dm notifications --- src/notifications/notifications.cpp | 33 +++++++++++++++++++++++++++++++++ 1 file changed, 33 insertions(+) create mode 100644 src/notifications/notifications.cpp (limited to 'src/notifications/notifications.cpp') 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; +} -- cgit v1.2.3