Add reasons to everything

fixes #1030
This commit is contained in:
Nicolas Werner 2022-03-30 23:38:38 +02:00
parent c91f91d5d3
commit a59b3147a6
No known key found for this signature in database
GPG key ID: C8D75E610773F2D9
10 changed files with 44 additions and 33 deletions

View file

@ -154,14 +154,14 @@ Send a message as a rainbow-colored notice.
=== Room management
*/join* _<roomname>_::
Join a room.
*/join* _<roomname>_ _[reason]_::
Join a room. _reason_ is optional.
*/knock* _<roomname>_::
Ask to join a room.
*/knock* _<roomname>_ _[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* _<username>_ _[reason]_::
Invite a user into the current room. _reason_ is optional.

View file

@ -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);

View file

@ -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)
}

View file

@ -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<std::string> &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

View file

@ -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<std::string> &via,
bool promptForConfirmation = true);
bool promptForConfirmation = true,
const QString &reason = "");
void inviteUser(QString userid, QString reason);
void kickUser(QString userid, QString reason);

View file

@ -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")) {

View file

@ -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);
}
}
}

View file

@ -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(); }

View file

@ -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:

View file

@ -64,7 +64,7 @@ signals:
void openLogoutDialog();
void openJoinRoomDialog();
void joinRoom(QString roomId);
void joinRoom(QString roomId, QString reason = "");
private:
QScopedPointer<UserProfile> currentUser_;