libQuotient
A Qt library for building matrix clients
Loading...
Searching...
No Matches
Quotient::RoomStateView Class Reference

#include <roomstateview.h>

Inheritance diagram for Quotient::RoomStateView:
Collaboration diagram for Quotient::RoomStateView:

Public Member Functions

const QHash< StateEventKey, const StateEvent * > & events () const
 
const StateEventget (const QString &evtType, const QString &stateKey={}) const
 Get a state event with the given event type and state key.
 
template<Keyed_State_Event EvT>
const EvT * get (const QString &stateKey={}) const
 Get a state event with the given event type and state key.
 
template<Keyless_State_Event EvT>
const EvT * get () const
 Get a state event with the given event type.
 
bool contains (const QString &evtType, const QString &stateKey={}) const
 
template<Keyed_State_Event EvT>
bool contains (const QString &stateKey={}) const
 
template<Keyless_State_Event EvT>
bool contains () const
 
template<Keyed_State_Event EvT>
auto content (const QString &stateKey, typename EvT::content_type defaultValue={}) const
 
template<Keyless_State_Event EvT>
auto content (typename EvT::content_type defaultValue={}) const
 
Q_INVOKABLE QJsonObject contentJson (const QString &evtType, const QString &stateKey={}) const
 Get the content of the current state event with the given event type and state key.
 
QVector< const StateEvent * > eventsOfType (const QString &evtType) const
 Get all state events in the room of a certain type.
 
template<Keyed_State_Event EvT>
QVector< const EvT * > eventsOfType () const
 Get all state events in the room of a certain type.
 
template<typename FnT >
auto query (const QString &evtType, const QString &stateKey, FnT &&fn) const
 Run a function on a state event with the given type and key.
 
template<Keyed_State_Fn FnT>
auto query (const QString &stateKey, FnT &&fn) const
 Run a function on a state event with the given type and key.
 
template<Keyless_State_Fn FnT>
auto query (FnT &&fn) const
 Run a function on a keyless state event with the given type.
 
template<Keyed_State_Fn FnT>
void queryAll (FnT &&fn) const
 Run a function on each event of the given type.
 
template<typename FnT , typename FallbackT >
auto queryOr (const QString &evtType, const QString &stateKey, FnT &&fn, FallbackT &&fallback) const
 Same as query() but with a fallback value.
 
template<typename FnT , typename FallbackT >
auto queryOr (const QString &stateKey, FnT &&fn, FallbackT &&fallback) const
 Same as query() but with a fallback value.
 
template<typename FnT , typename FallbackT >
auto queryOr (FnT &&fn, FallbackT &&fallback) const
 Same as query() but with a fallback value.
 

Friends

class Room
 

Detailed Description

Definition at line 25 of file roomstateview.h.

Member Function Documentation

◆ contains() [1/3]

template<Keyless_State_Event EvT>
bool Quotient::RoomStateView::contains ( ) const
inline

Definition at line 88 of file roomstateview.h.

◆ contains() [2/3]

bool Quotient::RoomStateView::contains ( const QString &  evtType,
const QString &  stateKey = {} 
) const

◆ contains() [3/3]

template<Keyed_State_Event EvT>
bool Quotient::RoomStateView::contains ( const QString &  stateKey = {}) const
inline

Definition at line 82 of file roomstateview.h.

◆ content() [1/2]

template<Keyed_State_Event EvT>
auto Quotient::RoomStateView::content ( const QString &  stateKey,
typename EvT::content_type  defaultValue = {} 
) const
inline

Definition at line 94 of file roomstateview.h.

◆ content() [2/2]

template<Keyless_State_Event EvT>
auto Quotient::RoomStateView::content ( typename EvT::content_type  defaultValue = {}) const
inline

Definition at line 105 of file roomstateview.h.

◆ contentJson()

Q_INVOKABLE QJsonObject Quotient::RoomStateView::contentJson ( const QString &  evtType,
const QString &  stateKey = {} 
) const

Get the content of the current state event with the given event type and state key.

Returns
An empty object if there's no event in the current state with this event type and state key; the contents of the event 'content' object otherwise

◆ events()

const QHash< StateEventKey, const StateEvent * > & Quotient::RoomStateView::events ( ) const
inline

Definition at line 29 of file roomstateview.h.

◆ eventsOfType() [1/2]

template<Keyed_State_Event EvT>
QVector< const EvT * > Quotient::RoomStateView::eventsOfType ( ) const
inline

Get all state events in the room of a certain type.

This is a type-safe overload for the case when the event type is known at compile time.

Note
This overload is only defined for event types that expect a state key.
Same as the other overload, this one has to look through the entire list of state events, although it is slightly faster thanks to the event type known at compile time.
Returns
all known state events of type EvT that have occurred in the room

Definition at line 137 of file roomstateview.h.

◆ eventsOfType() [2/2]

QVector< const StateEvent * > Quotient::RoomStateView::eventsOfType ( const QString &  evtType) const

