Skip to content

Commit 3c1c62d

Browse files
committed
Support retrieval of account and state events with alternative type ids
1 parent f8975b6 commit 3c1c62d

File tree

2 files changed

+20
-14
lines changed

2 files changed

+20
-14
lines changed

Quotient/connection.h

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -180,8 +180,10 @@ class QUOTIENT_API Connection : public QObject {
180180
template <EventClass EventT>
181181
const EventT* accountData() const
182182
{
183-
// 0.9: use the default argument and fold into the next overload
184-
return eventCast<EventT>(accountData(EventT::TypeId));
183+
for (auto typeId : EventT::MetaType.matrixIds)
184+
if (const auto &evtPtr = accountData(typeId))
185+
return eventCast<EventT>(evtPtr);
186+
return nullptr;
185187
}
186188

187189
template <EventClass EventT>

Quotient/roomstateview.h

Lines changed: 16 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -50,11 +50,11 @@ class QUOTIENT_API RoomStateView
5050
template <Keyed_State_Event EvT>
5151
const EvT* get(const QString& stateKey = {}) const
5252
{
53-
if (const auto* evt = get(EvT::TypeId, stateKey)) {
54-
Q_ASSERT(evt->matrixType() == EvT::TypeId
55-
&& evt->stateKey() == stateKey);
56-
return eventCast<const EvT>(evt);
57-
}
53+
for (auto typeId : EvT::MetaType.matrixIds)
54+
if (const auto *evt = get(typeId, stateKey)) {
55+
Q_ASSERT(evt->matrixType() == typeId && evt->stateKey() == stateKey);
56+
return eventCast<const EvT>(evt);
57+
}
5858
return nullptr;
5959
}
6060

@@ -66,10 +66,11 @@ class QUOTIENT_API RoomStateView
6666
template <Keyless_State_Event EvT>
6767
const EvT* get() const
6868
{
69-
if (const auto* evt = get(EvT::TypeId)) {
70-
Q_ASSERT(evt->matrixType() == EvT::TypeId);
71-
return eventCast<const EvT>(evt);
72-
}
69+
for (auto typeId : EvT::MetaType.matrixIds)
70+
if (const auto *evt = get(typeId)) {
71+
Q_ASSERT(evt->matrixType() == typeId);
72+
return eventCast<const EvT>(evt);
73+
}
7374
return nullptr;
7475
}
7576

@@ -80,20 +81,23 @@ class QUOTIENT_API RoomStateView
8081
template <Keyed_State_Event EvT>
8182
bool contains(const QString& stateKey = {}) const
8283
{
83-
return contains(EvT::TypeId, stateKey);
84+
return std::ranges::any_of(EvT::MetaType.matrixIds, [this, &stateKey](event_type_t typeId) {
85+
return contains(typeId, stateKey);
86+
});
8487
}
8588

8689
template <Keyless_State_Event EvT>
8790
bool contains() const
8891
{
89-
return contains(EvT::TypeId);
92+
return std::ranges::any_of(EvT::MetaType.matrixIds,
93+
[this](event_type_t typeId) { return contains(typeId); });
9094
}
9195

9296
template <Keyed_State_Event EvT>
9397
auto content(const QString& stateKey,
9498
typename EvT::content_type defaultValue = {}) const
9599
{
96-
// EventBase<>::content is special in that it returns a const-ref,
100+
// EventTemplate<>::content for StateEvent is special in that it returns a const-ref,
97101
// and lift() inside queryOr() can't wrap that in a temporary optional.
98102
if (const auto evt = get<EvT>(stateKey))
99103
return evt->content();

0 commit comments

Comments
 (0)