From 5949173ba29d2d2825a82b1178bbfbee321c7759 Mon Sep 17 00:00:00 2001 From: tastytea Date: Sun, 6 Mar 2022 14:48:31 +0100 Subject: [PATCH 1/3] Add function to force focus on InputDialog input field # Previous commits: # 9482ac4e Allow explicit selection of SSO method # ab05e2d8 Mobile message input (#962) # 12a6da01 If you replace the txn id, replace a string the length of the txn id... # df6a5aab Fix clicking on images in replies --- resources/qml/dialogs/InputDialog.qml | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/resources/qml/dialogs/InputDialog.qml b/resources/qml/dialogs/InputDialog.qml index cf1474dc..a674c3fb 100644 --- a/resources/qml/dialogs/InputDialog.qml +++ b/resources/qml/dialogs/InputDialog.qml @@ -21,6 +21,10 @@ ApplicationWindow { width: 350 height: fontMetrics.lineSpacing * 7 + function forceActiveFocus() { + statusInput.forceActiveFocus(); + } + Shortcut { sequence: StandardKey.Cancel onActivated: dbb.rejected() From e390c398626b5f6e885078de9ab14186e3c0c27e Mon Sep 17 00:00:00 2001 From: tastytea Date: Sun, 6 Mar 2022 14:46:52 +0100 Subject: [PATCH 2/3] Allow to specify reason for removed message # Previous commits: # 5949173b Add function to force focus on InputDialog input field # 9482ac4e Allow explicit selection of SSO method # ab05e2d8 Mobile message input (#962) # 12a6da01 If you replace the txn id, replace a string the length of the txn id... --- resources/qml/MessageView.qml | 24 +++++++++++++++++++++++- src/timeline/TimelineModel.cpp | 8 +++++--- src/timeline/TimelineModel.h | 2 +- 3 files changed, 29 insertions(+), 5 deletions(-) diff --git a/resources/qml/MessageView.qml b/resources/qml/MessageView.qml index a717cb31..55860ad6 100644 --- a/resources/qml/MessageView.qml +++ b/resources/qml/MessageView.qml @@ -7,6 +7,7 @@ import "./components" import "./delegates" import "./emoji" import "./ui" +import "./dialogs" import Qt.labs.platform 1.1 as Platform import QtQuick 2.15 import QtQuick.Controls 2.15 @@ -585,6 +586,21 @@ Item { open(); } + Component { + id: removeReason + InputDialog { + id: removeReasonDialog + + property string eventId + + title: qsTr("Reason for removal") + prompt: qsTr("Enter reason for removal or hit enter for no reason:") + onAccepted: function(text) { + room.redactEvent(eventId, text); + } + } + } + Platform.MenuItem { visible: messageContextMenu.text enabled: visible @@ -665,7 +681,13 @@ Item { Platform.MenuItem { visible: (room ? room.permissions.canRedact() : false) || messageContextMenu.isSender text: qsTr("Remo&ve message") - onTriggered: room.redactEvent(messageContextMenu.eventId) + onTriggered: function() { + var dialog = removeReason.createObject(timelineRoot); + dialog.eventId = messageContextMenu.eventId; + dialog.show(); + dialog.forceActiveFocus(); + timelineRoot.destroyOnClose(dialog); + } } Platform.MenuItem { diff --git a/src/timeline/TimelineModel.cpp b/src/timeline/TimelineModel.cpp index 903f137f..8e6c7235 100644 --- a/src/timeline/TimelineModel.cpp +++ b/src/timeline/TimelineModel.cpp @@ -1240,7 +1240,7 @@ TimelineModel::showReadReceipts(QString id) } void -TimelineModel::redactEvent(const QString &id) +TimelineModel::redactEvent(const QString &id, const QString &reason) { if (!id.isEmpty()) { auto edits = events.edits(id.toStdString()); @@ -1255,7 +1255,8 @@ TimelineModel::redactEvent(const QString &id) } emit dataAtIdChanged(id); - }); + }, + reason.toStdString()); // redact all edits to prevent leaks for (const auto &e : edits) { @@ -1271,7 +1272,8 @@ TimelineModel::redactEvent(const QString &id) } emit dataAtIdChanged(id); - }); + }, + reason.toStdString()); } } } diff --git a/src/timeline/TimelineModel.h b/src/timeline/TimelineModel.h index e4e3fa9d..f47203f0 100644 --- a/src/timeline/TimelineModel.h +++ b/src/timeline/TimelineModel.h @@ -272,7 +272,7 @@ public: Q_INVOKABLE void unpin(const QString &id); Q_INVOKABLE void pin(const QString &id); Q_INVOKABLE void showReadReceipts(QString id); - Q_INVOKABLE void redactEvent(const QString &id); + Q_INVOKABLE void redactEvent(const QString &id, const QString &reason = ""); Q_INVOKABLE int idToIndex(const QString &id) const; Q_INVOKABLE QString indexToId(int index) const; Q_INVOKABLE void openMedia(const QString &eventId); From 083562a7d8befa38ba9c3736b64e1530c04c1ed3 Mon Sep 17 00:00:00 2001 From: tastytea Date: Sun, 6 Mar 2022 15:59:32 +0100 Subject: [PATCH 3/3] 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 cdaf7260..3743eae0 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(),