diff --git a/src/timeline/CommunitiesModel.cpp b/src/timeline/CommunitiesModel.cpp
index 72d0bdfb..a0c73f84 100644
--- a/src/timeline/CommunitiesModel.cpp
+++ b/src/timeline/CommunitiesModel.cpp
@@ -605,6 +605,20 @@ CommunitiesModel::setCurrentTagId(const QString &tagId)
emit currentTagIdChanged(currentTagId_);
}
+bool
+CommunitiesModel::trySwitchToSpace(const QString &tag)
+{
+ for (const auto &t : spaceOrder_.tree) {
+ if (t.id == tag) {
+ this->currentTagId_ = "space:" + tag;
+ emit currentTagIdChanged(currentTagId_);
+ return true;
+ }
+ }
+
+ return false;
+}
+
void
CommunitiesModel::toggleTagId(QString tagId)
{
diff --git a/src/timeline/CommunitiesModel.h b/src/timeline/CommunitiesModel.h
index 89f1ed07..3a599476 100644
--- a/src/timeline/CommunitiesModel.h
+++ b/src/timeline/CommunitiesModel.h
@@ -179,6 +179,7 @@ public slots:
void clear();
QString currentTagId() const { return currentTagId_; }
void setCurrentTagId(const QString &tagId);
+ bool trySwitchToSpace(const QString &spaceId);
void resetCurrentTagId()
{
currentTagId_.clear();
diff --git a/src/timeline/TimelineModel.cpp b/src/timeline/TimelineModel.cpp
index eaf85b2a..1ddef7b7 100644
--- a/src/timeline/TimelineModel.cpp
+++ b/src/timeline/TimelineModel.cpp
@@ -915,6 +915,9 @@ TimelineModel::syncState(const mtx::responses::State &s)
} else if (std::holds_alternative<StateEvent<state::Encryption>>(e)) {
this->isEncrypted_ = cache::isRoomEncrypted(room_id_.toStdString());
emit encryptionChanged();
+ } else if (std::holds_alternative<StateEvent<state::space::Parent>>(e)) {
+ this->parentChecked = false;
+ emit parentSpaceChanged();
}
}
}
@@ -976,6 +979,9 @@ TimelineModel::addEvents(const mtx::responses::Timeline &timeline)
} else if (std::holds_alternative<StateEvent<state::Encryption>>(e)) {
this->isEncrypted_ = cache::isRoomEncrypted(room_id_.toStdString());
emit encryptionChanged();
+ } else if (std::holds_alternative<StateEvent<state::space::Parent>>(e)) {
+ this->parentChecked = false;
+ emit parentSpaceChanged();
}
}
@@ -2904,3 +2910,22 @@ TimelineModel::directChatOtherUserId() const
} else
return {};
}
+
+RoomSummary *
+TimelineModel::parentSpace()
+{
+ if (!parentChecked) {
+ auto parents = cache::client()->getStateEventsWithType<mtx::events::state::space::Parent>(
+ this->room_id_.toStdString());
+
+ for (const auto &p : parents) {
+ if (p.content.canonical and p.content.via and not p.content.via->empty()) {
+ parentSummary.reset(new RoomSummary(p.state_key, *p.content.via, ""));
+ QQmlEngine::setObjectOwnership(parentSummary.get(), QQmlEngine::CppOwnership);
+ break;
+ }
+ }
+ }
+
+ return parentSummary.get();
+}
diff --git a/src/timeline/TimelineModel.h b/src/timeline/TimelineModel.h
index 295bc69b..ea6daa34 100644
--- a/src/timeline/TimelineModel.h
+++ b/src/timeline/TimelineModel.h
@@ -22,6 +22,7 @@
#include "MemberList.h"
#include "Permissions.h"
#include "ReadReceiptsModel.h"
+#include "ui/RoomSummary.h"
namespace mtx::http {
using RequestErr = const std::optional<mtx::http::ClientError> &;
@@ -197,6 +198,7 @@ class TimelineModel : public QAbstractListModel
QString directChatOtherUserId READ directChatOtherUserId NOTIFY directChatOtherUserIdChanged)
Q_PROPERTY(InputBar *input READ input CONSTANT)
Q_PROPERTY(Permissions *permissions READ permissions NOTIFY permissionsChanged)
+ Q_PROPERTY(RoomSummary *parentSpace READ parentSpace NOTIFY parentSpaceChanged)
public:
explicit TimelineModel(TimelineViewManager *manager,
@@ -397,6 +399,7 @@ public slots:
Permissions *permissions() { return &permissions_; }
QString roomAvatarUrl() const;
QString roomId() const { return room_id_; }
+ RoomSummary *parentSpace();
bool hasMentions() const { return highlight_count > 0; }
int notificationCount() const { return notification_count; }
@@ -431,6 +434,7 @@ signals:
void addPendingMessageToStore(mtx::events::collections::TimelineEvents event);
void updateFlowEventId(std::string event_id);
+ void parentSpaceChanged();
void encryptionChanged();
void fullyReadEventIdChanged();
void trustlevelChanged();
@@ -488,6 +492,9 @@ private:
bool isEncrypted_ = false;
std::string last_event_id;
std::string fullyReadEventId_;
+
+ std::unique_ptr<RoomSummary> parentSummary = nullptr;
+ bool parentChecked = false;
};
template<class T>
|