Skip to content
This repository was archived by the owner on Mar 20, 2025. It is now read-only.

Commit 3611666

Browse files
committed
Add convinience data retrieval method to QXmppBitsOfBinaryDataList
1 parent f762f73 commit 3611666

File tree

2 files changed

+27
-0
lines changed

2 files changed

+27
-0
lines changed

src/base/QXmppBitsOfBinaryData.cpp

+24
Original file line numberDiff line numberDiff line change
@@ -215,6 +215,30 @@ QXmppBitsOfBinaryDataList::QXmppBitsOfBinaryDataList() = default;
215215
QXmppBitsOfBinaryDataList::~QXmppBitsOfBinaryDataList() = default;
216216

217217
/// \cond
218+
219+
///
220+
/// \brief Finds the data for a uri
221+
/// \param Uri cid uri
222+
/// \return Data belonging to the uri
223+
///
224+
/// \since QXmpp 1.5
225+
///
226+
std::optional<QXmppBitsOfBinaryData> QXmppBitsOfBinaryDataList::forCidUri(const QString &uri) const
227+
{
228+
auto cid = QXmppBitsOfBinaryContentId::fromCidUrl(uri);
229+
const auto thumbnailData = std::find_if(begin(), end(), [&](const auto &bobBlob) {
230+
return bobBlob.cid() == cid;
231+
});
232+
233+
if (thumbnailData != end()) {
234+
return *thumbnailData;
235+
} else {
236+
return {};
237+
}
238+
239+
return *thumbnailData;
240+
}
241+
218242
void QXmppBitsOfBinaryDataList::parse(const QDomElement &element)
219243
{
220244
// clear previous data elements

src/base/QXmppBitsOfBinaryDataList.h

+3
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88
#include "QXmppBitsOfBinaryData.h"
99

1010
#include <QVector>
11+
#include <optional>
1112

1213
class QDomElement;
1314
class QXmlStreamWriter;
@@ -18,6 +19,8 @@ class QXMPP_EXPORT QXmppBitsOfBinaryDataList : public QVector<QXmppBitsOfBinaryD
1819
QXmppBitsOfBinaryDataList();
1920
~QXmppBitsOfBinaryDataList();
2021

22+
std::optional<QXmppBitsOfBinaryData> forCidUri(const QString &uri) const;
23+
2124
/// \cond
2225
void parse(const QDomElement &element);
2326
void toXml(QXmlStreamWriter *writer) const;

0 commit comments

Comments
 (0)