From f3e5dcbe6521413344091004641feaa2906efb0f Mon Sep 17 00:00:00 2001
From: ouwou <26526779+ouwou@users.noreply.github.com>
Date: Fri, 9 Sep 2022 02:40:33 -0400
Subject: fix some potential crashes because of optionals
---
src/components/chatmessage.cpp | 18 ++++++++++++------
1 file changed, 12 insertions(+), 6 deletions(-)
(limited to 'src/components/chatmessage.cpp')
diff --git a/src/components/chatmessage.cpp b/src/components/chatmessage.cpp
index 1aca81d..89c924e 100644
--- a/src/components/chatmessage.cpp
+++ b/src/components/chatmessage.cpp
@@ -655,13 +655,19 @@ Gtk::Widget *ChatMessageItemContainer::CreateReplyComponent(const Message &data)
const auto role = discord.GetRole(role_id);
if (role.has_value()) {
const auto author = discord.GetUser(author_id);
- return "Color) + "\">" + author->GetEscapedString() + "";
+ if (author.has_value()) {
+ return "Color) + "\">" + author->GetEscapedString() + "";
+ }
}
}
}
const auto author = discord.GetUser(author_id);
- return author->GetEscapedBoldString();
+ if (author.has_value()) {
+ return author->GetEscapedBoldString();
+ }
+
+ return "Unknown User";
};
// if the message wasnt fetched from store it might have an un-fetched reference
@@ -673,15 +679,15 @@ Gtk::Widget *ChatMessageItemContainer::CreateReplyComponent(const Message &data)
}
if (data.Interaction.has_value()) {
- const auto user = *discord.GetUser(data.Interaction->User.ID);
-
if (data.GuildID.has_value()) {
- lbl->set_markup(get_author_markup(user.ID, *data.GuildID) +
+ lbl->set_markup(get_author_markup(data.Interaction->User.ID, *data.GuildID) +
" used /" +
Glib::Markup::escape_text(data.Interaction->Name) +
"");
+ } else if (const auto user = discord.GetUser(data.Interaction->User.ID); user.has_value()) {
+ lbl->set_markup(user->GetEscapedBoldString());
} else {
- lbl->set_markup(user.GetEscapedBoldString());
+ lbl->set_markup("Unknown User");
}
} else if (referenced_message.has_value()) {
if (referenced_message.value() == nullptr) {
--
cgit v1.2.3
From 3027e00905b19282a4f501a26f7a4f71bc6940ea Mon Sep 17 00:00:00 2001
From: ouwou <26526779+ouwou@users.noreply.github.com>
Date: Sun, 25 Sep 2022 01:44:09 -0400
Subject: open browser on mouse release (fixes #108)
---
src/components/chatmessage.cpp | 8 ++++----
src/windows/guildsettings/infopane.cpp | 7 +++----
src/windows/profile/userinfopane.cpp | 4 ++--
src/windows/profilewindow.cpp | 4 ++--
4 files changed, 11 insertions(+), 12 deletions(-)
(limited to 'src/components/chatmessage.cpp')
diff --git a/src/components/chatmessage.cpp b/src/components/chatmessage.cpp
index 89c924e..3afdf9f 100644
--- a/src/components/chatmessage.cpp
+++ b/src/components/chatmessage.cpp
@@ -150,8 +150,8 @@ void ChatMessageItemContainer::UpdateAttributes() {
void ChatMessageItemContainer::AddClickHandler(Gtk::Widget *widget, const std::string &url) {
// clang-format off
- widget->signal_button_press_event().connect([url](GdkEventButton *event) -> bool {
- if (event->type == GDK_BUTTON_PRESS && event->button == GDK_BUTTON_PRIMARY) {
+ widget->signal_button_release_event().connect([url](GdkEventButton *event) -> bool {
+ if (event->type == GDK_BUTTON_RELEASE && event->button == GDK_BUTTON_PRIMARY) {
LaunchBrowser(url);
return true;
}
@@ -357,8 +357,8 @@ Gtk::Widget *ChatMessageItemContainer::CreateEmbedComponent(const EmbedData &emb
if (embed.URL.has_value()) {
AddPointerCursor(*title_ev);
auto url = *embed.URL;
- title_ev->signal_button_press_event().connect([url = std::move(url)](GdkEventButton *event) -> bool {
- if (event->button == GDK_BUTTON_PRIMARY) {
+ title_ev->signal_button_release_event().connect([url = std::move(url)](GdkEventButton *event) -> bool {
+ if (event->type == GDK_BUTTON_RELEASE && event->button == GDK_BUTTON_PRIMARY) {
LaunchBrowser(url);
return true;
}
diff --git a/src/windows/guildsettings/infopane.cpp b/src/windows/guildsettings/infopane.cpp
index 578aaac..a27c1a8 100644
--- a/src/windows/guildsettings/infopane.cpp
+++ b/src/windows/guildsettings/infopane.cpp
@@ -56,10 +56,9 @@ GuildSettingsInfoPane::GuildSettingsInfoPane(Snowflake id)
guild_icon_url = guild.GetIconURL("gif", "512");
else
guild_icon_url = guild.GetIconURL("png", "512");
- m_guild_icon_ev.signal_button_press_event().connect([guild_icon_url](GdkEventButton *event) -> bool {
- if (event->type == GDK_BUTTON_PRESS)
- if (event->button == GDK_BUTTON_PRIMARY)
- LaunchBrowser(guild_icon_url);
+ m_guild_icon_ev.signal_button_release_event().connect([guild_icon_url](GdkEventButton *event) -> bool {
+ if (event->type == GDK_BUTTON_RELEASE && event->button == GDK_BUTTON_PRIMARY)
+ LaunchBrowser(guild_icon_url);
return false;
});
diff --git a/src/windows/profile/userinfopane.cpp b/src/windows/profile/userinfopane.cpp
index a17dbff..b62da93 100644
--- a/src/windows/profile/userinfopane.cpp
+++ b/src/windows/profile/userinfopane.cpp
@@ -41,13 +41,13 @@ ConnectionItem::ConnectionItem(const ConnectionData &conn)
m_box.add(m_name);
if (!url.empty()) {
auto cb = [url](GdkEventButton *event) -> bool {
- if (event->type == GDK_BUTTON_PRESS && event->button == GDK_BUTTON_PRIMARY) {
+ if (event->type == GDK_BUTTON_RELEASE && event->button == GDK_BUTTON_PRIMARY) {
LaunchBrowser(url);
return true;
}
return false;
};
- signal_button_press_event().connect(sigc::track_obj(cb, *this));
+ signal_button_release_event().connect(sigc::track_obj(cb, *this));
AddPointerCursor(*this);
}
m_overlay.add(m_box);
diff --git a/src/windows/profilewindow.cpp b/src/windows/profilewindow.cpp
index aff98c5..d73731d 100644
--- a/src/windows/profilewindow.cpp
+++ b/src/windows/profilewindow.cpp
@@ -34,8 +34,8 @@ ProfileWindow::ProfileWindow(Snowflake user_id)
if (user.HasAvatar())
AddPointerCursor(m_avatar_ev);
- m_avatar_ev.signal_button_press_event().connect([user](GdkEventButton *event) -> bool {
- if (event->type == GDK_BUTTON_PRESS && event->button == GDK_BUTTON_PRIMARY) {
+ m_avatar_ev.signal_button_release_event().connect([user](GdkEventButton *event) -> bool {
+ if (event->type == GDK_BUTTON_RELEASE && event->button == GDK_BUTTON_PRIMARY) {
if (user.HasAnimatedAvatar())
LaunchBrowser(user.GetAvatarURL("gif", "512"));
else
--
cgit v1.2.3