From 358f68d2679640d502d0a13b1d09ee2b3490b4e1 Mon Sep 17 00:00:00 2001 From: ouwou <26526779+ouwou@users.noreply.github.com> Date: Wed, 15 Mar 2023 20:19:54 -0400 Subject: cleanup and escape notification bodies --- src/notifications/notifications.cpp | 15 +++++++++++++-- 1 file changed, 13 insertions(+), 2 deletions(-) (limited to 'src/notifications/notifications.cpp') diff --git a/src/notifications/notifications.cpp b/src/notifications/notifications.cpp index 78ba53c..cda7bb4 100644 --- a/src/notifications/notifications.cpp +++ b/src/notifications/notifications.cpp @@ -1,4 +1,5 @@ #include "notifications.hpp" +#include "misc/chatutil.hpp" #include "discord/message.hpp" Notifications::Notifications() { @@ -104,12 +105,22 @@ void Notifications::CheckMessage(const Message &message) { } } +Glib::ustring Sanitize(const Message &message) { + auto buf = Gtk::TextBuffer::create(); + Gtk::TextBuffer::iterator begin, end; + buf->get_bounds(begin, end); + buf->insert(end, message.Content); + ChatUtil::CleanupEmojis(buf); + ChatUtil::HandleUserMentions(buf, message.ChannelID, true); + return Glib::Markup::escape_text(buf->get_text()); +} + void Notifications::NotifyMessageDM(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; + 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); @@ -133,7 +144,7 @@ void Notifications::NotifyMessageGuild(const Message &message) { title += " (#" + *channel->Name + ")"; } } - const auto body = message.Content; + 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); }); -- cgit v1.2.3