Implement support for system tags in propfindjob
authorClaudio Cambra <claudio.cambra@nextcloud.com>
Thu, 20 Apr 2023 13:14:57 +0000 (21:14 +0800)
committerClaudio Cambra <claudio.cambra@nextcloud.com>
Tue, 16 May 2023 10:23:33 +0000 (18:23 +0800)
Signed-off-by: Claudio Cambra <claudio.cambra@nextcloud.com>
fix

src/libsync/networkjobs.cpp
src/libsync/networkjobs.h

index d858d5320b708067fe03bf522a25d9459277a7c5..cb6189cadc6bdfa6c86f934595365160bafd109b 100644 (file)
@@ -63,6 +63,8 @@ constexpr auto notModifiedStatusCode = 304;
 constexpr auto propfindPropElementTagName = "prop";
 constexpr auto propfindFileTagElementTagName = "tag";
 constexpr auto propfindFileTagsContainerElementTagName = "tags";
+constexpr auto propfindSystemFileTagElementTagName = "system-tag";
+constexpr auto propfindSystemFileTagsContainerElementTagName = "system-tags";
 
 RequestEtagJob::RequestEtagJob(AccountPtr account, const QString &path, QObject *parent)
     : AbstractNetworkJob(account, path, parent)
@@ -665,6 +667,9 @@ QVariantMap PropfindJob::processPropfindDomDocument(const QDomDocument &domDocum
                 if (propChildElementTagName == propfindFileTagsContainerElementTagName) {
                     const auto tagList = processTagsInPropfindDomDocument(domDocument);
                     items.insert(propChildElementTagName, tagList);
+                } else if (propChildElementTagName == propfindSystemFileTagsContainerElementTagName) {
+                    const auto systemTagList = processSystemTagsInPropfindDomDocument(domDocument);
+                    items.insert(propChildElementTagName, systemTagList);
                 } else {
                     items.insert(propChildElementTagName, propChildElement.text());
                 }
@@ -702,6 +707,40 @@ QStringList PropfindJob::processTagsInPropfindDomDocument(const QDomDocument &do
     return tagList;
 }
 
+QVariantList PropfindJob::processSystemTagsInPropfindDomDocument(const QDomDocument &domDocument)
+{
+    const auto systemTagNodes = domDocument.elementsByTagName(propfindSystemFileTagElementTagName);
+    if (systemTagNodes.isEmpty()) {
+        return {};
+    }
+
+    const auto systemTagCount = systemTagNodes.count();
+    auto systemTagsList = QVariantList();
+
+    for (auto i = 0; i < systemTagCount; ++i) {
+        const auto systemTagNode = systemTagNodes.at(i);
+        const auto systemTagElem = systemTagNode.toElement();
+
+        if (systemTagElem.isNull()) {
+            continue;
+        }
+
+        auto systemTagMap = QVariantMap{ { QStringLiteral("tag"), systemTagElem.text() } };
+
+        const auto systemTagElemAttrs = systemTagElem.attributes();
+        for (auto i = 0; i < systemTagElemAttrs.count(); ++i) {
+            const auto systemTagElemAttrNode = systemTagElemAttrs.item(i);
+            const auto systemTagElemAttr = systemTagElemAttrNode.toAttr();
+
+            systemTagMap.insert(systemTagElemAttr.name(), systemTagElemAttr.value());
+        }
+
+        systemTagsList.append(systemTagMap);
+    }
+
+    return systemTagsList;
+}
+
 /*********************************************************************************************/
 
 #ifndef TOKEN_AUTH_ONLY
index 11f3c26ac7901493fa867e4dc488187e47e5ef28..533217466ebe82a948ec9541a740fe191c5bbf87 100644 (file)
@@ -201,6 +201,7 @@ private slots:
 private:
     static QVariantMap processPropfindDomDocument(const QDomDocument &domDocument);
     static QStringList processTagsInPropfindDomDocument(const QDomDocument &domDocument);
+    static QVariantList processSystemTagsInPropfindDomDocument(const QDomDocument &domDocument);
 
     QList<QByteArray> _properties;
 };