From 083562a7d8befa38ba9c3736b64e1530c04c1ed3 Mon Sep 17 00:00:00 2001
From: tastytea <tastytea@tastytea.de>
Date: Sun, 6 Mar 2022 15:59:32 +0100
Subject: [PATCH] Add GUI for specifying kick/ban reason

This replaces the are-you-sure dialog and also shows up when using
/-commands.

Closes: https://github.com/Nheko-Reborn/nheko/issues/239

# Previous commits:
#   e390c398 Allow to specify reason for removed message
#   5949173b Add function to force focus on InputDialog input field
#   9482ac4e Allow explicit selection of SSO method
#   ab05e2d8 Mobile message input (#962)
---
 src/ChatPage.cpp | 31 ++++++++++++++++++++++---------
 1 file changed, 22 insertions(+), 9 deletions(-)

diff --git a/src/ChatPage.cpp b/src/ChatPage.cpp
index cdaf72600..3743eae08 100644
--- a/src/ChatPage.cpp
+++ b/src/ChatPage.cpp
@@ -785,11 +785,18 @@ ChatPage::kickUser(QString userid, QString reason)
 {
     auto room = currentRoom();
 
-    if (QMessageBox::question(nullptr,
-                              tr("Confirm kick"),
-                              tr("Do you really want to kick %1 (%2)?")
-                                .arg(cache::displayName(room, userid), userid)) != QMessageBox::Yes)
+    bool confirmed;
+    reason =
+      QInputDialog::getText(nullptr,
+                            tr("Reason for the kick"),
+                            tr("Enter reason for kicking %1 (%2) or hit enter for no reason:")
+                              .arg(cache::displayName(room, userid), userid),
+                            QLineEdit::Normal,
+                            reason,
+                            &confirmed);
+    if (!confirmed) {
         return;
+    }
 
     http::client()->kick_user(
       room.toStdString(),
@@ -809,12 +816,18 @@ ChatPage::banUser(QString userid, QString reason)
 {
     auto room = currentRoom();
 
-    if (QMessageBox::question(
-          nullptr,
-          tr("Confirm ban"),
-          tr("Do you really want to ban %1 (%2)?").arg(cache::displayName(room, userid), userid)) !=
-        QMessageBox::Yes)
+    bool confirmed;
+    reason =
+      QInputDialog::getText(nullptr,
+                            tr("Reason for the ban"),
+                            tr("Enter reason for banning %1 (%2) or hit enter for no reason:")
+                              .arg(cache::displayName(room, userid), userid),
+                            QLineEdit::Normal,
+                            reason,
+                            &confirmed);
+    if (!confirmed) {
         return;
+    }
 
     http::client()->ban_user(
       room.toStdString(),
-- 
GitLab