mirror of
https://github.com/celisej567/abaddon.git
synced 2026-09-06 20:15:19 +03:00
withdraw notifications on channel open
This commit is contained in:
@@ -733,6 +733,8 @@ void Abaddon::ActionChannelOpened(Snowflake id, bool expand_to) {
|
||||
}
|
||||
if (id == m_main_window->GetChatActiveChannel()) return;
|
||||
|
||||
m_notifications.WithdrawChannel(id);
|
||||
|
||||
m_main_window->GetChatWindow()->SetTopic("");
|
||||
|
||||
const auto channel = m_discord.GetChannel(id);
|
||||
|
||||
@@ -99,12 +99,23 @@ void Notifications::CheckMessage(const Message &message) {
|
||||
// notify messages in DMs
|
||||
const auto channel = discord.GetChannel(message.ChannelID);
|
||||
if (channel->IsDM()) {
|
||||
m_chan_notifications[message.ChannelID].push_back(message.ID);
|
||||
NotifyMessageDM(message);
|
||||
} else if (CheckGuildMessage(message)) {
|
||||
m_chan_notifications[message.ChannelID].push_back(message.ID);
|
||||
NotifyMessageGuild(message);
|
||||
}
|
||||
}
|
||||
|
||||
void Notifications::WithdrawChannel(Snowflake channel_id) {
|
||||
if (auto it = m_chan_notifications.find(channel_id); it != m_chan_notifications.end()) {
|
||||
for (const auto notification_id : it->second) {
|
||||
m_notifier.Withdraw(std::to_string(notification_id));
|
||||
}
|
||||
it->second.clear();
|
||||
}
|
||||
}
|
||||
|
||||
Glib::ustring Sanitize(const Message &message) {
|
||||
auto buf = Gtk::TextBuffer::create();
|
||||
Gtk::TextBuffer::iterator begin, end;
|
||||
@@ -123,7 +134,7 @@ void Notifications::NotifyMessageDM(const Message &message) {
|
||||
const auto body = Sanitize(message);
|
||||
|
||||
Abaddon::Get().GetImageManager().GetCache().GetFileFromURL(message.Author.GetAvatarURL("png", "64"), [=](const std::string &path) {
|
||||
m_notifier.Notify(title, body, default_action, path);
|
||||
m_notifier.Notify(std::to_string(message.ID), title, body, default_action, path);
|
||||
});
|
||||
}
|
||||
|
||||
@@ -146,7 +157,7 @@ void Notifications::NotifyMessageGuild(const Message &message) {
|
||||
}
|
||||
const auto body = Sanitize(message);
|
||||
Abaddon::Get().GetImageManager().GetCache().GetFileFromURL(message.Author.GetAvatarURL("png", "64"), [=](const std::string &path) {
|
||||
m_notifier.Notify(title, body, default_action, path);
|
||||
m_notifier.Notify(std::to_string(message.ID), title, body, default_action, path);
|
||||
});
|
||||
}
|
||||
|
||||
|
||||
@@ -1,5 +1,7 @@
|
||||
#pragma once
|
||||
#include "notifier.hpp"
|
||||
#include <map>
|
||||
#include <vector>
|
||||
|
||||
class Message;
|
||||
|
||||
@@ -8,6 +10,7 @@ public:
|
||||
Notifications();
|
||||
|
||||
void CheckMessage(const Message &message);
|
||||
void WithdrawChannel(Snowflake channel_id);
|
||||
|
||||
private:
|
||||
void NotifyMessageDM(const Message &message);
|
||||
@@ -16,4 +19,5 @@ private:
|
||||
[[nodiscard]] bool IsDND() const;
|
||||
|
||||
Notifier m_notifier;
|
||||
std::map<Snowflake, std::vector<Snowflake>> m_chan_notifications;
|
||||
};
|
||||
|
||||
@@ -11,7 +11,8 @@ public:
|
||||
Notifier();
|
||||
~Notifier();
|
||||
|
||||
void Notify(const Glib::ustring &title, const Glib::ustring &text, const Glib::ustring &default_action, const std::string &icon_path);
|
||||
void Notify(const Glib::ustring &id, const Glib::ustring &title, const Glib::ustring &text, const Glib::ustring &default_action, const std::string &icon_path);
|
||||
void Withdraw(const Glib::ustring &id);
|
||||
|
||||
private:
|
||||
#ifdef ENABLE_NOTIFICATION_SOUNDS
|
||||
|
||||
@@ -18,7 +18,7 @@ Notifier::~Notifier() {
|
||||
#endif
|
||||
}
|
||||
|
||||
void Notifier::Notify(const Glib::ustring &title, const Glib::ustring &text, const Glib::ustring &default_action, const std::string &icon_path) {
|
||||
void Notifier::Notify(const Glib::ustring &id, const Glib::ustring &title, const Glib::ustring &text, const Glib::ustring &default_action, const std::string &icon_path) {
|
||||
auto n = Gio::Notification::create(title);
|
||||
n->set_body(text);
|
||||
n->set_default_action(default_action);
|
||||
@@ -29,7 +29,7 @@ void Notifier::Notify(const Glib::ustring &title, const Glib::ustring &text, con
|
||||
auto *icon = g_file_icon_new(file);
|
||||
g_notification_set_icon(n->gobj(), icon);
|
||||
|
||||
Abaddon::Get().GetApp()->send_notification(n);
|
||||
Abaddon::Get().GetApp()->send_notification(id, n);
|
||||
|
||||
g_object_unref(icon);
|
||||
g_object_unref(file);
|
||||
@@ -38,3 +38,7 @@ void Notifier::Notify(const Glib::ustring &title, const Glib::ustring &text, con
|
||||
ma_engine_play_sound(&m_engine, Abaddon::Get().GetResPath("/sound/message.mp3").c_str(), nullptr);
|
||||
#endif
|
||||
}
|
||||
|
||||
void Notifier::Withdraw(const Glib::ustring &id) {
|
||||
Abaddon::Get().GetApp()->withdraw_notification(id);
|
||||
}
|
||||
|
||||
@@ -4,4 +4,6 @@ Notifier::Notifier() {}
|
||||
|
||||
Notifier::~Notifier() {}
|
||||
|
||||
void Notifier::Notify(const Glib::ustring &title, const Glib::ustring &text, const Glib::ustring &default_action, const std::string &icon_path) {}
|
||||
void Notifier::Notify(const Glib::ustring &id, const Glib::ustring &title, const Glib::ustring &text, const Glib::ustring &default_action, const std::string &icon_path) {}
|
||||
|
||||
void Notifier::Withdraw(const Glib::ustring &id) {}
|
||||
|
||||
Reference in New Issue
Block a user