Made #channel link in /mentions jump to #channel split (#2220)

This commit is contained in:
Paweł 2020-11-28 17:45:20 +01:00 committed by GitHub
parent 1a4d4dca79
commit 49fa9bfd72
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
4 changed files with 38 additions and 1 deletions

View file

@ -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)

View file

@ -20,6 +20,7 @@ public:
AutoModAllow,
AutoModDeny,
OpenAccountsPage,
JumpToChannel,
};
Link();

View file

@ -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<TextElement>(channelName, MessageElementFlag::ChannelName,
MessageColor::System)

View file

@ -2043,6 +2043,41 @@ void ChannelView::handleLinkClick(QMouseEvent *event, const Link &link,
SettingsDialogPreference::Accounts);
}
break;
case Link::JumpToChannel: {
// Get all currently open pages
QList<SplitContainer *> openPages;
auto &nb = getApp()->windows->getMainWindow().getNotebook();
for (int i = 0; i < nb.getPageCount(); ++i)
{
openPages.push_back(
static_cast<SplitContainer *>(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:;
}