Simplify fetching calendars

pull/3756/head
Alex Baker 4 months ago
parent 9d96bed5b3
commit c5f8583146

@ -18,7 +18,6 @@ import kotlinx.coroutines.Dispatchers
import kotlinx.coroutines.withContext
import okhttp3.HttpUrl
import okhttp3.HttpUrl.Companion.toHttpUrl
import okhttp3.Interceptor
import okhttp3.MediaType.Companion.toMediaType
import okhttp3.OkHttpClient
import okhttp3.RequestBody.Companion.toRequestBody
@ -101,9 +100,12 @@ open class CaldavClient(
.findHomeset()
}
suspend fun calendars(interceptor: (Interceptor.Chain) -> okhttp3.Response): List<Response> =
suspend fun calendars(interceptor: (okhttp3.Response) -> okhttp3.Response = { it }): List<Response> =
DavResource(
httpClient.newBuilder().addNetworkInterceptor(interceptor).build(),
httpClient
.newBuilder()
.addNetworkInterceptor { interceptor(it.proceed(it.request())) }
.build(),
httpUrl!!
)
.propfind(1, *calendarProperties)

@ -136,8 +136,7 @@ class CaldavSynchronizer @Inject constructor(
private suspend fun synchronize(account: CaldavAccount) {
val caldavClient = provider.forAccount(account)
var serverType = account.serverType
val resources = caldavClient.calendars { chain ->
val response = chain.proceed(chain.request())
val resources = caldavClient.calendars { response ->
if (serverType == SERVER_UNKNOWN) {
serverType = getServerType(account, response.headers)
}

Loading…
Cancel
Save