Skip to content

Commit

Permalink
Add convinience data retrieval method to QXmppBitsOfBinaryDataList
Browse files Browse the repository at this point in the history
  • Loading branch information
jbruechert committed Sep 27, 2022
1 parent f762f73 commit 3611666
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 0 deletions.
24 changes: 24 additions & 0 deletions src/base/QXmppBitsOfBinaryData.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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<QXmppBitsOfBinaryData> 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
Expand Down
3 changes: 3 additions & 0 deletions src/base/QXmppBitsOfBinaryDataList.h
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
#include "QXmppBitsOfBinaryData.h"

#include <QVector>
#include <optional>

class QDomElement;
class QXmlStreamWriter;
Expand All @@ -18,6 +19,8 @@ class QXMPP_EXPORT QXmppBitsOfBinaryDataList : public QVector<QXmppBitsOfBinaryD
QXmppBitsOfBinaryDataList();
~QXmppBitsOfBinaryDataList();

std::optional<QXmppBitsOfBinaryData> forCidUri(const QString &uri) const;

/// \cond
void parse(const QDomElement &element);
void toXml(QXmlStreamWriter *writer) const;
Expand Down

0 comments on commit 3611666

Please sign in to comment.