Respect folderId == null, fixes #293.

This commit is contained in:
Martin Rotter 2020-11-12 09:00:45 +01:00
parent 883cefa67d
commit a29a083382
3 changed files with 15 additions and 5 deletions

View File

@ -247,7 +247,7 @@ bool SystemFactory::isVersionNewer(const QString& new_version, const QString& ba
const int new_number = new_version_tkn.takeFirst().toInt(); const int new_number = new_version_tkn.takeFirst().toInt();
if (new_number > base_number) { if (new_number > base_number) {
// New version is indeed higher thatn current version. // New version is indeed higher that current version.
return true; return true;
} }
else if (new_number < base_number) { else if (new_number < base_number) {
@ -277,7 +277,7 @@ bool SystemFactory::isVersionEqualOrNewer(const QString& new_version, const QStr
bool SystemFactory::openFolderFile(const QString& file_path) { bool SystemFactory::openFolderFile(const QString& file_path) {
#if defined(Q_OS_WIN) #if defined(Q_OS_WIN)
return QProcess::startDetached(QSL("explorer.exe"), return QProcess::startDetached(QSL("explorer.exe"),
{ "/select,", QDir::toNativeSeparators(file_path)}); { "/select,", QDir::toNativeSeparators(file_path) });
#else #else
const QString folder = QDir::toNativeSeparators(QFileInfo(file_path).absoluteDir().absolutePath()); const QString folder = QDir::toNativeSeparators(QFileInfo(file_path).absoluteDir().absolutePath());

View File

@ -54,7 +54,7 @@ void FormOwnCloudFeedDetails::apply() {
else { else {
const RootItem* parent = static_cast<RootItem*>(m_ui->m_cmbParentCategory->itemData( const RootItem* parent = static_cast<RootItem*>(m_ui->m_cmbParentCategory->itemData(
m_ui->m_cmbParentCategory->currentIndex()).value<void*>()); m_ui->m_cmbParentCategory->currentIndex()).value<void*>());
const int category_id = parent->kind() == RootItem::Kind::ServiceRoot ? 0 : parent->customId().toInt(); const int category_id = parent->kind() == RootItem::Kind::ServiceRoot ? 0 : parent->customNumericId();
const bool response = qobject_cast<OwnCloudServiceRoot*>(m_serviceRoot)->network()->createFeed(m_ui->m_txtUrl->lineEdit()->text(), const bool response = qobject_cast<OwnCloudServiceRoot*>(m_serviceRoot)->network()->createFeed(m_ui->m_txtUrl->lineEdit()->text(),
category_id); category_id);

View File

@ -184,7 +184,15 @@ bool OwnCloudNetworkFactory::createFeed(const QString& url, int parent_id) {
QJsonObject json; QJsonObject json;
json["url"] = url; json["url"] = url;
json["folderId"] = parent_id;
auto nextcloud_version = status().version();
if (SystemFactory::isVersionEqualOrNewer(nextcloud_version, QSL("15.1.0"))) {
json["folderId"] = parent_id == 0 ? QJsonValue::Null : parent_id;
}
else {
json["folderId"] = parent_id;
}
QByteArray result_raw; QByteArray result_raw;
QList<QPair<QByteArray, QByteArray>> headers; QList<QPair<QByteArray, QByteArray>> headers;
@ -461,7 +469,7 @@ RootItem* OwnCloudGetFeedsCategoriesResponse::feedsCategories(bool obtain_icons)
auto* parent = new RootItem(); auto* parent = new RootItem();
QMap<QString, RootItem*> cats; QMap<QString, RootItem*> cats;
// Top-level feed have "folderId" set to "0". // Top-level feed have "folderId" set to "0" or JSON "null" value.
cats.insert(QSL("0"), parent); cats.insert(QSL("0"), parent);
// Process categories first, then process feeds. // Process categories first, then process feeds.
@ -524,6 +532,8 @@ RootItem* OwnCloudGetFeedsCategoriesResponse::feedsCategories(bool obtain_icons)
} }
} }
// NOTE: Starting with News 15.1.0, top-level feeds do not have parent folder ID 0, but JSON "null".
// Luckily, if folder ID is not convertible to int, then default 0 value is returned.
cats.value(QString::number(item["folderId"].toInt()))->appendChild(feed); cats.value(QString::number(item["folderId"].toInt()))->appendChild(feed);
qDebugNN << LOGSEC_NEXTCLOUD qDebugNN << LOGSEC_NEXTCLOUD
<< "Custom ID of next fetched processed feed is" << "Custom ID of next fetched processed feed is"