From a59b3147a68ab67629d76d1c18d53950bfeb0277 Mon Sep 17 00:00:00 2001 From: Nicolas Werner Date: Wed, 30 Mar 2022 23:38:38 +0200 Subject: [PATCH] Add reasons to everything fixes #1030 --- man/nheko.1.adoc | 12 +++++----- resources/qml/Root.qml | 5 ++-- resources/qml/dialogs/LeaveRoomDialog.qml | 3 ++- src/ChatPage.cpp | 28 +++++++++++++++-------- src/ChatPage.h | 9 ++++---- src/timeline/InputBar.cpp | 6 ++--- src/timeline/RoomlistModel.cpp | 6 ++--- src/timeline/RoomlistModel.h | 4 ++-- src/timeline/TimelineViewManager.h | 2 +- src/ui/NhekoGlobalObject.h | 2 +- 10 files changed, 44 insertions(+), 33 deletions(-) diff --git a/man/nheko.1.adoc b/man/nheko.1.adoc index d04d37fe..bef889e3 100644 --- a/man/nheko.1.adoc +++ b/man/nheko.1.adoc @@ -154,14 +154,14 @@ Send a message as a rainbow-colored notice. === Room management -*/join* __:: -Join a room. +*/join* __ _[reason]_:: +Join a room. _reason_ is optional. -*/knock* __:: -Ask to join a room. +*/knock* __ _[reason]_:: +Ask to join a room. _reason_ is optional. -*/part*, */leave*:: -Leave the current room. +*/part*, */leave* _[reason]_:: +Leave the current room. _reason_ is optional. */invite* __ _[reason]_:: Invite a user into the current room. _reason_ is optional. diff --git a/resources/qml/Root.qml b/resources/qml/Root.qml index 98212c83..cd97cce2 100644 --- a/resources/qml/Root.qml +++ b/resources/qml/Root.qml @@ -275,9 +275,10 @@ Pane { destroyOnClose(dialog); } - function onOpenLeaveRoomDialog(roomid) { + function onOpenLeaveRoomDialog(roomid, reason) { var dialog = leaveRoomComponent.createObject(timelineRoot, { - "roomId": roomid + "roomId": roomid, + "reason": reason }); dialog.open(); destroyOnClose(dialog); diff --git a/resources/qml/dialogs/LeaveRoomDialog.qml b/resources/qml/dialogs/LeaveRoomDialog.qml index d35025a7..d64b2d31 100644 --- a/resources/qml/dialogs/LeaveRoomDialog.qml +++ b/resources/qml/dialogs/LeaveRoomDialog.qml @@ -12,10 +12,11 @@ P.MessageDialog { id: leaveRoomRoot required property string roomId + property string reason: "" title: qsTr("Leave room") text: qsTr("Are you sure you want to leave?") modality: Qt.ApplicationModal buttons: P.MessageDialog.Ok | P.MessageDialog.Cancel - onAccepted: Rooms.leave(roomId) + onAccepted: Rooms.leave(roomId, reason) } diff --git a/src/ChatPage.cpp b/src/ChatPage.cpp index a7d5bf64..a3469a69 100644 --- a/src/ChatPage.cpp +++ b/src/ChatPage.cpp @@ -659,7 +659,7 @@ ChatPage::trySync() } void -ChatPage::knockRoom(const QString &room) +ChatPage::knockRoom(const QString &room, const QString &reason) { const auto room_id = room.toStdString(); if (QMessageBox::Yes != @@ -668,26 +668,30 @@ ChatPage::knockRoom(const QString &room) return; http::client()->knock_room( - room_id, {}, [this, room_id](const mtx::responses::RoomId &, mtx::http::RequestErr err) { + room_id, + {}, + [this, room_id](const mtx::responses::RoomId &, mtx::http::RequestErr err) { if (err) { emit showNotification(tr("Failed to knock room: %1") .arg(QString::fromStdString(err->matrix_error.error))); return; } - }); + }, + reason.toStdString()); } void -ChatPage::joinRoom(const QString &room) +ChatPage::joinRoom(const QString &room, const QString &reason) { const auto room_id = room.toStdString(); - joinRoomVia(room_id, {}, false); + joinRoomVia(room_id, {}, false, reason); } void ChatPage::joinRoomVia(const std::string &room_id, const std::vector &via, - bool promptForConfirmation) + bool promptForConfirmation, + const QString &reason) { if (promptForConfirmation && QMessageBox::Yes != @@ -698,7 +702,9 @@ ChatPage::joinRoomVia(const std::string &room_id, return; http::client()->join_room( - room_id, via, [this, room_id](const mtx::responses::RoomId &, mtx::http::RequestErr err) { + room_id, + via, + [this, room_id](const mtx::responses::RoomId &, mtx::http::RequestErr err) { if (err) { emit showNotification( tr("Failed to join room: %1").arg(QString::fromStdString(err->matrix_error.error))); @@ -713,7 +719,8 @@ ChatPage::joinRoomVia(const std::string &room_id, } view_manager_->rooms()->setCurrentRoom(QString::fromStdString(room_id)); - }); + }, + reason.toStdString()); } void @@ -740,7 +747,7 @@ ChatPage::createRoom(const mtx::requests::CreateRoom &req) } void -ChatPage::leaveRoom(const QString &room_id) +ChatPage::leaveRoom(const QString &room_id, const QString &reason) { http::client()->leave_room( room_id.toStdString(), @@ -762,7 +769,8 @@ ChatPage::leaveRoom(const QString &room_id) } emit leftRoom(room_id); - }); + }, + reason.toStdString()); } void diff --git a/src/ChatPage.h b/src/ChatPage.h index cfa6f275..f2249637 100644 --- a/src/ChatPage.h +++ b/src/ChatPage.h @@ -81,13 +81,14 @@ public slots: bool handleMatrixUri(const QUrl &uri); void startChat(QString userid) { startChat(userid, std::nullopt); } - void leaveRoom(const QString &room_id); + void leaveRoom(const QString &room_id, const QString &reason); void createRoom(const mtx::requests::CreateRoom &req); - void joinRoom(const QString &room); - void knockRoom(const QString &room); + void joinRoom(const QString &room, const QString &reason = ""); + void knockRoom(const QString &room, const QString &reason = ""); void joinRoomVia(const std::string &room_id, const std::vector &via, - bool promptForConfirmation = true); + bool promptForConfirmation = true, + const QString &reason = ""); void inviteUser(QString userid, QString reason); void kickUser(QString userid, QString reason); diff --git a/src/timeline/InputBar.cpp b/src/timeline/InputBar.cpp index 4116729d..1de7a141 100644 --- a/src/timeline/InputBar.cpp +++ b/src/timeline/InputBar.cpp @@ -669,11 +669,11 @@ InputBar::command(const QString &command, QString args) if (!eventId.isEmpty()) reaction(eventId, args.trimmed()); } else if (command == QLatin1String("join")) { - ChatPage::instance()->joinRoom(args); + ChatPage::instance()->joinRoom(args.section(' ', 0, 0), args.section(' ', 1, -1)); } else if (command == QLatin1String("knock")) { - ChatPage::instance()->knockRoom(args); + ChatPage::instance()->knockRoom(args.section(' ', 0, 0), args.section(' ', 1, -1)); } else if (command == QLatin1String("part") || command == QLatin1String("leave")) { - ChatPage::instance()->timelineManager()->openLeaveRoomDialog(room->roomId()); + ChatPage::instance()->timelineManager()->openLeaveRoomDialog(room->roomId(), args); } else if (command == QLatin1String("invite")) { ChatPage::instance()->inviteUser(args.section(' ', 0, 0), args.section(' ', 1, -1)); } else if (command == QLatin1String("kick")) { diff --git a/src/timeline/RoomlistModel.cpp b/src/timeline/RoomlistModel.cpp index 3846b643..31e5a33d 100644 --- a/src/timeline/RoomlistModel.cpp +++ b/src/timeline/RoomlistModel.cpp @@ -659,12 +659,12 @@ RoomlistModel::declineInvite(QString roomid) roomids.erase(roomids.begin() + idx); invites.remove(roomid); endRemoveRows(); - ChatPage::instance()->leaveRoom(roomid); + ChatPage::instance()->leaveRoom(roomid, ""); } } } void -RoomlistModel::leave(QString roomid) +RoomlistModel::leave(QString roomid, QString reason) { if (models.contains(roomid)) { auto idx = roomidToIndex(roomid); @@ -674,7 +674,7 @@ RoomlistModel::leave(QString roomid) roomids.erase(roomids.begin() + idx); models.remove(roomid); endRemoveRows(); - ChatPage::instance()->leaveRoom(roomid); + ChatPage::instance()->leaveRoom(roomid, reason); } } } diff --git a/src/timeline/RoomlistModel.h b/src/timeline/RoomlistModel.h index 2476b21b..73ccd929 100644 --- a/src/timeline/RoomlistModel.h +++ b/src/timeline/RoomlistModel.h @@ -102,7 +102,7 @@ public slots: void joinPreview(QString roomid, QString parentSpace); void acceptInvite(QString roomid); void declineInvite(QString roomid); - void leave(QString roomid); + void leave(QString roomid, QString reason = ""); TimelineModel *currentRoom() const { return currentRoom_.get(); } RoomPreview currentRoomPreview() const { return currentRoomPreview_.value_or(RoomPreview{}); } void setCurrentRoom(QString roomid); @@ -165,7 +165,7 @@ public slots: } void acceptInvite(QString roomid) { roomlistmodel->acceptInvite(roomid); } void declineInvite(QString roomid) { roomlistmodel->declineInvite(roomid); } - void leave(QString roomid) { roomlistmodel->leave(roomid); } + void leave(QString roomid, QString reason = "") { roomlistmodel->leave(roomid, reason); } void toggleTag(QString roomid, QString tag, bool on); TimelineModel *currentRoom() const { return roomlistmodel->currentRoom(); } diff --git a/src/timeline/TimelineViewManager.h b/src/timeline/TimelineViewManager.h index 07ebfe79..df622ac6 100644 --- a/src/timeline/TimelineViewManager.h +++ b/src/timeline/TimelineViewManager.h @@ -89,7 +89,7 @@ signals: void openInviteUsersDialog(InviteesModel *invitees); void openProfile(UserProfile *profile); void showImagePackSettings(TimelineModel *room, ImagePackListModel *packlist); - void openLeaveRoomDialog(QString roomid); + void openLeaveRoomDialog(QString roomid, QString reason); void showImageOverlay(TimelineModel *room, QString eventId, QString url); public slots: diff --git a/src/ui/NhekoGlobalObject.h b/src/ui/NhekoGlobalObject.h index 1139cf31..cfcf31fb 100644 --- a/src/ui/NhekoGlobalObject.h +++ b/src/ui/NhekoGlobalObject.h @@ -64,7 +64,7 @@ signals: void openLogoutDialog(); void openJoinRoomDialog(); - void joinRoom(QString roomId); + void joinRoom(QString roomId, QString reason = ""); private: QScopedPointer currentUser_;