summary refs log tree commit diff
path: root/src/ui/RoomSummary.cpp
diff options
context:
space:
mode:
authorNicolas Werner <nicolas.werner@hotmail.de>2022-08-05 21:44:40 +0200
committerNicolas Werner <nicolas.werner@hotmail.de>2022-08-05 21:57:54 +0200
commit9d8d6b4bcaec0994776bf91a556a7e27cb862c30 (patch)
tree5d0220c3ea1681221eb99d79231fe753175b70af /src/ui/RoomSummary.cpp
parentAdd notification authorization for badges on macOS (diff)
downloadnheko-9d8d6b4bcaec0994776bf91a556a7e27cb862c30.tar.xz
Show a room preview in the join confirmation dialog
Requires MSC3266

Fixes #1129
Diffstat (limited to 'src/ui/RoomSummary.cpp')
-rw-r--r--src/ui/RoomSummary.cpp54
1 files changed, 54 insertions, 0 deletions
diff --git a/src/ui/RoomSummary.cpp b/src/ui/RoomSummary.cpp
new file mode 100644

index 00000000..dc035fe0 --- /dev/null +++ b/src/ui/RoomSummary.cpp
@@ -0,0 +1,54 @@ +// SPDX-FileCopyrightText: 2022 Nheko Contributors +// +// SPDX-License-Identifier: GPL-3.0-or-later + +#include "RoomSummary.h" + +#include <QMetaType> + +#include "ChatPage.h" +#include "MatrixClient.h" + +RoomSummary::RoomSummary(std::string roomIdOrAlias_, + std::vector<std::string> vias_, + QString r_, + QObject *p) + : QObject(p) + , roomIdOrAlias(std::move(roomIdOrAlias_)) + , vias(std::move(vias_)) + , reason_(std::move(r_)) +{ + auto ctx = std::make_shared<RoomSummaryProxy>(); + + connect(ctx.get(), &RoomSummaryProxy::failed, this, [this]() { + loaded_ = true; + emit loaded(); + }); + connect( + ctx.get(), &RoomSummaryProxy::loaded, this, [this](const mtx::responses::PublicRoom &resp) { + loaded_ = true; + room = resp; + emit loaded(); + }); + + http::client()->get_summary( + roomIdOrAlias, + [proxy = std::move(ctx)](const mtx::responses::PublicRoom &room, mtx::http::RequestErr e) { + if (e) { + emit proxy->failed(); + } else { + emit proxy->loaded(room); + } + }, + vias); +} + +void +RoomSummary::join() +{ + if (isKnockOnly()) + ChatPage::instance()->knockRoom( + QString::fromStdString(roomIdOrAlias), vias, reason_, false, false); + else + ChatPage::instance()->joinRoomVia(roomIdOrAlias, vias, false, reason_); +}