From 3550121c89efcdfb829269173d94124c7a8a6f1f Mon Sep 17 00:00:00 2001 From: Mm2PL Date: Sat, 5 Aug 2023 13:17:34 +0200 Subject: [PATCH] Fixed right-clicking mentions no longer working. (#4751) * fix up rightclicking mentions * changelog * Merge changelog entries other PR was merged after 2.4.4 --- CHANGELOG.md | 2 +- src/widgets/helper/ChannelView.cpp | 77 ++++++++++++++++-------------- 2 files changed, 42 insertions(+), 37 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 7697a84c045..cc7fadb589a 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -19,6 +19,7 @@ - Minor: Stream status requests are now batched. (#4713) - Minor: Added `/c2-theme-autoreload` command to automatically reload a custom theme. This is useful for when you're developing your own theme. (#4718) - Minor: Show channel point redemptions without messages in usercard. (#4557) +- Minor: Allow for customizing the behavior of `Right Click`ing of usernames. (#4622, #4751) - Bugfix: Increased amount of blocked users loaded from 100 to 1,000. (#4721) - Bugfix: Fixed generation of crashdumps by the browser-extension process when the browser was closed. (#4667) - Bugfix: Fix spacing issue with mentions inside RTL text. (#4677) @@ -54,7 +55,6 @@ - Minor: Added a Send button in the input box so you can click to send a message. This is disabled by default and can be enabled with the "Show send message button" setting. (#4607) - Minor: Improved error messages when the updater fails a download. (#4594) - Minor: Added `/shield` and `/shieldoff` commands to toggle shield mode. (#4580) -- Minor: Allow for customizing the behavior of `Right Click`ing of usernames. (#4622) - Bugfix: Fixed the menu warping on macOS on Qt6. (#4595) - Bugfix: Fixed link tooltips not showing unless the thumbnail setting was enabled. (#4597) - Bugfix: Domains starting with `http` are now parsed as links again. (#4598) diff --git a/src/widgets/helper/ChannelView.cpp b/src/widgets/helper/ChannelView.cpp index 83653c49b2e..9ed6b7aceec 100644 --- a/src/widgets/helper/ChannelView.cpp +++ b/src/widgets/helper/ChannelView.cpp @@ -2105,8 +2105,15 @@ void ChannelView::handleMouseClick(QMouseEvent *event, if (link.type == Link::UserInfo) { - if (hoveredElement->getFlags().has( - MessageElementFlag::Username)) + // This is terrible because it FPs on messages where the + // user mentions themselves + bool canReply = + QString::compare(link.value, + layout->getMessage()->loginName, + Qt::CaseInsensitive) == 0; + UsernameRightClickBehavior action = + UsernameRightClickBehavior::Mention; + if (canReply) { Qt::KeyboardModifier userSpecifiedModifier = getSettings()->usernameRightClickModifier; @@ -2125,7 +2132,6 @@ void ChannelView::handleMouseClick(QMouseEvent *event, Qt::KeyboardModifiers modifiers{userSpecifiedModifier}; auto isModifierHeld = event->modifiers() == modifiers; - UsernameRightClickBehavior action{}; if (isModifierHeld) { action = getSettings() @@ -2135,44 +2141,43 @@ void ChannelView::handleMouseClick(QMouseEvent *event, { action = getSettings()->usernameRightClickBehavior; } - - switch (action) - { - case UsernameRightClickBehavior::Mention: { - if (split == nullptr) - { - return; - } - - // Insert @username into split input - const bool commaMention = - getSettings()->mentionUsersWithComma; - const bool isFirstWord = - split->getInput().isEditFirstWord(); - auto userMention = formatUserMention( - link.value, isFirstWord, commaMention); - insertText("@" + userMention + " "); + } + switch (action) + { + case UsernameRightClickBehavior::Mention: { + if (split == nullptr) + { + return; } - break; - case UsernameRightClickBehavior::Reply: { - // Start a new reply if matching user's settings - this->setInputReply(layout->getMessagePtr()); - } - break; + // Insert @username into split input + const bool commaMention = + getSettings()->mentionUsersWithComma; + const bool isFirstWord = + split->getInput().isEditFirstWord(); + auto userMention = formatUserMention( + link.value, isFirstWord, commaMention); + insertText("@" + userMention + " "); + } + break; - case UsernameRightClickBehavior::Ignore: - break; + case UsernameRightClickBehavior::Reply: { + // Start a new reply if matching user's settings + this->setInputReply(layout->getMessagePtr()); + } + break; - default: { - qCWarning(chatterinoCommon) - << "unhandled or corrupted " - "UsernameRightClickBehavior value in " - "ChannelView::handleMouseClick:" - << action; - } - break; // unreachable + case UsernameRightClickBehavior::Ignore: + break; + + default: { + qCWarning(chatterinoCommon) + << "unhandled or corrupted " + "UsernameRightClickBehavior value in " + "ChannelView::handleMouseClick:" + << action; } + break; // unreachable } return;