Add reasons to everything

fixes #1030
pull/1033/head
Nicolas Werner 3 years ago
parent c91f91d5d3
commit a59b3147a6
No known key found for this signature in database
GPG Key ID: C8D75E610773F2D9
  1. 12
      man/nheko.1.adoc
  2. 5
      resources/qml/Root.qml
  3. 3
      resources/qml/dialogs/LeaveRoomDialog.qml
  4. 28
      src/ChatPage.cpp
  5. 9
      src/ChatPage.h
  6. 6
      src/timeline/InputBar.cpp
  7. 6
      src/timeline/RoomlistModel.cpp
  8. 4
      src/timeline/RoomlistModel.h
  9. 2
      src/timeline/TimelineViewManager.h
  10. 2
      src/ui/NhekoGlobalObject.h

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

@ -275,9 +275,10 @@ Pane {
destroyOnClose(dialog); destroyOnClose(dialog);
} }
function onOpenLeaveRoomDialog(roomid) { function onOpenLeaveRoomDialog(roomid, reason) {
var dialog = leaveRoomComponent.createObject(timelineRoot, { var dialog = leaveRoomComponent.createObject(timelineRoot, {
"roomId": roomid "roomId": roomid,
"reason": reason
}); });
dialog.open(); dialog.open();
destroyOnClose(dialog); destroyOnClose(dialog);

@ -12,10 +12,11 @@ P.MessageDialog {
id: leaveRoomRoot id: leaveRoomRoot
required property string roomId required property string roomId
property string reason: ""
title: qsTr("Leave room") title: qsTr("Leave room")
text: qsTr("Are you sure you want to leave?") text: qsTr("Are you sure you want to leave?")
modality: Qt.ApplicationModal modality: Qt.ApplicationModal
buttons: P.MessageDialog.Ok | P.MessageDialog.Cancel buttons: P.MessageDialog.Ok | P.MessageDialog.Cancel
onAccepted: Rooms.leave(roomId) onAccepted: Rooms.leave(roomId, reason)
} }

@ -659,7 +659,7 @@ ChatPage::trySync()
} }
void void
ChatPage::knockRoom(const QString &room) ChatPage::knockRoom(const QString &room, const QString &reason)
{ {
const auto room_id = room.toStdString(); const auto room_id = room.toStdString();
if (QMessageBox::Yes != if (QMessageBox::Yes !=
@ -668,26 +668,30 @@ ChatPage::knockRoom(const QString &room)
return; return;
http::client()->knock_room( 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) { if (err) {
emit showNotification(tr("Failed to knock room: %1") emit showNotification(tr("Failed to knock room: %1")
.arg(QString::fromStdString(err->matrix_error.error))); .arg(QString::fromStdString(err->matrix_error.error)));
return; return;
} }
}); },
reason.toStdString());
} }
void void
ChatPage::joinRoom(const QString &room) ChatPage::joinRoom(const QString &room, const QString &reason)
{ {
const auto room_id = room.toStdString(); const auto room_id = room.toStdString();
joinRoomVia(room_id, {}, false); joinRoomVia(room_id, {}, false, reason);
} }
void void
ChatPage::joinRoomVia(const std::string &room_id, ChatPage::joinRoomVia(const std::string &room_id,
const std::vector<std::string> &via, const std::vector<std::string> &via,
bool promptForConfirmation) bool promptForConfirmation,
const QString &reason)
{ {
if (promptForConfirmation && if (promptForConfirmation &&
QMessageBox::Yes != QMessageBox::Yes !=
@ -698,7 +702,9 @@ ChatPage::joinRoomVia(const std::string &room_id,
return; return;
http::client()->join_room( 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) { if (err) {
emit showNotification( emit showNotification(
tr("Failed to join room: %1").arg(QString::fromStdString(err->matrix_error.error))); 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)); view_manager_->rooms()->setCurrentRoom(QString::fromStdString(room_id));
}); },
reason.toStdString());
} }
void void
@ -740,7 +747,7 @@ ChatPage::createRoom(const mtx::requests::CreateRoom &req)
} }
void void
ChatPage::leaveRoom(const QString &room_id) ChatPage::leaveRoom(const QString &room_id, const QString &reason)
{ {
http::client()->leave_room( http::client()->leave_room(
room_id.toStdString(), room_id.toStdString(),
@ -762,7 +769,8 @@ ChatPage::leaveRoom(const QString &room_id)
} }
emit leftRoom(room_id); emit leftRoom(room_id);
}); },
reason.toStdString());
} }
void void

