From 4695bbb34049d5e7f2c1193ef5e39f39afbd17c0 Mon Sep 17 00:00:00 2001 From: NepNep21 <43792621+NepNep21@users.noreply.github.com> Date: Mon, 11 Dec 2023 22:29:36 -0300 Subject: Add /ignore --- src/CommandCompleter.cpp | 6 ++++++ src/CommandCompleter.h | 1 + src/timeline/InputBar.cpp | 14 +++++++++++++- src/ui/UserProfile.cpp | 6 ++++++ src/ui/UserProfile.h | 2 ++ 5 files changed, 28 insertions(+), 1 deletion(-) (limited to 'src') diff --git a/src/CommandCompleter.cpp b/src/CommandCompleter.cpp index 8123b8e6..e1b91a8c 100644 --- a/src/CommandCompleter.cpp +++ b/src/CommandCompleter.cpp @@ -97,6 +97,8 @@ CommandCompleter::data(const QModelIndex &index, int role) const return QStringLiteral("/converttodm"); case ConvertToRoom: return QStringLiteral("/converttoroom"); + case Ignore: + return QStringLiteral("/ignore"); default: return {}; } @@ -170,6 +172,8 @@ CommandCompleter::data(const QModelIndex &index, int role) const return QStringLiteral("/converttodm"); case ConvertToRoom: return QStringLiteral("/converttoroom"); + case Ignore: + return QStringLiteral("/ignore <@userid>"); default: return {}; } @@ -243,6 +247,8 @@ CommandCompleter::data(const QModelIndex &index, int role) const return tr("Convert this room to a direct chat."); case ConvertToRoom: return tr("Convert this direct chat into a room."); + case Ignore: + return tr("Ignores a user."); default: return {}; } diff --git a/src/CommandCompleter.h b/src/CommandCompleter.h index 4f27fe29..325ebc6d 100644 --- a/src/CommandCompleter.h +++ b/src/CommandCompleter.h @@ -51,6 +51,7 @@ public: Goto, ConvertToDm, ConvertToRoom, + Ignore, COUNT, }; diff --git a/src/timeline/InputBar.cpp b/src/timeline/InputBar.cpp index bcb30aa0..ca320d04 100644 --- a/src/timeline/InputBar.cpp +++ b/src/timeline/InputBar.cpp @@ -30,6 +30,7 @@ #include "ChatPage.h" #include "EventAccessors.h" #include "Logging.h" +#include "MainWindow.h" #include "MatrixClient.h" #include "TimelineModel.h" #include "TimelineViewManager.h" @@ -239,7 +240,8 @@ InputBar::updateTextContentProperties(const QString &t) QStringLiteral("msgtype"), QStringLiteral("goto"), QStringLiteral("converttodm"), - QStringLiteral("converttoroom")}; + QStringLiteral("converttoroom"), + QStringLiteral("ignore")}; bool hasInvalidCommand = !commandName.isNull() && !validCommands.contains(commandName); bool hasIncompleteCommand = hasInvalidCommand && '/' + commandName == t; @@ -937,6 +939,16 @@ InputBar::command(const QString &command, QString args) cache::getMembers(this->room->roomId().toStdString(), 0, -1)); } else if (command == QLatin1String("converttoroom")) { utils::removeDirectFromRoom(this->room->roomId()); + } else if (command == QLatin1String("ignore")) { + QSharedPointer user( + new UserProfile(QString(), args, TimelineViewManager::instance())); + connect(user.get(), &UserProfile::failedToFetchProfile, [args] { + MainWindow::instance()->showNotification(tr("Failed to fetch user %1").arg(args)); + }); + connect(user.get(), &UserProfile::globalUsernameRetrieved, [user](const QString &user_id) { + Q_UNUSED(user_id) + user->setIgnored(true); + }); } else { return false; } diff --git a/src/ui/UserProfile.cpp b/src/ui/UserProfile.cpp index 338f3658..5c63deb2 100644 --- a/src/ui/UserProfile.cpp +++ b/src/ui/UserProfile.cpp @@ -592,12 +592,18 @@ UserProfile::getGlobalProfileData() emit avatarUrlChanged(); }); + connect(profProx.get(), + &UserProfileFetchProxy::failedToFetchProfile, + this, + &UserProfile::failedToFetchProfile); + http::client()->get_profile(userid_.toStdString(), [prox = std::move(profProx), user = userid_.toStdString()]( const mtx::responses::Profile &res, mtx::http::RequestErr err) { if (err) { nhlog::net()->warn("failed to retrieve profile info for {}", user); + emit prox->failedToFetchProfile(); return; } diff --git a/src/ui/UserProfile.h b/src/ui/UserProfile.h index bc5b6a35..64dbf99c 100644 --- a/src/ui/UserProfile.h +++ b/src/ui/UserProfile.h @@ -45,6 +45,7 @@ public: signals: void profileFetched(mtx::responses::Profile); + void failedToFetchProfile(); }; class DeviceInfo @@ -205,6 +206,7 @@ signals: void globalUsernameRetrieved(const QString &globalUser); void devicesChanged(); void ignoredChanged(); + void failedToFetchProfile(); // internal void verificationStatiChanged(); -- cgit 1.4.1 From bfdf87a92dc6a5a18c38fc04af61d306d69ac03c Mon Sep 17 00:00:00 2001 From: NepNep21 Date: Sun, 17 Dec 2023 20:17:43 -0300 Subject: Multiple changes More consistent language with similar description strings Add manpage entry Add /unignore Add ignore & decline button in the invite page Add invite rejection to all ignore methods --- man/nheko.1.adoc | 8 ++++++++ resources/qml/TimelineView.qml | 10 ++++++++++ src/CommandCompleter.cpp | 8 +++++++- src/CommandCompleter.h | 1 + src/timeline/InputBar.cpp | 32 ++++++++++++++++++++++---------- src/timeline/InputBar.h | 2 ++ src/timeline/RoomlistModel.h | 2 ++ src/ui/UserProfile.cpp | 8 ++++++++ 8 files changed, 60 insertions(+), 11 deletions(-) (limited to 'src') diff --git a/man/nheko.1.adoc b/man/nheko.1.adoc index cc4b8f74..5bd5d622 100644 --- a/man/nheko.1.adoc +++ b/man/nheko.1.adoc @@ -229,6 +229,14 @@ Inserts `┯━┯╭( º _ º╭)` */sovietflip*:: Inserts `ノ┬─┬ノ ︵ ( \\o°o)\\` +=== User management + +*/ignore* __:: +Ignore a user, invites from them are also rejected. + +*/unignore* __:: +Stops ignoring a user. + === Advanced */clear-timeline*:: diff --git a/resources/qml/TimelineView.qml b/resources/qml/TimelineView.qml index f66df94f..0a255491 100644 --- a/resources/qml/TimelineView.qml +++ b/resources/qml/TimelineView.qml @@ -277,6 +277,16 @@ Item { onClicked: Rooms.declineInvite(roomPreview.roomid) } + FlatButton { + Layout.alignment: Qt.AlignHCenter + text: qsTr("decline invite and ignore user") + visible: roomPreview && roomPreview.isInvite + + onClicked: { + var inviter = TimelineManager.getGlobalUserProfile(roomPreview.inviterUserId) + inviter.ignored = true + } + } FlatButton { Layout.alignment: Qt.AlignHCenter text: qsTr("leave") diff --git a/src/CommandCompleter.cpp b/src/CommandCompleter.cpp index e1b91a8c..ee666559 100644 --- a/src/CommandCompleter.cpp +++ b/src/CommandCompleter.cpp @@ -99,6 +99,8 @@ CommandCompleter::data(const QModelIndex &index, int role) const return QStringLiteral("/converttoroom"); case Ignore: return QStringLiteral("/ignore"); + case Unignore: + return QStringLiteral("/unignore"); default: return {}; } @@ -174,6 +176,8 @@ CommandCompleter::data(const QModelIndex &index, int role) const return QStringLiteral("/converttoroom"); case Ignore: return QStringLiteral("/ignore <@userid>"); + case Unignore: + return QStringLiteral("/unignore <@userid>"); default: return {}; } @@ -248,7 +252,9 @@ CommandCompleter::data(const QModelIndex &index, int role) const case ConvertToRoom: return tr("Convert this direct chat into a room."); case Ignore: - return tr("Ignores a user."); + return tr("Ignore a user."); + case Unignore: + return tr("Stop ignoring a user."); default: return {}; } diff --git a/src/CommandCompleter.h b/src/CommandCompleter.h index 325ebc6d..35ce2b36 100644 --- a/src/CommandCompleter.h +++ b/src/CommandCompleter.h @@ -52,6 +52,7 @@ public: ConvertToDm, ConvertToRoom, Ignore, + Unignore, COUNT, }; diff --git a/src/timeline/InputBar.cpp b/src/timeline/InputBar.cpp index ca320d04..e93f2795 100644 --- a/src/timeline/InputBar.cpp +++ b/src/timeline/InputBar.cpp @@ -241,7 +241,8 @@ InputBar::updateTextContentProperties(const QString &t) QStringLiteral("goto"), QStringLiteral("converttodm"), QStringLiteral("converttoroom"), - QStringLiteral("ignore")}; + QStringLiteral("ignore"), + QStringLiteral("unignore")}; bool hasInvalidCommand = !commandName.isNull() && !validCommands.contains(commandName); bool hasIncompleteCommand = hasInvalidCommand && '/' + commandName == t; @@ -940,15 +941,9 @@ InputBar::command(const QString &command, QString args) } else if (command == QLatin1String("converttoroom")) { utils::removeDirectFromRoom(this->room->roomId()); } else if (command == QLatin1String("ignore")) { - QSharedPointer user( - new UserProfile(QString(), args, TimelineViewManager::instance())); - connect(user.get(), &UserProfile::failedToFetchProfile, [args] { - MainWindow::instance()->showNotification(tr("Failed to fetch user %1").arg(args)); - }); - connect(user.get(), &UserProfile::globalUsernameRetrieved, [user](const QString &user_id) { - Q_UNUSED(user_id) - user->setIgnored(true); - }); + this->setArgIgnored(args, true); + } else if (command == QLatin1String("unignore")) { + this->setArgIgnored(args, false); } else { return false; } @@ -956,6 +951,23 @@ InputBar::command(const QString &command, QString args) return true; } +void +InputBar::setArgIgnored(const QString &user, const bool ignored) +{ + QSharedPointer profile( + new UserProfile(QString(), user, TimelineViewManager::instance())); + connect(profile.get(), &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); + }); +} + MediaUpload::MediaUpload(std::unique_ptr source_, const QString &mimetype, const QString &originalFilename, diff --git a/src/timeline/InputBar.h b/src/timeline/InputBar.h index b15377fc..cbde0e07 100644 --- a/src/timeline/InputBar.h +++ b/src/timeline/InputBar.h @@ -283,6 +283,8 @@ private: void updateTextContentProperties(const QString &t); + void setArgIgnored(const QString &user, const bool ignored); + QTimer typingRefresh_; QTimer typingTimeout_; TimelineModel *room; diff --git a/src/timeline/RoomlistModel.h b/src/timeline/RoomlistModel.h index 34bf3f9a..2294864f 100644 --- a/src/timeline/RoomlistModel.h +++ b/src/timeline/RoomlistModel.h @@ -197,6 +197,8 @@ public: return instance_; } + static FilteredRoomlistModel *instance() { return instance_; } + bool lessThan(const QModelIndex &left, const QModelIndex &right) const override; bool filterAcceptsRow(int sourceRow, const QModelIndex &) const override; diff --git a/src/ui/UserProfile.cpp b/src/ui/UserProfile.cpp index 5c63deb2..ffb69aa4 100644 --- a/src/ui/UserProfile.cpp +++ b/src/ui/UserProfile.cpp @@ -278,6 +278,14 @@ UserProfile::setIgnored(bool ignore) .arg(userid, QString::fromStdString(e->matrix_error.error))); } }); + + if (ignore) { + const QHash invites = cache::invites(); + + for (auto room = invites.keyBegin(), end = invites.keyEnd(); room != end; room++) { + FilteredRoomlistModel::instance()->declineInvite(*room); + } + } } void -- cgit 1.4.1 From 7c57292c6d2f62c8319a79babb7e80928dcedba1 Mon Sep 17 00:00:00 2001 From: Nep Nep Date: Tue, 19 Dec 2023 21:41:48 -0300 Subject: Improve naming Co-authored-by: DeepBlueV7.X --- src/timeline/InputBar.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'src') diff --git a/src/timeline/InputBar.cpp b/src/timeline/InputBar.cpp index e93f2795..224709ea 100644 --- a/src/timeline/InputBar.cpp +++ b/src/timeline/InputBar.cpp @@ -952,7 +952,7 @@ InputBar::command(const QString &command, QString args) } void -InputBar::setArgIgnored(const QString &user, const bool ignored) +InputBar::toggleIgnore(const QString &user, const bool ignored) { QSharedPointer profile( new UserProfile(QString(), user, TimelineViewManager::instance())); -- cgit 1.4.1 From 1295e84020b23f549aa5474fdeb282d399a3c369 Mon Sep 17 00:00:00 2001 From: NepNep21 Date: Tue, 19 Dec 2023 21:44:19 -0300 Subject: Other occurences --- src/timeline/InputBar.cpp | 4 ++-- src/timeline/InputBar.h | 2 +- 2 files changed, 3 insertions(+), 3 deletions(-) (limited to 'src') diff --git a/src/timeline/InputBar.cpp b/src/timeline/InputBar.cpp index 224709ea..191aebdc 100644 --- a/src/timeline/InputBar.cpp +++ b/src/timeline/InputBar.cpp @@ -941,9 +941,9 @@ InputBar::command(const QString &command, QString args) } else if (command == QLatin1String("converttoroom")) { utils::removeDirectFromRoom(this->room->roomId()); } else if (command == QLatin1String("ignore")) { - this->setArgIgnored(args, true); + this->toggleIgnore(args, true); } else if (command == QLatin1String("unignore")) { - this->setArgIgnored(args, false); + this->toggleIgnore(args, false); } else { return false; } diff --git a/src/timeline/InputBar.h b/src/timeline/InputBar.h index cbde0e07..fbf08343 100644 --- a/src/timeline/InputBar.h +++ b/src/timeline/InputBar.h @@ -283,7 +283,7 @@ private: void updateTextContentProperties(const QString &t); - void setArgIgnored(const QString &user, const bool ignored); + void toggleIgnore(const QString &user, const bool ignored); QTimer typingRefresh_; QTimer typingTimeout_; -- cgit 1.4.1 From 2abd2870e0b6b37fecdfbcfdb3a16024a086e1b4 Mon Sep 17 00:00:00 2001 From: NepNep21 Date: Tue, 19 Dec 2023 23:53:55 -0300 Subject: Fix memory leak and invite filtering --- src/timeline/InputBar.cpp | 17 ++++++++--------- src/ui/UserProfile.cpp | 5 ++++- 2 files changed, 12 insertions(+), 10 deletions(-) (limited to 'src') diff --git a/src/timeline/InputBar.cpp b/src/timeline/InputBar.cpp index 191aebdc..ba1d7880 100644 --- a/src/timeline/InputBar.cpp +++ b/src/timeline/InputBar.cpp @@ -954,18 +954,17 @@ InputBar::command(const QString &command, QString args) void InputBar::toggleIgnore(const QString &user, const bool ignored) { - QSharedPointer 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 source_, diff --git a/src/ui/UserProfile.cpp b/src/ui/UserProfile.cpp index ffb69aa4..c7254e23 100644 --- a/src/ui/UserProfile.cpp +++ b/src/ui/UserProfile.cpp @@ -281,9 +281,12 @@ UserProfile::setIgnored(bool ignore) if (ignore) { const QHash 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); + } } } } -- cgit 1.4.1 From c4ab063aecc0d3c01c819a42792850a35a6a59f3 Mon Sep 17 00:00:00 2001 From: NepNep21 Date: Thu, 21 Dec 2023 22:05:24 -0300 Subject: deleteLater() on failure --- src/timeline/InputBar.cpp | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) (limited to 'src') diff --git a/src/timeline/InputBar.cpp b/src/timeline/InputBar.cpp index 7d5e8ba3..03ae5658 100644 --- a/src/timeline/InputBar.cpp +++ b/src/timeline/InputBar.cpp @@ -955,8 +955,9 @@ void InputBar::toggleIgnore(const QString &user, const bool ignored) { UserProfile *profile = new UserProfile(QString(), user, TimelineViewManager::instance()); - connect(profile, &UserProfile::failedToFetchProfile, [user] { + connect(profile, &UserProfile::failedToFetchProfile, [user, profile] { MainWindow::instance()->showNotification(tr("Failed to fetch user %1").arg(user)); + profile->deleteLater(); }); connect( -- cgit 1.4.1