Make opening threads from a usercard opened with /usercard not crash the client (#3905)

Co-authored-by: Rasmus Karlsson <rasmus.karlsson@pajlada.com>
This commit is contained in:
Mm2PL 2022-11-05 13:40:15 +01:00 committed by GitHub
parent 2ec26f57cc
commit 6f88c1cc8a
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
3 changed files with 44 additions and 2 deletions

View file

@ -2,7 +2,7 @@
## Unversioned
- Major: Added support for Twitch's Chat Replies. [Wiki Page](https://wiki.chatterino.com/Features/#message-replies) (#3722, #3989, #4041, #4047, #4055, #4067, #4077)
- Major: Added support for Twitch's Chat Replies. [Wiki Page](https://wiki.chatterino.com/Features/#message-replies) (#3722, #3989, #4041, #4047, #4055, #4067, #4077, #3905)
- Major: Added multi-channel searching to search dialog via keyboard shortcut. (Ctrl+Shift+F by default) (#3694, #3875)
- Major: Added support for emotes and badges from [7TV](https://7tv.app). [Wiki Page](https://wiki.chatterino.com/Third_party_services/#7tv) (#4002, #4062)
- Minor: Added highlights for `Elevated Messages`. (#4016)

View file

@ -32,6 +32,7 @@
#include "widgets/dialogs/ReplyThreadPopup.hpp"
#include "widgets/dialogs/UserInfoPopup.hpp"
#include "widgets/splits/Split.hpp"
#include "widgets/splits/SplitContainer.hpp"
#include <QApplication>
#include <QDesktopServices>
@ -838,10 +839,49 @@ void CommandController::initialize(Settings &, Paths &paths)
channel = channelTemp;
}
// try to link to current split if possible
Split *currentSplit = nullptr;
auto *currentPage = dynamic_cast<SplitContainer *>(
getApp()->windows->getMainWindow().getNotebook().getSelectedPage());
if (currentPage != nullptr)
{
currentSplit = currentPage->getSelectedSplit();
}
auto differentChannel =
currentSplit != nullptr && currentSplit->getChannel() != channel;
if (differentChannel || currentSplit == nullptr)
{
// not possible to use current split, try searching for one
const auto &notebook =
getApp()->windows->getMainWindow().getNotebook();
auto count = notebook.getPageCount();
for (int i = 0; i < count; i++)
{
auto *page = notebook.getPageAt(i);
auto *container = dynamic_cast<SplitContainer *>(page);
assert(container != nullptr);
for (auto *split : container->getSplits())
{
if (split->getChannel() == channel)
{
currentSplit = split;
break;
}
}
}
// This would have crashed either way.
assert(currentSplit != nullptr &&
"something went HORRIBLY wrong with the /usercard "
"command. It couldn't find a split for a channel which "
"should be open.");
}
auto *userPopup = new UserInfoPopup(
getSettings()->autoCloseUserPopup,
static_cast<QWidget *>(&(getApp()->windows->getMainWindow())),
nullptr);
currentSplit);
userPopup->setData(userName, channel);
userPopup->move(QCursor::pos());
userPopup->show();

View file

@ -135,6 +135,8 @@ UserInfoPopup::UserInfoPopup(bool closeAutomatically, QWidget *parent,
: DraggablePopup(closeAutomatically, parent)
, split_(split)
{
assert(split != nullptr &&
"split being nullptr causes lots of bugs down the road");
this->setWindowTitle("Usercard");
this->setStayInScreenRect(true);