summaryrefslogtreecommitdiff
path: root/components
diff options
context:
space:
mode:
authorouwou <26526779+ouwou@users.noreply.github.com>2021-04-04 04:09:56 -0400
committerouwou <26526779+ouwou@users.noreply.github.com>2021-04-04 04:09:56 -0400
commit6f1013d146e9e4878b3ef542d4b95ccbcaa7fff1 (patch)
treea878b7092216431f6bc4304addabd097cc7c7698 /components
parenta933a0ca276e8919836084dde5aec9e0d30daeb8 (diff)
downloadabaddon-portaudio-6f1013d146e9e4878b3ef542d4b95ccbcaa7fff1.tar.gz
abaddon-portaudio-6f1013d146e9e4878b3ef542d4b95ccbcaa7fff1.zip
display interaction responses (again)
Diffstat (limited to 'components')
-rw-r--r--components/chatmessage.cpp58
-rw-r--r--components/chatwindow.hpp3
2 files changed, 36 insertions, 25 deletions
diff --git a/components/chatmessage.cpp b/components/chatmessage.cpp
index 90daa87..b527ce4 100644
--- a/components/chatmessage.cpp
+++ b/components/chatmessage.cpp
@@ -60,7 +60,7 @@ ChatMessageItemContainer *ChatMessageItemContainer::FromMessage(Snowflake id) {
container->m_main->add(*container->m_text_component);
}
- if (data->MessageReference.has_value()) {
+ if (data->MessageReference.has_value() || data->Interaction.has_value()) {
auto *widget = container->CreateReplyComponent(*data);
container->m_main->add(*widget);
container->m_main->child_property_position(*widget) = 0; // eek
@@ -230,6 +230,12 @@ void ChatMessageItemContainer::UpdateTextComponent(Gtk::TextView *tv) {
const auto app = data->Application->Name;
b->insert_markup(s, "<i>used <span color='#697ec4'>" + cmd + "</span> with " + app + "</i>");
}
+ } else {
+ b->insert(s, data->Content);
+ HandleUserMentions(b);
+ HandleLinks(*tv);
+ HandleChannelMentions(tv);
+ HandleEmojis(*tv);
}
} break;
case MessageType::RECIPIENT_ADD: {
@@ -567,7 +573,32 @@ Gtk::Widget *ChatMessageItemContainer::CreateReplyComponent(const Message &data)
lbl->get_style_context()->add_class("message-reply");
box->add(*lbl);
- if (data.ReferencedMessage.has_value()) {
+ const auto &discord = Abaddon::Get().GetDiscordClient();
+
+ const auto get_author_markup = [&](Snowflake author_id, Snowflake guild_id = Snowflake::Invalid) -> std::string {
+ if (guild_id.IsValid()) {
+ const auto role_id = discord.GetMemberHoistedRole(guild_id, author_id, true);
+ if (role_id.IsValid()) {
+ const auto role = discord.GetRole(role_id);
+ if (role.has_value()) {
+ const auto author = discord.GetUser(author_id);
+ return "<b><span color=\"#" + IntToCSSColor(role->Color) + "\">" + author->GetEscapedString() + "</span></b>";
+ }
+ }
+ }
+
+ const auto author = discord.GetUser(author_id);
+ return author->GetEscapedBoldString<false>();
+ };
+
+ if (data.Interaction.has_value()) {
+ const auto user = *discord.GetUser(data.Interaction->User.ID);
+ lbl->set_markup(
+ get_author_markup(user.ID, data.GuildID.has_value() ? *data.GuildID : Snowflake::Invalid) +
+ " used <span color='#697ec4'>/" +
+ Glib::Markup::escape_text(data.Interaction->Name) +
+ "</span>");
+ } else if (data.ReferencedMessage.has_value()) {
if (data.ReferencedMessage.value().get() == nullptr) {
lbl->set_markup("<i>deleted message</i>");
} else {
@@ -595,28 +626,7 @@ Gtk::Widget *ChatMessageItemContainer::CreateReplyComponent(const Message &data)
// which of course would not be an issue if i could figure out how to get fonts to work on this god-forsaken framework
// oh well
// but ill manually get colors for the user who is being replied to
- const auto &discord = Abaddon::Get().GetDiscordClient();
- if (referenced.GuildID.has_value()) {
- const auto role_id = discord.GetMemberHoistedRole(*referenced.GuildID, referenced.Author.ID, true);
- if (role_id.IsValid()) {
- const auto role = discord.GetRole(role_id);
- if (role.has_value()) {
- const auto author = discord.GetUser(referenced.Author.ID);
- // clang-format off
- lbl->set_markup(
- "<b><span color=\"#" + IntToCSSColor(role->Color) + "\">"
- + author->GetEscapedString()
- + "</span></b>: "
- + text
- );
- // clang-format on
- return box;
- }
- }
- }
-
- const auto author = discord.GetUser(referenced.Author.ID);
- lbl->set_markup(author->GetEscapedBoldString<false>() + ": " + text);
+ lbl->set_markup(get_author_markup(referenced.Author.ID, *referenced.GuildID) + ": " + text);
}
} else {
lbl->set_markup("<i>reply unavailable</i>");
diff --git a/components/chatwindow.hpp b/components/chatwindow.hpp
index 066a804..f8336dd 100644
--- a/components/chatwindow.hpp
+++ b/components/chatwindow.hpp
@@ -3,9 +3,10 @@
#include <string>
#include <set>
#include "../discord/discord.hpp"
-#include "chatmessage.hpp"
#include "completer.hpp"
+class ChatMessageHeader;
+class ChatMessageItemContainer;
class ChatInput;
class ChatInputIndicator;
class ChatWindow {