aboutsummaryrefslogtreecommitdiff
path: root/lib
diff options
context:
space:
mode:
Diffstat (limited to 'lib')
-rw-r--r--lib/room.cpp5
-rw-r--r--lib/roomstateview.h20
2 files changed, 22 insertions, 3 deletions
diff --git a/lib/room.cpp b/lib/room.cpp
index 042d38ac..a6617cc3 100644
--- a/lib/room.cpp
+++ b/lib/room.cpp
@@ -597,7 +597,7 @@ bool Room::allHistoryLoaded() const
QString Room::name() const
{
- return currentState().queryOr(&RoomNameEvent::name, QString());
+ return currentState().content<RoomNameEvent>().value;
}
QStringList Room::aliases() const
@@ -613,8 +613,7 @@ QStringList Room::aliases() const
QStringList Room::altAliases() const
{
- return currentState().queryOr(&RoomCanonicalAliasEvent::altAliases,
- QStringList());
+ return currentState().content<RoomCanonicalAliasEvent>().altAliases;
}
QString Room::canonicalAlias() const
diff --git a/lib/roomstateview.h b/lib/roomstateview.h
index 13b375f2..119c24cf 100644
--- a/lib/roomstateview.h
+++ b/lib/roomstateview.h
@@ -90,6 +90,26 @@ public:
return contains(EvT::TypeId);
}
+ template <Keyed_State_Event EvT>
+ auto content(const QString& stateKey,
+ typename EvT::content_type defaultValue = {}) const
+ {
+ // StateEvent<>::content is special in that it returns a const-ref,
+ // and lift() inside queryOr() can't wrap that in a temporary Omittable.
+ if (const auto evt = get<EvT>(stateKey))
+ return evt->content();
+ return std::move(defaultValue);
+ }
+
+ template <Keyless_State_Event EvT>
+ auto content(typename EvT::content_type defaultValue = {}) const
+ {
+ // Same as above
+ if (const auto evt = get<EvT>())
+ return evt->content();
+ return defaultValue;
+ }
+
//! \brief Get the content of the current state event with the given
//! event type and state key
//! \return An empty object if there's no event in the current state with