summary refs log tree commit diff
path: root/src
diff options
context:
space:
mode:
Diffstat (limited to 'src')
-rw-r--r--src/ChatPage.cpp99
-rw-r--r--src/TextInputWidget.cpp8
-rw-r--r--src/TextInputWidget.h4
3 files changed, 102 insertions, 9 deletions
diff --git a/src/ChatPage.cpp b/src/ChatPage.cpp
index c7739281..a337baac 100644
--- a/src/ChatPage.cpp
+++ b/src/ChatPage.cpp
@@ -208,12 +208,11 @@ ChatPage::ChatPage(QSharedPointer<UserSettings> userSettings, QWidget *parent)
                                                mtx::http::RequestErr err) {
                                           if (err) {
                                                   emit showNotification(
-                                                    QString("Failed to invite user: %1").arg(user));
+                                                    tr("Failed to invite user: %1").arg(user));
                                                   return;
                                           }
 
-                                          emit showNotification(
-                                            QString("Invited user: %1").arg(user));
+                                          emit showNotification(tr("Invited user: %1").arg(user));
                                   });
                         });
                 }
@@ -280,6 +279,89 @@ ChatPage::ChatPage(QSharedPointer<UserSettings> userSettings, QWidget *parent)
 
         connect(text_input_, &TextInputWidget::sendJoinRoomRequest, this, &ChatPage::joinRoom);
 
+        // invites and bans via quick command
+        connect(text_input_,
+                &TextInputWidget::sendInviteRoomRequest,
+                this,
+                [this](QString userid, QString reason) {
+                        http::client()->invite_user(
+                          current_room_.toStdString(),
+                          userid.toStdString(),
+                          [this, userid, room = current_room_](const mtx::responses::Empty &,
+                                                               mtx::http::RequestErr err) {
+                                  if (err) {
+                                          emit showNotification(tr("Failed to invite %1 to %2: %3")
+                                                                  .arg(userid)
+                                                                  .arg(room)
+                                                                  .arg(QString::fromStdString(
+                                                                    err->matrix_error.error)));
+                                  } else
+                                          emit showNotification(tr("Invited user: %1").arg(userid));
+                          },
+                          reason.trimmed().toStdString());
+                });
+        connect(text_input_,
+                &TextInputWidget::sendKickRoomRequest,
+                this,
+                [this](QString userid, QString reason) {
+                        http::client()->kick_user(
+                          current_room_.toStdString(),
+                          userid.toStdString(),
+                          [this, userid, room = current_room_](const mtx::responses::Empty &,
+                                                               mtx::http::RequestErr err) {
+                                  if (err) {
+                                          emit showNotification(tr("Failed to kick %1 to %2: %3")
+                                                                  .arg(userid)
+                                                                  .arg(room)
+                                                                  .arg(QString::fromStdString(
+                                                                    err->matrix_error.error)));
+                                  } else
+                                          emit showNotification(tr("Kicked user: %1").arg(userid));
+                          },
+                          reason.trimmed().toStdString());
+                });
+        connect(text_input_,
+                &TextInputWidget::sendBanRoomRequest,
+                this,
+                [this](QString userid, QString reason) {
+                        http::client()->ban_user(
+                          current_room_.toStdString(),
+                          userid.toStdString(),
+                          [this, userid, room = current_room_](const mtx::responses::Empty &,
+                                                               mtx::http::RequestErr err) {
+                                  if (err) {
+                                          emit showNotification(tr("Failed to ban %1 in %2: %3")
+                                                                  .arg(userid)
+                                                                  .arg(room)
+                                                                  .arg(QString::fromStdString(
+                                                                    err->matrix_error.error)));
+                                  } else
+                                          emit showNotification(tr("Banned user: %1").arg(userid));
+                          },
+                          reason.trimmed().toStdString());
+                });
+        connect(
+          text_input_,
+          &TextInputWidget::sendUnbanRoomRequest,
+          this,
+          [this](QString userid, QString reason) {
+                  http::client()->unban_user(
+                    current_room_.toStdString(),
+                    userid.toStdString(),
+                    [this, userid, room = current_room_](const mtx::responses::Empty &,
+                                                         mtx::http::RequestErr err) {
+                            if (err) {
+                                    emit showNotification(
+                                      tr("Failed to unban %1 in %2: %3")
+                                        .arg(userid)
+                                        .arg(room)
+                                        .arg(QString::fromStdString(err->matrix_error.error)));
+                            } else
+                                    emit showNotification(tr("Unbanned user: %1").arg(userid));
+                    },
+                    reason.trimmed().toStdString());
+          });
+
         connect(
           text_input_,
           &TextInputWidget::uploadMedia,
@@ -998,19 +1080,18 @@ ChatPage::joinRoom(const QString &room)
           room_id, [this, room_id](const nlohmann::json &, mtx::http::RequestErr err) {
                   if (err) {
                           emit showNotification(
-                            QString("Failed to join room: %1")
+                            tr("Failed to join room: %1")
                               .arg(QString::fromStdString(err->matrix_error.error)));
                           return;
                   }
 
-                  emit showNotification("You joined the room");
+                  emit tr("You joined the room");
 
                   // We remove any invites with the same room_id.
                   try {
                           cache::removeInvite(room_id);
                   } catch (const lmdb::error &e) {
-                          emit showNotification(
-                            QString("Failed to remove invite: %1").arg(e.what()));
+                          emit showNotification(tr("Failed to remove invite: %1").arg(e.what()));
                   }
           });
 }