Get all state events in the room of a certain type.

This function allows to retrieve all events of one type regardless of their state key.

Note
To do its job, the function has to look through the entire list of state events currently in the room; this may have implications in performance-sensitive code.
Returns
all known state events of evtType that have occurred in the room

◆ get() [1/3]

template<Keyless_State_Event EvT>
const EvT * Quotient::RoomStateView::get ( ) const
inline

Get a state event with the given event type.

This is a typesafe overload that accepts a C++ event type instead of its Matrix name. This overload only defined for events that do not use state key (i.e., derived from KeylessStateEvent).

Definition at line 68 of file roomstateview.h.

◆ get() [2/3]

const StateEvent * Quotient::RoomStateView::get ( const QString &  evtType,
const QString &  stateKey = {} 
) const

Get a state event with the given event type and state key.

Returns
A state event corresponding to the pair of event type evtType and state key stateKey, or nullptr if there's no such evtType / stateKey combination in the current state.
Warning
The returned value is not guaranteed to be non-nullptr; you MUST check it before using or use other methods of this class such as query() and content() to access state safely.
See also
content, contentJson, query

◆ get() [3/3]

template<Keyed_State_Event EvT>
const EvT * Quotient::RoomStateView::get ( const QString &  stateKey = {}) const
inline

Get a state event with the given event type and state key.

This is a typesafe overload that accepts a C++ event type instead of its Matrix name. It is only defined for events with state key (i.e., derived from KeyedStateEvent).

Definition at line 52 of file roomstateview.h.

◆ query() [1/3]

template<typename FnT >
auto Quotient::RoomStateView::query ( const QString &  evtType,
const QString &  stateKey,
FnT &&  fn 
) const
inline

Run a function on a state event with the given type and key.

Use this overload when there's no predefined event type or the event type is unknown at compile time.

Returns
an optional with the result of the function call, or std::nullopt if the event is not found or fn fails

Definition at line 151 of file roomstateview.h.

◆ query() [2/3]

template<Keyed_State_Fn FnT>
auto Quotient::RoomStateView::query ( const QString &  stateKey,
FnT &&  fn 
) const
inline

Run a function on a state event with the given type and key.

This is an overload for keyed state events (those that have needsStateKey == true) with type defined at compile time.

Returns
an optional with the result of the function call, or std::nullopt if the event is not found or fn fails

Definition at line 163 of file roomstateview.h.

◆ query() [3/3]

template<Keyless_State_Fn FnT>
auto Quotient::RoomStateView::query ( FnT &&  fn) const
inline

Run a function on a keyless state event with the given type.

This is an overload for keyless state events (those having needsStateKey == false) with type defined at compile time.

Returns
an optional with the result of the function call, or std::nullopt if the event is not found or fn fails

Definition at line 176 of file roomstateview.h.

◆ queryAll()

template<Keyed_State_Fn FnT>
void Quotient::RoomStateView::queryAll ( FnT &&  fn) const
inline

Run a function on each event of the given type.

This is effectively a combination of query and eventsOfType() except that it doesn't create a new container. The return value of FnT is ignored.

Definition at line 187 of file roomstateview.h.

◆ queryOr() [1/3]

template<typename FnT , typename FallbackT >
auto Quotient::RoomStateView::queryOr ( const QString &  evtType,
const QString &  stateKey,
FnT &&  fn,
FallbackT &&  fallback 
) const
inline

Same as query() but with a fallback value.

This is a shortcut for query().value_or(), passing respective arguments to the respective functions. This is an overload for the case when the event type cannot be fixed at compile time.

Returns
the result of fn execution, or fallback if the requested event doesn't exist or the function fails

Definition at line 202 of file roomstateview.h.

◆ queryOr() [2/3]

template<typename FnT , typename FallbackT >
auto Quotient::RoomStateView::queryOr ( const QString &  stateKey,
FnT &&  fn,
FallbackT &&  fallback 
) const
inline

Same as query() but with a fallback value.

This is a shortcut for query().value_or(), passing respective arguments to the respective functions. This is an overload for the case when the event type cannot be fixed at compile time.

Returns
the result of fn execution, or fallback if the requested event doesn't exist or the function fails

Definition at line 217 of file roomstateview.h.

◆ queryOr() [3/3]

template<typename FnT , typename FallbackT >
auto Quotient::RoomStateView::queryOr ( FnT &&  fn,
FallbackT &&  fallback 
) const
inline

Same as query() but with a fallback value.

This is a shortcut for query().value_or(), passing respective arguments to the respective functions. This is an overload for the case when the event type cannot be fixed at compile time.

Returns
the result of fn execution, or fallback if the requested event doesn't exist or the function fails

Definition at line 231 of file roomstateview.h.

Friends And Related Symbol Documentation

◆ Room

friend class Room
friend

Definition at line 238 of file roomstateview.h.


The documentation for this class was generated from the following file: