diff options
author | ouwou <26526779+ouwou@users.noreply.github.com> | 2023-03-15 20:19:54 -0400 |
---|---|---|
committer | ouwou <26526779+ouwou@users.noreply.github.com> | 2023-03-15 20:19:54 -0400 |
commit | 358f68d2679640d502d0a13b1d09ee2b3490b4e1 (patch) | |
tree | 685b851243092e1345e70da4e7794f1d282e055c /src/notifications/notifications.cpp | |
parent | 823ba090f05a3b464f93721fc8ce2a6969e3bb67 (diff) | |
download | abaddon-portaudio-358f68d2679640d502d0a13b1d09ee2b3490b4e1.tar.gz abaddon-portaudio-358f68d2679640d502d0a13b1d09ee2b3490b4e1.zip |
cleanup and escape notification bodies
Diffstat (limited to 'src/notifications/notifications.cpp')
-rw-r--r-- | src/notifications/notifications.cpp | 15 |
1 files changed, 13 insertions, 2 deletions
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); }); |