From 3611666483003a98a4d237240d0d75ead743d06b 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 | 24 ++++++++++++++++++++++++ src/base/QXmppBitsOfBinaryDataList.h | 3 +++ 2 files changed, 27 insertions(+) diff --git a/src/base/QXmppBitsOfBinaryData.cpp b/src/base/QXmppBitsOfBinaryData.cpp index 6f9226de4..88fdeee12 100644 --- a/src/base/QXmppBitsOfBinaryData.cpp +++ b/src/base/QXmppBitsOfBinaryData.cpp @@ -215,6 +215,30 @@ QXmppBitsOfBinaryDataList::QXmppBitsOfBinaryDataList() = default; QXmppBitsOfBinaryDataList::~QXmppBitsOfBinaryDataList() = default; /// \cond + +/// +/// \brief Finds the data for a uri +/// \param Uri cid uri +/// \return Data belonging to the uri +/// +/// \since QXmpp 1.5 +/// +std::optional QXmppBitsOfBinaryDataList::forCidUri(const QString &uri) const +{ + auto cid = QXmppBitsOfBinaryContentId::fromCidUrl(uri); + const auto thumbnailData = std::find_if(begin(), end(), [&](const auto &bobBlob) { + return bobBlob.cid() == cid; + }); + + if (thumbnailData != end()) { + return *thumbnailData; + } else { + return {}; + } + + return *thumbnailData; +} + void QXmppBitsOfBinaryDataList::parse(const QDomElement &element) { // clear previous data elements diff --git a/src/base/QXmppBitsOfBinaryDataList.h b/src/base/QXmppBitsOfBinaryDataList.h index 671cd7fb6..fc4b5f8d8 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 forCidUri(const QString &uri) const; + /// \cond void parse(const QDomElement &element); void toXml(QXmlStreamWriter *writer) const;