Add support for system tags in filetagmodel
authorClaudio Cambra <claudio.cambra@nextcloud.com>
Thu, 20 Apr 2023 13:17:24 +0000 (21:17 +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>
src/gui/filetagmodel.cpp

index 4f00e41f2a26c6e79eb178a298d4c3f5dbfb44c6..a9bd35bbda825f8e0ac343b1369d7c2af534e3a4 100644 (file)
@@ -65,7 +65,8 @@ void FileTagModel::fetchFileTags()
     qCDebug(lcFileTagModel) << "Starting fetch of filetags for file at:" << _serverRelativePath;
 
     const auto propfindJob = new PropfindJob(_account, _serverRelativePath, this);
-    propfindJob->setProperties({ QByteArrayLiteral("http://nextcloud.org/ns:tags") });
+    propfindJob->setProperties({ QByteArrayLiteral("http://nextcloud.org/ns:tags"),
+                                 QByteArrayLiteral("http://nextcloud.org/ns:system-tags") });
 
     connect(propfindJob, &PropfindJob::result, this, &FileTagModel::processFileTagRequestFinished);
     connect(propfindJob, &PropfindJob::finishedWithError, this, &FileTagModel::processFileTagRequestFinishedWithError);
@@ -85,7 +86,20 @@ void FileTagModel::processFileTagRequestFinished(const QVariantMap &result)
                             << _serverRelativePath;
 
     beginResetModel();
-    _tags = result.value(QStringLiteral("tags")).toStringList();
+    _tags.clear();
+
+    const auto normalTags = result.value(QStringLiteral("tags")).toStringList();
+    const auto systemTags = result.value(QStringLiteral("system-tags")).toList();
+
+    auto systemTagStringList = QStringList();
+    for (const auto &systemTagMapVariant : systemTags) {
+        const auto systemTagMap = systemTagMapVariant.toMap();
+        const auto systemTag = systemTagMap.value(QStringLiteral("tag")).toString();
+        systemTagStringList << systemTag;
+    }
+
+    _tags << normalTags << systemTagStringList;
+
     Q_EMIT totalTagsChanged();
     endResetModel();
 }