Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add convenience data retrieval method to QXmppBitsOfBinaryDataList #475

Draft
wants to merge 2 commits into
base: master
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 20 additions & 0 deletions src/base/QXmppBitsOfBinaryData.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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<QXmppBitsOfBinaryData> 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 {};
}
jbruechert marked this conversation as resolved.
Show resolved Hide resolved
}

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> find(const QXmppBitsOfBinaryContentId &cid) const;

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