libQuotient
A Qt library for building matrix clients
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. More...
 
template<Keyed_State_Event EvT>
const EvT * get (const QString &stateKey={}) const
 Get a state event with the given event type and state key. More...
 
template<Keyless_State_Event EvT>
const EvT * get () const
 Get a state event with the given event type. More...
 
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. More...
 
const QVector< const StateEvent * > eventsOfType (const QString &evtType) const
 Get all state events in the room of a certain type. More...
 
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. More...
 
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. More...
 
template<Keyless_State_Fn FnT>
auto query (FnT &&fn) const
 Run a function on a keyless state event with the given type. More...
 
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. More...
 
template<typename FnT , typename FallbackT >
auto queryOr (const QString &stateKey, FnT &&fn, FallbackT &&fallback) const
 Same as query() but with a fallback value. More...
 
template<typename FnT , typename FallbackT >
auto queryOr (FnT &&fn, FallbackT &&fallback) const
 Same as query() but with a fallback value. More...
 

Friends

class Room
 

Detailed Description

Definition at line 24 of file roomstateview.h.

Member Function Documentation

◆ contains() [1/3]

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

Definition at line 87 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 81 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 93 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 104 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 28 of file roomstateview.h.

◆ eventsOfType()

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

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

This method returns all known state events that have occured in the room of the given type.

◆ 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 67 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 51 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 133 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 145 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 158 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 172 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 187 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 201 of file roomstateview.h.

Friends And Related Function Documentation

◆ Room

friend class Room
friend

Definition at line 208 of file roomstateview.h.


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