blob: 351cf3251441fc48255c7c121a6076618658e51e (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
|
#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;
// 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;
}
|