aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--lib/connection.cpp11
-rw-r--r--lib/connection.h29
2 files changed, 16 insertions, 24 deletions
diff --git a/lib/connection.cpp b/lib/connection.cpp
index 6e04883e..9e4444df 100644
--- a/lib/connection.cpp
+++ b/lib/connection.cpp
@@ -175,15 +175,6 @@ public:
void consumeToDeviceEvents(Events&& toDeviceEvents);
void consumeDevicesList(DevicesList&& devicesList);
- template <typename EventT>
- EventT* unpackAccountData() const
- {
- const auto& eventIt = accountData.find(EventT::matrixTypeId());
- return eventIt == accountData.end()
- ? nullptr
- : weakPtrCast<EventT>(eventIt->second);
- }
-
void packAndSendAccountData(EventPtr&& event)
{
const auto eventType = event->matrixType();
@@ -1665,7 +1656,7 @@ bool Connection::isIgnored(const User* user) const
IgnoredUsersList Connection::ignoredUsers() const
{
- const auto* event = d->unpackAccountData<IgnoredUsersEvent>();
+ const auto* event = accountData<IgnoredUsersEvent>();
return event ? event->ignored_users() : IgnoredUsersList();
}
diff --git a/lib/connection.h b/lib/connection.h
index b8246ecb..0d0c85b6 100644
--- a/lib/connection.h
+++ b/lib/connection.h
@@ -174,24 +174,25 @@ public:
*/
bool hasAccountData(const QString& type) const;
- /** Get a generic account data event of the given type
- * This returns an account data event of the given type
- * stored on the server. Direct chats map cannot be retrieved
- * using this method _yet_; use directChats() instead.
- */
+ //! \brief Get a generic account data event of the given type
+ //!
+ //! \return an account data event of the given type stored on the server,
+ //! or nullptr if there's none of that type.
+ //! \note Direct chats map cannot be retrieved using this method _yet_;
+ //! use directChats() instead.
const EventPtr& accountData(const QString& type) const;
- /** Get a generic account data event of the given type
- * This returns an account data event of the given type
- * stored on the server. Direct chats map cannot be retrieved
- * using this method _yet_; use directChats() instead.
- */
+ //! \brief Get an account data event of the given type
+ //!
+ //! \return the account data content for the given event type stored
+ //! on the server, or a default-constructed object if there's none
+ //! of that type.
+ //! \note Direct chats map cannot be retrieved using this method _yet_;
+ //! use directChats() instead.
template <typename EventT>
- const typename EventT::content_type accountData() const
+ const EventT* accountData() const
{
- if (const auto& eventPtr = accountData(EventT::matrixTypeId()))
- return eventPtr->content();
- return {};
+ return eventCast<EventT>(accountData(EventT::TypeId));
}
/** Get account data as a JSON object