Skip to content

Commit

Permalink
Don't publish vcard's empty lists
Browse files Browse the repository at this point in the history
  • Loading branch information
Ri0n committed Jun 12, 2024
1 parent 61e5cdb commit 6e668bc
Showing 1 changed file with 11 additions and 4 deletions.
15 changes: 11 additions & 4 deletions src/xmpp/xmpp-im/xmpp_vcard4.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -118,6 +118,9 @@ namespace {
static void serializeList(QDomElement &parent, const TaggedList<Item<T>> &list, const QString &tagName,
const QString &innerTagName = QLatin1String("text"))
{
if (list.isEmpty()) {
return;
}
auto document = parent.ownerDocument();
for (const auto &entry : list) {
QDomElement element = document.createElement(tagName);
Expand Down Expand Up @@ -319,6 +322,9 @@ Address::Address(const QDomElement &element)

QDomElement Address::toXmlElement(QDomDocument &document) const
{
if (isEmpty()) {
return {};
}
QDomElement addressElement = document.createElement(QLatin1String("adr"));
VCardHelper::addTextElement(document, addressElement, QLatin1String("pobox"), pobox);
VCardHelper::addTextElement(document, addressElement, QLatin1String("ext"), extaddr);
Expand Down Expand Up @@ -700,10 +706,11 @@ QDomElement VCard::toXmlElement(QDomDocument &document) const
}

for (const auto &address : d->addresses) {
QDomElement adrElement = document.createElement(QLatin1String("adr"));
address.parameters.addTo(adrElement);
adrElement.appendChild(address.data.toXmlElement(document));
vCardElement.appendChild(adrElement);
auto addrEl = address.data.toXmlElement(document);
if (!addrEl.isNull()) {
address.parameters.addTo(addrEl);
vCardElement.appendChild(addrEl);
}
}

return vCardElement;
Expand Down

0 comments on commit 6e668bc

Please sign in to comment.