forked from blue/squawk
feat(OMEMO): qxmppfactories, refactoring
This commit is contained in:
parent
b22a4c8ca3
commit
6721b62629
8 changed files with 294 additions and 77 deletions
|
@ -16,4 +16,6 @@ target_sources(squawk PRIVATE
|
|||
utils.h
|
||||
vcard.cpp
|
||||
vcard.h
|
||||
qxmppfactories.cpp
|
||||
qxmppfactories.h
|
||||
)
|
||||
|
|
75
shared/qxmppfactories.cpp
Normal file
75
shared/qxmppfactories.cpp
Normal file
|
@ -0,0 +1,75 @@
|
|||
/*
|
||||
* Created by victoria on 2021-05-12.
|
||||
*/
|
||||
|
||||
#include "qxmppfactories.h"
|
||||
|
||||
#include <QDebug>
|
||||
|
||||
bool QXmpp::Factories::elementMatches(const QXmppElement &element,
|
||||
const QString &tagName,
|
||||
const QString &xmlns) {
|
||||
if (element.tagName() != tagName) {
|
||||
qWarning() << "tag name: expected = " << tagName
|
||||
<< ", got = " << element.tagName();
|
||||
return false;
|
||||
}
|
||||
|
||||
if (!xmlns.isEmpty() && element.attribute("xmlns") != xmlns) {
|
||||
qWarning() << "xmlns: expected = " << xmlns
|
||||
<< ", got = " << element.attribute("xmlns");
|
||||
return false;
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
QXmppElement QXmpp::Factories::createElement(const QString &tagName,
|
||||
const QString &xmlns) {
|
||||
QXmppElement el{};
|
||||
el.setTagName(tagName);
|
||||
|
||||
if (!xmlns.isEmpty())
|
||||
el.setAttribute("xmlns", xmlns);
|
||||
|
||||
return el;
|
||||
}
|
||||
|
||||
QXmppElement QXmpp::Factories::createValue(const QString &value) {
|
||||
auto el = createElement("value");
|
||||
el.setValue(value);
|
||||
|
||||
return el;
|
||||
}
|
||||
|
||||
QXmppElement QXmpp::Factories::createField(const QString &key,
|
||||
const QString &value, bool hidden) {
|
||||
auto field = createElement("field");
|
||||
field.setAttribute("var", key);
|
||||
if (hidden)
|
||||
field.setAttribute("type", "hidden");
|
||||
field.appendChild(createValue(value));
|
||||
|
||||
return field;
|
||||
}
|
||||
|
||||
QXmppElement
|
||||
QXmpp::Factories::createOpenPublishOptions(const QString &maxItems) {
|
||||
auto formType = createField(
|
||||
"FORM_TYPE", "http://jabber.org/protocol/pubsub#publish-options", true);
|
||||
auto accessModel = createField("pubsub#access_model", "open");
|
||||
|
||||
auto x = createElement("x", "jabber:x:data");
|
||||
x.setAttribute("type", "submit");
|
||||
|
||||
x.appendChild(formType);
|
||||
x.appendChild(accessModel);
|
||||
|
||||
if (!maxItems.isEmpty())
|
||||
x.appendChild(createField("pubsub#max_items", maxItems));
|
||||
|
||||
auto publishOptions = createElement("publish-options");
|
||||
publishOptions.appendChild(x);
|
||||
|
||||
return publishOptions;
|
||||
}
|
25
shared/qxmppfactories.h
Normal file
25
shared/qxmppfactories.h
Normal file
|
@ -0,0 +1,25 @@
|
|||
/*
|
||||
* Created by victoria on 2021-05-12.
|
||||
*/
|
||||
|
||||
#pragma once
|
||||
|
||||
#include <QXmppElement.h>
|
||||
|
||||
namespace QXmpp::Factories {
|
||||
|
||||
bool elementMatches(const QXmppElement &element, const QString &tagName,
|
||||
const QString &xmlns = QStringLiteral(""));
|
||||
|
||||
QXmppElement createElement(const QString &tagName,
|
||||
const QString &xmlns = QStringLiteral(""));
|
||||
|
||||
QXmppElement createValue(const QString &value);
|
||||
|
||||
QXmppElement createField(const QString &key, const QString &value,
|
||||
bool hidden = false);
|
||||
|
||||
QXmppElement
|
||||
createOpenPublishOptions(const QString &maxItems = QStringLiteral(""));
|
||||
|
||||
} // namespace QXmpp::Factories
|
Loading…
Add table
Add a link
Reference in a new issue