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

View file

@ -281,9 +281,12 @@ UserProfile::setIgnored(bool ignore)
if (ignore) {
const QHash<QString, RoomInfo> invites = cache::invites();
FilteredRoomlistModel *room_model = FilteredRoomlistModel::instance();
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);
}
}
}
}