Skip to content

Commit

Permalink
Fixed right-clicking mentions no longer working. (#4751)
Browse files Browse the repository at this point in the history
* fix up rightclicking mentions

* changelog

* Merge changelog entries other PR was merged after 2.4.4
  • Loading branch information
Mm2PL authored Aug 5, 2023
1 parent 222b3da commit b98be3b
Show file tree
Hide file tree
Showing 2 changed files with 42 additions and 37 deletions.
2 changes: 1 addition & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down Expand Up @@ -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)
Expand Down
77 changes: 41 additions & 36 deletions src/widgets/helper/ChannelView.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2104,8 +2104,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;
Expand All @@ -2124,7 +2131,6 @@ void ChannelView::handleMouseClick(QMouseEvent *event,
Qt::KeyboardModifiers modifiers{userSpecifiedModifier};
auto isModifierHeld = event->modifiers() == modifiers;

UsernameRightClickBehavior action{};
if (isModifierHeld)
{
action = getSettings()
Expand All @@ -2134,44 +2140,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;
Expand Down

0 comments on commit b98be3b

Please sign in to comment.