fix: CalDAV Nextcloud — fallback principals/users/ pour calendar-home-set (v0.0.2)

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
This commit is contained in:
2026-06-06 08:12:12 +02:00
parent f038dbe0ee
commit 98b08f0219
2 changed files with 15 additions and 5 deletions
+1 -1
View File
@@ -16,7 +16,7 @@ android {
minSdk = 26 minSdk = 26
targetSdk = 35 targetSdk = 35
versionCode = 1 versionCode = 1
versionName = "0.0.1" versionName = "0.0.2"
testInstrumentationRunner = "androidx.test.runner.AndroidJUnitRunner" testInstrumentationRunner = "androidx.test.runner.AndroidJUnitRunner"
} }
@@ -94,10 +94,20 @@ class CalDavDiscovery @Inject constructor(private val client: CalDavClient) {
</propfind> </propfind>
""".trimIndent() """.trimIndent()
val resp = client.propfind(principalUrl, credentials, "0", body) val urlsToTry = mutableListOf(principalUrl)
if (!resp.isSuccess) return null // Nextcloud alias /principals/username/ doesn't expose calendar-home-set,
val href = extractHref(resp.body, "calendar-home-set") ?: return null // but /principals/users/username/ does — add it as fallback
return resolveUrl(principalUrl, href) if (principalUrl.contains("/principals/") && !principalUrl.contains("/principals/users/")) {
urlsToTry.add(principalUrl.replaceFirst("/principals/", "/principals/users/"))
}
for (url in urlsToTry) {
val resp = client.propfind(url, credentials, "0", body)
if (!resp.isSuccess) continue
val href = extractHref(resp.body, "calendar-home-set") ?: continue
return resolveUrl(url, href)
}
return null
} }
private fun listCalendars(homeUrl: String, credentials: String, username: String, baseUrl: String): List<CalendarInfo> { private fun listCalendars(homeUrl: String, credentials: String, username: String, baseUrl: String): List<CalendarInfo> {