Fix crash on empty mxid in ignore commands

fixes #1753
This commit is contained in:
Nicolas Werner 2024-06-20 16:59:14 +02:00
parent dbdbb5ef75
commit c7483aed98
No known key found for this signature in database
GPG key ID: C8D75E610773F2D9

View file

@ -1030,9 +1030,9 @@ InputBar::command(const QString &command, QString args)
} else if (command == QLatin1String("converttoroom")) { } else if (command == QLatin1String("converttoroom")) {
utils::removeDirectFromRoom(this->room->roomId()); utils::removeDirectFromRoom(this->room->roomId());
} else if (command == QLatin1String("ignore")) { } else if (command == QLatin1String("ignore")) {
this->toggleIgnore(args, true); this->toggleIgnore(args.trimmed(), true);
} else if (command == QLatin1String("unignore")) { } else if (command == QLatin1String("unignore")) {
this->toggleIgnore(args, false); this->toggleIgnore(args.trimmed(), false);
} else { } else {
return false; return false;
} }
@ -1043,6 +1043,11 @@ InputBar::command(const QString &command, QString args)
void void
InputBar::toggleIgnore(const QString &user, const bool ignored) InputBar::toggleIgnore(const QString &user, const bool ignored)
{ {
if (!user.startsWith(u"@")) {
MainWindow::instance()->showNotification(tr("You need to pass a valid mxid when ignoring a user. '%1' is not a valid userid.").arg(user));
return;
}
UserProfile *profile = new UserProfile(QString(), user, TimelineViewManager::instance()); UserProfile *profile = new UserProfile(QString(), user, TimelineViewManager::instance());
connect(profile, &UserProfile::failedToFetchProfile, [user, profile] { connect(profile, &UserProfile::failedToFetchProfile, [user, profile] {
MainWindow::instance()->showNotification(tr("Failed to fetch user %1").arg(user)); MainWindow::instance()->showNotification(tr("Failed to fetch user %1").arg(user));