diff --git a/app/src/main/kotlin/at/bitfire/davdroid/db/Collection.kt b/app/src/main/kotlin/at/bitfire/davdroid/db/Collection.kt index d7dcf462a..092712354 100644 --- a/app/src/main/kotlin/at/bitfire/davdroid/db/Collection.kt +++ b/app/src/main/kotlin/at/bitfire/davdroid/db/Collection.kt @@ -127,10 +127,10 @@ data class Collection( /** WebDAV-Push subscription URL */ var pushSubscription: String? = null, - /** when the [pushSubscription] expires (timestamp) */ + /** when the [pushSubscription] expires (timestamp, used to determine whether we need to re-subscribe) */ var pushSubscriptionExpires: Long? = null, - /** when the [pushSubscription] was created/updated (timestamp, used to determine whether we need to re-subscribe) */ + /** when the [pushSubscription] was created/updated (timestamp) */ var pushSubscriptionCreated: Long? = null ) { diff --git a/app/src/main/kotlin/at/bitfire/davdroid/push/PushRegistrationWorker.kt b/app/src/main/kotlin/at/bitfire/davdroid/push/PushRegistrationWorker.kt index 468e9c99f..41eda8fb1 100644 --- a/app/src/main/kotlin/at/bitfire/davdroid/push/PushRegistrationWorker.kt +++ b/app/src/main/kotlin/at/bitfire/davdroid/push/PushRegistrationWorker.kt @@ -80,17 +80,25 @@ class PushRegistrationWorker @AssistedInject constructor( .use { client -> val httpClient = client.okHttpClient + // requested expiration time: 3 days + val requestedExpiration = Instant.now() + Duration.ofDays(3) + val serializer = XmlUtils.newSerializer() val writer = StringWriter() serializer.setOutput(writer) serializer.startDocument("UTF-8", true) serializer.insertTag(Property.Name(NS_WEBDAV_PUSH, "push-register")) { serializer.insertTag(Property.Name(NS_WEBDAV_PUSH, "subscription")) { + // subscription URL serializer.insertTag(Property.Name(NS_WEBDAV_PUSH, "web-push-subscription")) { serializer.insertTag(Property.Name(NS_WEBDAV_PUSH, "push-resource")) { text(endpoint) } } + // requested expiration + serializer.insertTag(Property.Name(NS_WEBDAV_PUSH, "expires")) { + text(HttpUtils.formatDate(requestedExpiration)) + } } } serializer.endDocument() @@ -102,7 +110,7 @@ class PushRegistrationWorker @AssistedInject constructor( val subscriptionUrl = response.header("Location") val expires = response.header("Expires")?.let { expiresDate -> HttpUtils.parseDate(expiresDate) - } ?: /* or assume 3 days */ (Instant.now() + Duration.ofDays(3)) + } ?: /* or assume requested expiration */ requestedExpiration collectionRepository.updatePushSubscription(collection.id, subscriptionUrl, expires?.epochSecond) } else logger.warning("Couldn't register push for ${collection.url}: $response")