diff --git a/src/ChatPage.cpp b/src/ChatPage.cpp index d0ca4670..90abc63e 100644 --- a/src/ChatPage.cpp +++ b/src/ChatPage.cpp @@ -300,6 +300,29 @@ ChatPage::ChatPage(QSharedPointer userSettings, QWidget *parent) connect(text_input_, &TextInputWidget::sendBanRoomRequest, this, &ChatPage::banUser); connect(text_input_, &TextInputWidget::sendUnbanRoomRequest, this, &ChatPage::unbanUser); + connect( + text_input_, &TextInputWidget::changeRoomNick, this, [this](const QString &displayName) { + mtx::events::state::Member member; + member.display_name = displayName.toStdString(); + member.avatar_url = + cache::avatarUrl(currentRoom(), + QString::fromStdString(http::client()->user_id().to_string())) + .toStdString(); + member.membership = mtx::events::state::Membership::Join; + + http::client() + ->send_state_event( + currentRoom().toStdString(), + http::client()->user_id().to_string(), + member, + [](mtx::responses::EventId, mtx::http::RequestErr err) { + if (err) + nhlog::net()->error("Failed to set room displayname: {}", + err->matrix_error.error); + }); + }); + connect( text_input_, &TextInputWidget::uploadMedia, diff --git a/src/TextInputWidget.cpp b/src/TextInputWidget.cpp index af5c278e..d2359910 100644 --- a/src/TextInputWidget.cpp +++ b/src/TextInputWidget.cpp @@ -576,6 +576,8 @@ TextInputWidget::command(QString command, QString args) sendBanRoomRequest(args.section(' ', 0, 0), args.section(' ', 1, -1)); } else if (command == "unban") { sendUnbanRoomRequest(args.section(' ', 0, 0), args.section(' ', 1, -1)); + } else if (command == "roomnick") { + changeRoomNick(args); } else if (command == "shrug") { sendTextMessage("¯\\_(ツ)_/¯"); } else if (command == "fliptable") { diff --git a/src/TextInputWidget.h b/src/TextInputWidget.h index addb61ec..a0105eb0 100644 --- a/src/TextInputWidget.h +++ b/src/TextInputWidget.h @@ -167,6 +167,7 @@ signals: void sendKickRoomRequest(const QString &userid, const QString &reason); void sendBanRoomRequest(const QString &userid, const QString &reason); void sendUnbanRoomRequest(const QString &userid, const QString &reason); + void changeRoomNick(const QString &displayname); void startedTyping(); void stoppedTyping();