From 49fa9bfd7225ead6e8c044aa138c7cb3ccaeef94 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Pawe=C5=82?= Date: Sat, 28 Nov 2020 17:45:20 +0100 Subject: [PATCH] Made #channel link in /mentions jump to #channel split (#2220) --- CHANGELOG.md | 1 + src/messages/Link.hpp | 1 + src/messages/SharedMessageBuilder.cpp | 2 +- src/widgets/helper/ChannelView.cpp | 35 +++++++++++++++++++++++++++ 4 files changed, 38 insertions(+), 1 deletion(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 5dd4ad99d..4dd00fec5 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -2,6 +2,7 @@ ## Unversioned +- Minor: Made "#channel" in `/mentions` tab a clickable link which takes you to the channel that you were mentioned in. (#2220) - Minor: Added a keyboard shortcut (Ctrl+F5) for "Reconnect" (#2215) - Minor: Made `Try to find usernames without @ prefix` option still resolve usernames when special characters (commas, dots, (semi)colons, exclamation mark, question mark) are appended to them. (#2212) - Minor: Made usercard update user's display name (#2160) diff --git a/src/messages/Link.hpp b/src/messages/Link.hpp index 716345935..ac83da587 100644 --- a/src/messages/Link.hpp +++ b/src/messages/Link.hpp @@ -20,6 +20,7 @@ public: AutoModAllow, AutoModDeny, OpenAccountsPage, + JumpToChannel, }; Link(); diff --git a/src/messages/SharedMessageBuilder.cpp b/src/messages/SharedMessageBuilder.cpp index d3da6b1c7..25a82fe2b 100644 --- a/src/messages/SharedMessageBuilder.cpp +++ b/src/messages/SharedMessageBuilder.cpp @@ -356,7 +356,7 @@ void SharedMessageBuilder::addTextOrEmoji(const QString &string_) void SharedMessageBuilder::appendChannelName() { QString channelName("#" + this->channel->getName()); - Link link(Link::Url, this->channel->getName() + "\n" + this->message().id); + Link link(Link::JumpToChannel, this->channel->getName()); this->emplace(channelName, MessageElementFlag::ChannelName, MessageColor::System) diff --git a/src/widgets/helper/ChannelView.cpp b/src/widgets/helper/ChannelView.cpp index 55319f3ed..f0d61c26f 100644 --- a/src/widgets/helper/ChannelView.cpp +++ b/src/widgets/helper/ChannelView.cpp @@ -2043,6 +2043,41 @@ void ChannelView::handleLinkClick(QMouseEvent *event, const Link &link, SettingsDialogPreference::Accounts); } break; + case Link::JumpToChannel: { + // Get all currently open pages + QList openPages; + + auto &nb = getApp()->windows->getMainWindow().getNotebook(); + for (int i = 0; i < nb.getPageCount(); ++i) + { + openPages.push_back( + static_cast(nb.getPageAt(i))); + } + + for (auto *page : openPages) + { + auto splits = page->getSplits(); + + // Search for channel matching link in page/split container + // TODO(zneix): Consider opening a channel if it's closed (?) + auto it = std::find_if( + splits.begin(), splits.end(), [link](Split *split) { + return split->getChannel()->getName() == link.value; + }); + + if (it != splits.end()) + { + // Select SplitContainer and Split itself where mention message was sent + // TODO(zneix): Try exploring ways of scrolling to a certain message as well + nb.select(page); + + Split *split = *it; + page->setSelected(split); + break; + } + } + } + break; default:; }