mirror of
https://github.com/Nheko-Reborn/nheko.git
synced 2024-11-25 20:48:52 +03:00
Fetch previews for space children using /hierarchy
This commit is contained in:
parent
fcefdb7ca6
commit
112426e30b
4 changed files with 52 additions and 48 deletions
|
@ -402,7 +402,7 @@ if(USE_BUNDLED_MTXCLIENT)
|
||||||
FetchContent_Declare(
|
FetchContent_Declare(
|
||||||
MatrixClient
|
MatrixClient
|
||||||
GIT_REPOSITORY https://github.com/Nheko-Reborn/mtxclient.git
|
GIT_REPOSITORY https://github.com/Nheko-Reborn/mtxclient.git
|
||||||
GIT_TAG 9781553b0186f2db9036d2abbde83c28828eb2b9
|
GIT_TAG dc55f64862aeaf02d75383fbdadcbf64ea585506
|
||||||
)
|
)
|
||||||
set(BUILD_LIB_EXAMPLES OFF CACHE INTERNAL "")
|
set(BUILD_LIB_EXAMPLES OFF CACHE INTERNAL "")
|
||||||
set(BUILD_LIB_TESTS OFF CACHE INTERNAL "")
|
set(BUILD_LIB_TESTS OFF CACHE INTERNAL "")
|
||||||
|
|
|
@ -191,7 +191,7 @@ modules:
|
||||||
buildsystem: cmake-ninja
|
buildsystem: cmake-ninja
|
||||||
name: mtxclient
|
name: mtxclient
|
||||||
sources:
|
sources:
|
||||||
- commit: 9781553b0186f2db9036d2abbde83c28828eb2b9
|
- commit: dc55f64862aeaf02d75383fbdadcbf64ea585506
|
||||||
#tag: v0.6.1
|
#tag: v0.6.1
|
||||||
type: git
|
type: git
|
||||||
url: https://github.com/Nheko-Reborn/mtxclient.git
|
url: https://github.com/Nheko-Reborn/mtxclient.git
|
||||||
|
|
|
@ -207,7 +207,6 @@ RoomlistModel::data(const QModelIndex &index, int role) const
|
||||||
else if (role == Roles::IsPreviewFetched)
|
else if (role == Roles::IsPreviewFetched)
|
||||||
return false;
|
return false;
|
||||||
|
|
||||||
fetchPreview(roomid);
|
|
||||||
switch (role) {
|
switch (role) {
|
||||||
case Roles::AvatarUrl:
|
case Roles::AvatarUrl:
|
||||||
return QString();
|
return QString();
|
||||||
|
@ -386,56 +385,60 @@ RoomlistModel::addRoom(const QString &room_id, bool suppressInsertNotification)
|
||||||
}
|
}
|
||||||
|
|
||||||
void
|
void
|
||||||
RoomlistModel::fetchPreview(QString roomid_) const
|
RoomlistModel::fetchPreviews(QString roomid_, const std::string &from)
|
||||||
{
|
{
|
||||||
std::string roomid = roomid_.toStdString();
|
auto roomid = roomid_.toStdString();
|
||||||
http::client()->get_state_event<mtx::events::state::Create>(
|
if (from.empty()) {
|
||||||
roomid, "", [this, roomid](const mtx::events::state::Create &c, mtx::http::RequestErr err) {
|
// check if we need to fetch anything
|
||||||
bool is_space = false;
|
auto children = cache::client()->getChildRoomIds(roomid);
|
||||||
if (!err) {
|
bool fetch = false;
|
||||||
is_space = c.type == mtx::events::state::room_type::space;
|
for (const auto &c : children) {
|
||||||
|
auto id = QString::fromStdString(c);
|
||||||
|
if (invites.contains(id) || models.contains(id) ||
|
||||||
|
(previewedRooms.contains(id) && previewedRooms.value(id).has_value()))
|
||||||
|
continue;
|
||||||
|
else {
|
||||||
|
fetch = true;
|
||||||
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
http::client()->get_state_event<mtx::events::state::Avatar>(
|
|
||||||
roomid,
|
|
||||||
"",
|
|
||||||
[this, roomid, is_space](const mtx::events::state::Avatar &a, mtx::http::RequestErr) {
|
|
||||||
auto avatar_url = a.url;
|
|
||||||
|
|
||||||
http::client()->get_state_event<mtx::events::state::Topic>(
|
|
||||||
roomid,
|
|
||||||
"",
|
|
||||||
[this, roomid, avatar_url, is_space](const mtx::events::state::Topic &t,
|
|
||||||
mtx::http::RequestErr) {
|
|
||||||
auto topic = t.topic;
|
|
||||||
http::client()->get_state_event<mtx::events::state::Name>(
|
|
||||||
roomid,
|
|
||||||
"",
|
|
||||||
[this, roomid, topic, avatar_url, is_space](
|
|
||||||
const mtx::events::state::Name &n, mtx::http::RequestErr err) {
|
|
||||||
if (err) {
|
|
||||||
nhlog::net()->warn("Failed to fetch name event to "
|
|
||||||
"create preview for {}",
|
|
||||||
roomid);
|
|
||||||
}
|
}
|
||||||
|
if (!fetch) {
|
||||||
// don't even add a preview, if we got not a single
|
nhlog::net()->info("Not feching previews for children of {}", roomid);
|
||||||
// response
|
|
||||||
if (n.name.empty() && avatar_url.empty() && topic.empty())
|
|
||||||
return;
|
return;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
nhlog::net()->info("Feching previews for children of {}", roomid);
|
||||||
|
http::client()->get_hierarchy(
|
||||||
|
roomid,
|
||||||
|
[this, roomid, roomid_](const mtx::responses::HierarchyRooms &h, mtx::http::RequestErr err) {
|
||||||
|
if (err) {
|
||||||
|
nhlog::net()->error("Failed to fetch previews for children of {}: {}", roomid, *err);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
nhlog::net()->info("Feched previews for children of {}: {}", roomid, h.rooms.size());
|
||||||
|
|
||||||
|
for (const auto &e : h.rooms) {
|
||||||
RoomInfo info{};
|
RoomInfo info{};
|
||||||
info.name = n.name;
|
info.name = e.name;
|
||||||
info.is_space = is_space;
|
info.is_space = e.room_type == mtx::events::state::room_type::space;
|
||||||
info.avatar_url = avatar_url;
|
info.avatar_url = e.avatar_url;
|
||||||
info.topic = topic;
|
info.topic = e.topic;
|
||||||
|
info.guest_access = e.guest_can_join;
|
||||||
|
info.join_rule = e.join_rule;
|
||||||
|
info.member_count = e.num_joined_members;
|
||||||
|
|
||||||
const_cast<RoomlistModel *>(this)->fetchedPreview(
|
emit fetchedPreview(QString::fromStdString(e.room_id), info);
|
||||||
QString::fromStdString(roomid), info);
|
}
|
||||||
});
|
|
||||||
});
|
if (!h.next_batch.empty())
|
||||||
});
|
fetchPreviews(roomid_, h.next_batch);
|
||||||
});
|
},
|
||||||
|
from,
|
||||||
|
50,
|
||||||
|
1,
|
||||||
|
false);
|
||||||
}
|
}
|
||||||
|
|
||||||
std::set<QString>
|
std::set<QString>
|
||||||
|
|
|
@ -123,7 +123,7 @@ signals:
|
||||||
|
|
||||||
private:
|
private:
|
||||||
void addRoom(const QString &room_id, bool suppressInsertNotification = false);
|
void addRoom(const QString &room_id, bool suppressInsertNotification = false);
|
||||||
void fetchPreview(QString roomid) const;
|
void fetchPreviews(QString roomid, const std::string &from = "");
|
||||||
std::set<QString> updateDMs(mtx::events::AccountDataEvent<mtx::events::account_data::Direct> e);
|
std::set<QString> updateDMs(mtx::events::AccountDataEvent<mtx::events::account_data::Direct> e);
|
||||||
|
|
||||||
TimelineViewManager *manager = nullptr;
|
TimelineViewManager *manager = nullptr;
|
||||||
|
@ -189,6 +189,7 @@ public slots:
|
||||||
} else if (tagId.startsWith(QLatin1String("space:"))) {
|
} else if (tagId.startsWith(QLatin1String("space:"))) {
|
||||||
filterType = FilterBy::Space;
|
filterType = FilterBy::Space;
|
||||||
filterStr = tagId.mid(6);
|
filterStr = tagId.mid(6);
|
||||||
|
roomlistmodel->fetchPreviews(filterStr);
|
||||||
} else if (tagId.startsWith(QLatin1String("dm"))) {
|
} else if (tagId.startsWith(QLatin1String("dm"))) {
|
||||||
filterType = FilterBy::DirectChats;
|
filterType = FilterBy::DirectChats;
|
||||||
filterStr.clear();
|
filterStr.clear();
|
||||||
|
|
Loading…
Reference in a new issue