Ensure UnifiedPush endpoint is registered.

This commit is contained in:
Benoit Marty 2024-05-07 11:23:13 +02:00 committed by Benoit Marty
parent e64051f7bd
commit dc572af9db

View file

@ -69,26 +69,20 @@ class VectorUnifiedPushMessagingReceiver : MessagingReceiver() {
* You should send the endpoint to your application server and sync for missing notifications. * You should send the endpoint to your application server and sync for missing notifications.
*/ */
override fun onNewEndpoint(context: Context, endpoint: String, instance: String) { override fun onNewEndpoint(context: Context, endpoint: String, instance: String) {
Timber.tag(loggerTag.value).i("onNewEndpoint: adding $endpoint") Timber.tag(loggerTag.value).i("onNewEndpoint: $endpoint")
// If the endpoint has changed
// or the gateway has changed
if (unifiedPushStore.getEndpoint(instance) != endpoint) {
coroutineScope.launch { coroutineScope.launch {
val gateway = unifiedPushGatewayResolver.getGateway(endpoint) val gateway = unifiedPushGatewayResolver.getGateway(endpoint)
unifiedPushStore.storePushGateway(gateway, instance) unifiedPushStore.storePushGateway(gateway, instance)
gateway?.let { pushGateway -> gateway?.let { pushGateway ->
newGatewayHandler.handle(endpoint, pushGateway, instance) newGatewayHandler.handle(endpoint, pushGateway, instance)
.onFailure { .onFailure {
Timber.tag(loggerTag.value).e("Failed to handle new gateway") Timber.tag(loggerTag.value).e(it, "Failed to handle new gateway")
} }
.onSuccess { .onSuccess {
unifiedPushStore.storeUpEndpoint(endpoint, instance) unifiedPushStore.storeUpEndpoint(endpoint, instance)
} }
} }
} }
} else {
Timber.tag(loggerTag.value).i("onNewEndpoint: skipped")
}
guardServiceStarter.stop() guardServiceStarter.stop()
} }