Fix memory leak and invite filtering

This commit is contained in:
NepNep21 2023-12-19 23:53:55 -03:00
parent 1295e84020
commit 2abd2870e0
No known key found for this signature in database
GPG key ID: 60372BB5B7534B09
2 changed files with 12 additions and 10 deletions

View file

@ -954,17 +954,16 @@ 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)
{ {
QSharedPointer<UserProfile> profile( UserProfile *profile = new UserProfile(QString(), user, TimelineViewManager::instance());
new UserProfile(QString(), user, TimelineViewManager::instance())); connect(profile, &UserProfile::failedToFetchProfile, [user] {
connect(profile.get(), &UserProfile::failedToFetchProfile, [user] {
MainWindow::instance()->showNotification(tr("Failed to fetch user %1").arg(user)); MainWindow::instance()->showNotification(tr("Failed to fetch user %1").arg(user));
}); });
connect(profile.get(), connect(
&UserProfile::globalUsernameRetrieved, profile, &UserProfile::globalUsernameRetrieved, [profile, ignored](const QString &user_id) {
[profile, ignored](const QString &user_id) {
Q_UNUSED(user_id) Q_UNUSED(user_id)
profile->setIgnored(ignored); profile->setIgnored(ignored);
profile->deleteLater();
}); });
} }

View file

@ -281,9 +281,12 @@ UserProfile::setIgnored(bool ignore)
if (ignore) { if (ignore) {
const QHash<QString, RoomInfo> invites = cache::invites(); const QHash<QString, RoomInfo> invites = cache::invites();
FilteredRoomlistModel *room_model = FilteredRoomlistModel::instance();
for (auto room = invites.keyBegin(), end = invites.keyEnd(); room != end; room++) { for (auto room = invites.keyBegin(), end = invites.keyEnd(); room != end; room++) {
FilteredRoomlistModel::instance()->declineInvite(*room); if (room_model->getRoomPreviewById(*room).inviterUserId() == userid) {
room_model->declineInvite(*room);
}
} }
} }
} }