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
@@ -94,10 +94,20 @@ class CalDavDiscovery @Inject constructor(private val client: CalDavClient) {
</propfind>
""".trimIndent()
val resp = client.propfind(principalUrl, credentials, "0", body)
if (!resp.isSuccess) return null
val href = extractHref(resp.body, "calendar-home-set") ?: return null
return resolveUrl(principalUrl, href)
val urlsToTry = mutableListOf(principalUrl)
// Nextcloud alias /principals/username/ doesn't expose calendar-home-set,
// but /principals/users/username/ does — add it as fallback
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> {