Debian Codegraph @

src/ui/RoomSummary.cpp

raw symbols SCIP
1 // SPDX-FileCopyrightText: Nheko Contributors
2 //
3 // SPDX-License-Identifier: GPL-3.0-or-later
4
5 #include "RoomSummary.h"
6
7 #include <QMetaType>
8
9 #include "Cache.h"
10 #include "ChatPage.h"
11 #include "MatrixClient.h"
12 #include "Utils.h"
13
14 RoomSummary::RoomSummary(std::string roomIdOrAlias_,
15 std::vector<std::string> vias_,
16 QString r_,
17 QObject *p)
18 : QObject(p)
19 , roomIdOrAlias(std::move(roomIdOrAlias_))
20 , vias(std::move(vias_))
21 , reason_(std::move(r_))
22 {
23 if (roomIdOrAlias.empty())
24 return;
25
26 if (roomIdOrAlias[0] == '!') {
27 auto temp = cache::singleRoomInfo(roomIdOrAlias);
28
29 if (temp.member_count) {
30 mtx::responses::PublicRoom newInfo{};
31 // newInfo.aliases;
32 // newInfo.canonical_alias = "";
33 newInfo.name = temp.name;
34 newInfo.room_id = roomIdOrAlias;
35 newInfo.topic = temp.topic;
36 newInfo.num_joined_members = temp.member_count;
37 // newInfo.world_readable;
38 newInfo.guest_can_join = temp.guest_access;
39 newInfo.avatar_url = temp.avatar_url;
40
41 newInfo.join_rule = temp.join_rule;
42 newInfo.room_type = temp.is_space ? mtx::events::state::room_type::space : "";
43 newInfo.room_version = temp.version;
44 newInfo.membership = mtx::events::state::Membership::Join;
45 // newInfo.encryption;
46
47 this->room = std::move(newInfo);
48 loaded_ = true;
49 return;
50 }
51
52 // newInfo.encryption;
53 }
54
55 auto ctx = std::make_shared<RoomSummaryProxy>();
56
57 connect(ctx.get(), &RoomSummaryProxy::failed, this, [this]() {
58 loaded_ = true;
59 emit loaded();
60 });
61 connect(
62 ctx.get(), &RoomSummaryProxy::loaded, this, [this](const mtx::responses::PublicRoom &resp) {
63 loaded_ = true;
64 room = resp;
65 emit loaded();
66 });
67
68 http::client()->get_summary(
69 roomIdOrAlias,
70 [proxy = std::move(ctx)](const mtx::responses::PublicRoom &room_, mtx::http::RequestErr e) {
71 if (e) {
72 emit proxy->failed();
73 } else {
74 emit proxy->loaded(room_);
75 }
76 },
77 vias);
78 }
79
80 QString
81 RoomSummary::roomName() const
82 {
83 return utils::replaceEmoji(
84 QString::fromStdString(room ? room->name : roomIdOrAlias).toHtmlEscaped());
85 }
86 QString
87 RoomSummary::roomTopic() const
88 {
89 return room ? utils::replaceEmoji(
90 utils::linkifyMessage(QString::fromStdString(room->topic)
91 .toHtmlEscaped()
92 .replace(QLatin1String("\n"), QLatin1String("<br>"))))
93 : "";
94 }
95
96 void
97 RoomSummary::join()
98 {
99 if (isKnockOnly())
100 ChatPage::instance()->knockRoom(
101 QString::fromStdString(roomIdOrAlias), vias, reason_, false, false);
102 else
103 ChatPage::instance()->joinRoomVia(roomIdOrAlias, vias, false, reason_);
104 }
105
106 void
107 RoomSummary::promptJoin()
108 {
109 if (isKnockOnly())
110 ChatPage::instance()->knockRoom(
111 QString::fromStdString(roomIdOrAlias), vias, reason_, false, true);
112 else
113 ChatPage::instance()->joinRoomVia(roomIdOrAlias, vias, true, reason_);
114 }
115
116 #include "moc_RoomSummary.cpp"