summary refs log tree commit diff
diff options
context:
space:
mode:
authorNepNep21 <43792621+NepNep21@users.noreply.github.com>2023-12-11 22:29:36 -0300
committerNepNep21 <43792621+NepNep21@users.noreply.github.com>2023-12-11 22:29:36 -0300
commit4695bbb34049d5e7f2c1193ef5e39f39afbd17c0 (patch)
treef1e86e09d0b5705c3234c9d7d70d4b37da1fdcab
parentFix joined spaces having no description (diff)
downloadnheko-4695bbb34049d5e7f2c1193ef5e39f39afbd17c0.tar.xz
Add /ignore
-rw-r--r--src/CommandCompleter.cpp6
-rw-r--r--src/CommandCompleter.h1
-rw-r--r--src/timeline/InputBar.cpp14
-rw-r--r--src/ui/UserProfile.cpp6
-rw-r--r--src/ui/UserProfile.h2
5 files changed, 28 insertions, 1 deletions
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<UserProfile> 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();