@ -81,13 +81,14 @@ public slots:
bool handleMatrixUri(const QUrl &uri); bool handleMatrixUri(const QUrl &uri);
void startChat(QString userid) { startChat(userid, std::nullopt); } 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 createRoom(const mtx::requests::CreateRoom &req);
void joinRoom(const QString &room); void joinRoom(const QString &room, const QString &reason = "");
void knockRoom(const QString &room); void knockRoom(const QString &room, const QString &reason = "");
void joinRoomVia(const std::string &room_id, void joinRoomVia(const std::string &room_id,
const std::vector<std::string> &via, const std::vector<std::string> &via,
bool promptForConfirmation = true); bool promptForConfirmation = true,
const QString &reason = "");
void inviteUser(QString userid, QString reason); void inviteUser(QString userid, QString reason);
void kickUser(QString userid, QString reason); void kickUser(QString userid, QString reason);

@ -669,11 +669,11 @@ InputBar::command(const QString &command, QString args)
if (!eventId.isEmpty()) if (!eventId.isEmpty())
reaction(eventId, args.trimmed()); reaction(eventId, args.trimmed());
} else if (command == QLatin1String("join")) { } 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")) { } 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")) { } 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")) { } else if (command == QLatin1String("invite")) {
ChatPage::instance()->inviteUser(args.section(' ', 0, 0), args.section(' ', 1, -1)); ChatPage::instance()->inviteUser(args.section(' ', 0, 0), args.section(' ', 1, -1));
} else if (command == QLatin1String("kick")) { } else if (command == QLatin1String("kick")) {

@ -659,12 +659,12 @@ RoomlistModel::declineInvite(QString roomid)
roomids.erase(roomids.begin() + idx); roomids.erase(roomids.begin() + idx);
invites.remove(roomid); invites.remove(roomid);
endRemoveRows(); endRemoveRows();
ChatPage::instance()->leaveRoom(roomid); ChatPage::instance()->leaveRoom(roomid, "");
} }
} }
} }
void void
RoomlistModel::leave(QString roomid) RoomlistModel::leave(QString roomid, QString reason)
{ {
if (models.contains(roomid)) { if (models.contains(roomid)) {
auto idx = roomidToIndex(roomid); auto idx = roomidToIndex(roomid);
@ -674,7 +674,7 @@ RoomlistModel::leave(QString roomid)
roomids.erase(roomids.begin() + idx); roomids.erase(roomids.begin() + idx);
models.remove(roomid); models.remove(roomid);
endRemoveRows(); endRemoveRows();
ChatPage::instance()->leaveRoom(roomid); ChatPage::instance()->leaveRoom(roomid, reason);
} }
} }
} }

@ -102,7 +102,7 @@ public slots:
void joinPreview(QString roomid, QString parentSpace); void joinPreview(QString roomid, QString parentSpace);
void acceptInvite(QString roomid); void acceptInvite(QString roomid);
void declineInvite(QString roomid); void declineInvite(QString roomid);
void leave(QString roomid); void leave(QString roomid, QString reason = "");
TimelineModel *currentRoom() const { return currentRoom_.get(); } TimelineModel *currentRoom() const { return currentRoom_.get(); }
RoomPreview currentRoomPreview() const { return currentRoomPreview_.value_or(RoomPreview{}); } RoomPreview currentRoomPreview() const { return currentRoomPreview_.value_or(RoomPreview{}); }
void setCurrentRoom(QString roomid); void setCurrentRoom(QString roomid);
@ -165,7 +165,7 @@ public slots:
} }
void acceptInvite(QString roomid) { roomlistmodel->acceptInvite(roomid); } void acceptInvite(QString roomid) { roomlistmodel->acceptInvite(roomid); }
void declineInvite(QString roomid) { roomlistmodel->declineInvite(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); void toggleTag(QString roomid, QString tag, bool on);
TimelineModel *currentRoom() const { return roomlistmodel->currentRoom(); } TimelineModel *currentRoom() const { return roomlistmodel->currentRoom(); }

@ -89,7 +89,7 @@ signals:
void openInviteUsersDialog(InviteesModel *invitees); void openInviteUsersDialog(InviteesModel *invitees);
void openProfile(UserProfile *profile); void openProfile(UserProfile *profile);
void showImagePackSettings(TimelineModel *room, ImagePackListModel *packlist); void showImagePackSettings(TimelineModel *room, ImagePackListModel *packlist);
void openLeaveRoomDialog(QString roomid); void openLeaveRoomDialog(QString roomid, QString reason);
void showImageOverlay(TimelineModel *room, QString eventId, QString url); void showImageOverlay(TimelineModel *room, QString eventId, QString url);
public slots: public slots:

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

Loading…
Cancel
Save