From e1017907d6b7a2fe17427fda477e3a6de2657b88 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jonah=20Br=C3=BCchert?= Date: Tue, 27 Sep 2022 23:15:32 +0200 Subject: [PATCH] Add convinience data retrieval method to QXmppBitsOfBinaryDataList --- src/base/QXmppBitsOfBinaryData.cpp | 20 ++++++++++++++++++++ src/base/QXmppBitsOfBinaryDataList.h | 3 +++ 2 files changed, 23 insertions(+) diff --git a/src/base/QXmppBitsOfBinaryData.cpp b/src/base/QXmppBitsOfBinaryData.cpp index 6f9226de4..9aa7cc8b9 100644 --- a/src/base/QXmppBitsOfBinaryData.cpp +++ b/src/base/QXmppBitsOfBinaryData.cpp @@ -215,6 +215,26 @@ QXmppBitsOfBinaryDataList::QXmppBitsOfBinaryDataList() = default; QXmppBitsOfBinaryDataList::~QXmppBitsOfBinaryDataList() = default; /// \cond + +/// +/// \brief Finds the data for a uri +/// \return Data belonging to the uri +/// +/// \since QXmpp 1.5 +/// +std::optional QXmppBitsOfBinaryDataList::find(const QXmppBitsOfBinaryContentId &cid) const +{ + const auto thumbnailData = std::find_if(begin(), end(), [&](const auto &bobBlob) { + return bobBlob.cid() == cid; + }); + + if (thumbnailData != end()) { + return *thumbnailData; + } else { + return {}; + } +} + void QXmppBitsOfBinaryDataList::parse(const QDomElement &element) { // clear previous data elements diff --git a/src/base/QXmppBitsOfBinaryDataList.h b/src/base/QXmppBitsOfBinaryDataList.h index 671cd7fb6..9d956b697 100644 --- a/src/base/QXmppBitsOfBinaryDataList.h +++ b/src/base/QXmppBitsOfBinaryDataList.h @@ -8,6 +8,7 @@ #include "QXmppBitsOfBinaryData.h" #include +#include class QDomElement; class QXmlStreamWriter; @@ -18,6 +19,8 @@ class QXMPP_EXPORT QXmppBitsOfBinaryDataList : public QVector find(const QXmppBitsOfBinaryContentId &cid) const; + /// \cond void parse(const QDomElement &element); void toXml(QXmlStreamWriter *writer) const;