diff --git a/app/src/full/java/de/jeanlucmakiola/agendula/data/sync/RemoteListRepository.kt b/app/src/full/java/de/jeanlucmakiola/agendula/data/sync/RemoteListRepository.kt
index 7441ea1..98ba699 100644
--- a/app/src/full/java/de/jeanlucmakiola/agendula/data/sync/RemoteListRepository.kt
+++ b/app/src/full/java/de/jeanlucmakiola/agendula/data/sync/RemoteListRepository.kt
@@ -107,6 +107,7 @@ class RemoteListRepository @Inject constructor(
val homeSet = account.homeSetUrl?.toHttpUrlOrNull()
?: return@withContext Outcome.NoAccount
val admin = adminFor(account) ?: return@withContext Outcome.NoAccount
+ if (homeSetIsAList(account)) return@withContext Outcome.Unsupported
val capabilities = support.refresh(accountId) { admin.support(homeSet) }
if (!capabilities.canCreate) return@withContext Outcome.Unsupported
@@ -233,10 +234,17 @@ class RemoteListRepository @Inject constructor(
private suspend fun supportFor(account: AccountEntity): CollectionSupport {
val homeSet = account.homeSetUrl?.toHttpUrlOrNull() ?: return CollectionSupport.NONE
+ if (homeSetIsAList(account)) return CollectionSupport.NONE
val admin = adminFor(account) ?: return CollectionSupport.NONE
return support.refresh(account.id) { admin.support(homeSet) }
}
+ /** A home set that is itself a calendar (#180) cannot hold another one. */
+ private fun homeSetIsAList(account: AccountEntity): Boolean {
+ val homeSet = account.homeSetUrl?.trimEnd('/') ?: return false
+ return database.taskLists().syncedForAccount(account.id).any { it.href?.trimEnd('/') == homeSet }
+ }
+
/**
* Null when the account has no credential we can use — a stopped account, or
* a restore.
diff --git a/caldav/src/main/kotlin/de/jeanlucmakiola/caldav/CalDavDiscovery.kt b/caldav/src/main/kotlin/de/jeanlucmakiola/caldav/CalDavDiscovery.kt
index 09c9dfe..4c156ce 100644
--- a/caldav/src/main/kotlin/de/jeanlucmakiola/caldav/CalDavDiscovery.kt
+++ b/caldav/src/main/kotlin/de/jeanlucmakiola/caldav/CalDavDiscovery.kt
@@ -1,7 +1,8 @@
package de.jeanlucmakiola.caldav
import at.bitfire.dav4jvm.DavResource
-import at.bitfire.dav4jvm.UrlUtils
+import at.bitfire.dav4jvm.Response
+import at.bitfire.dav4jvm.property.ResourceType
import at.bitfire.dav4jvm.property.CalendarHomeSet
import at.bitfire.dav4jvm.exception.HttpException
import at.bitfire.dav4jvm.property.CurrentUserPrincipal
@@ -318,16 +319,22 @@ class CalDavDiscovery(
var anySucceeded = false
for (homeSet in homeSets.distinct()) {
+ var self: TaskCollection? = null
+ var hasMemberCollections = false
val result = runCatching {
- // The home set itself is classified too: all-inkl.com reports its
- // one calendar as the home set (#180). A plain home collection is
- // not a calendar, so the classifier drops it as before. Keyed
- // slash-insensitively, since the self href may lack the slash.
- DavResource(httpClient, homeSet).propfind(1, *collectionProperties) { response, _ ->
- CollectionClassifier.classify(response)?.let {
- collections[UrlUtils.withTrailingSlash(it.url)] = it
+ DavResource(httpClient, homeSet).propfind(1, *collectionProperties) { response, relation ->
+ if (relation == Response.HrefRelation.SELF) {
+ if (self == null) self = CollectionClassifier.classify(response)
+ return@propfind
}
+ if (response[ResourceType::class.java]?.types?.contains(ResourceType.COLLECTION) == true) {
+ hasMemberCollections = true
+ }
+ CollectionClassifier.classify(response)?.let { collections[it.url] = it }
}
+ // A home set that is itself a calendar with no collections in it
+ // is the account's one list, as on all-inkl.com (#180).
+ self?.takeIf { !hasMemberCollections }?.let { collections.putIfAbsent(it.url, it) }
}
result.fold(
// A failed home set must not fail the account — the same rule the
diff --git a/caldav/src/test/kotlin/de/jeanlucmakiola/caldav/CalDavDiscoveryTest.kt b/caldav/src/test/kotlin/de/jeanlucmakiola/caldav/CalDavDiscoveryTest.kt
index 3d0880a..a32dbff 100644
--- a/caldav/src/test/kotlin/de/jeanlucmakiola/caldav/CalDavDiscoveryTest.kt
+++ b/caldav/src/test/kotlin/de/jeanlucmakiola/caldav/CalDavDiscoveryTest.kt
@@ -288,6 +288,20 @@ class CalDavDiscoveryTest {
assertThat(found.collections.map { it.url.encodedPath.trimEnd('/') }).containsExactly("/calendars/user/1")
}
+ @Test
+ fun `a calendar home set with calendars in it offers only those`() {
+ server.enqueue(homeSetResponse("/calendars/user/1/"))
+ server.enqueue(
+ calendarAsHomeSet(
+ "",
+ collection("/calendars/user/1/tasks/", ""),
+ ),
+ )
+
+ val found = discovery.fromPrincipal(server.url("/calendars/principals/user/")) as CalDavDiscovery.Outcome.Found
+ assertThat(found.collections.map { it.url.encodedPath }).containsExactly("/calendars/user/1/tasks/")
+ }
+
@Test
fun `a home set that is a VEVENT-only calendar is not a list`() {
server.enqueue(homeSetResponse("/calendars/user/1/"))