@@ -1033,8 +1114,8 @@ ChatPage::createRoom(const mtx::requests::CreateRoom &req)
                           return;
                   }
 
-                  emit showNotification(QString("Room %1 created")
-                                          .arg(QString::fromStdString(res.room_id.to_string())));
+                  emit showNotification(
+                    tr("Room %1 created").arg(QString::fromStdString(res.room_id.to_string())));
           });
 }
 
diff --git a/src/TextInputWidget.cpp b/src/TextInputWidget.cpp
index b6b51980..52686c0f 100644
--- a/src/TextInputWidget.cpp
+++ b/src/TextInputWidget.cpp
@@ -605,6 +605,14 @@ TextInputWidget::command(QString command, QString args)
                 sendEmoteMessage(args, input_->related);
         } else if (command == "join") {
                 sendJoinRoomRequest(args);
+        } else if (command == "invite") {
+                sendInviteRoomRequest(args.section(' ', 0, 0), args.section(' ', 1, -1));
+        } else if (command == "kick") {
+                sendKickRoomRequest(args.section(' ', 0, 0), args.section(' ', 1, -1));
+        } else if (command == "ban") {
+                sendBanRoomRequest(args.section(' ', 0, 0), args.section(' ', 1, -1));
+        } else if (command == "unban") {
+                sendUnbanRoomRequest(args.section(' ', 0, 0), args.section(' ', 1, -1));
         } else if (command == "shrug") {
                 sendTextMessage("¯\\_(ツ)_/¯", input_->related);
         } else if (command == "fliptable") {
diff --git a/src/TextInputWidget.h b/src/TextInputWidget.h
index 6641d97c..4bdb2509 100644
--- a/src/TextInputWidget.h
+++ b/src/TextInputWidget.h
@@ -183,6 +183,10 @@ signals:
                          const std::optional<RelatedInfo> &related);
 
         void sendJoinRoomRequest(const QString &room);
+        void sendInviteRoomRequest(const QString &userid, const QString &reason);
+        void sendKickRoomRequest(const QString &userid, const QString &reason);
+        void sendBanRoomRequest(const QString &userid, const QString &reason);
+        void sendUnbanRoomRequest(const QString &userid, const QString &reason);
 
         void startedTyping();
         void stoppedTyping();