@@ -10,6 +10,7 @@ package io.element.android.libraries.pushproviders.unifiedpush
1010import com.squareup.anvil.annotations.ContributesBinding
1111import io.element.android.libraries.core.coroutine.CoroutineDispatchers
1212import io.element.android.libraries.core.data.tryOrNull
13+ import io.element.android.libraries.core.log.logger.LoggerTag
1314import io.element.android.libraries.di.AppScope
1415import kotlinx.coroutines.withContext
1516import retrofit2.HttpException
@@ -29,43 +30,45 @@ interface UnifiedPushGatewayResolver {
2930 suspend fun getGateway (endpoint : String ): UnifiedPushGatewayResolverResult
3031}
3132
33+ private val loggerTag = LoggerTag (" DefaultUnifiedPushGatewayResolver" )
34+
3235@ContributesBinding(AppScope ::class )
3336class DefaultUnifiedPushGatewayResolver @Inject constructor(
3437 private val unifiedPushApiFactory : UnifiedPushApiFactory ,
3538 private val coroutineDispatchers : CoroutineDispatchers ,
3639) : UnifiedPushGatewayResolver {
3740 override suspend fun getGateway (endpoint : String ): UnifiedPushGatewayResolverResult {
3841 val url = tryOrNull(
39- onException = { Timber .tag(" DefaultUnifiedPushGatewayResolver " ).d(it, " Cannot parse endpoint as an URL" ) }
42+ onException = { Timber .tag(loggerTag.value ).d(it, " Cannot parse endpoint as an URL" ) }
4043 ) {
4144 URL (endpoint)
4245 }
4346 return if (url == null ) {
44- Timber .tag(" DefaultUnifiedPushGatewayResolver " ).d(" ErrorInvalidUrl" )
47+ Timber .tag(loggerTag.value ).d(" ErrorInvalidUrl" )
4548 UnifiedPushGatewayResolverResult .ErrorInvalidUrl
4649 } else {
4750 val port = if (url.port != - 1 ) " :${url.port} " else " "
4851 val customBase = " ${url.protocol} ://${url.host}$port "
4952 val customUrl = " $customBase /_matrix/push/v1/notify"
50- Timber .tag(" DefaultUnifiedPushGatewayResolver " ).i(" Testing $customUrl " )
53+ Timber .tag(loggerTag.value ).i(" Testing $customUrl " )
5154 return withContext(coroutineDispatchers.io) {
5255 val api = unifiedPushApiFactory.create(customBase)
5356 try {
5457 val discoveryResponse = api.discover()
5558 if (discoveryResponse.unifiedpush.gateway == " matrix" ) {
56- Timber .tag(" DefaultUnifiedPushGatewayResolver " ).d(" The endpoint seems to be a valid UnifiedPush gateway" )
59+ Timber .tag(loggerTag.value ).d(" The endpoint seems to be a valid UnifiedPush gateway" )
5760 UnifiedPushGatewayResolverResult .Success (customUrl)
5861 } else {
5962 // The endpoint returned a 200 OK but didn't promote an actual matrix gateway, which means it doesn't have any
60- Timber .tag(" DefaultUnifiedPushGatewayResolver " ).w(" The endpoint does not seem to be a valid UnifiedPush gateway, using fallback" )
63+ Timber .tag(loggerTag.value ).w(" The endpoint does not seem to be a valid UnifiedPush gateway, using fallback" )
6164 UnifiedPushGatewayResolverResult .NoMatrixGateway
6265 }
6366 } catch (throwable: Throwable ) {
6467 if ((throwable as ? HttpException )?.code() == HttpURLConnection .HTTP_NOT_FOUND ) {
65- Timber .tag(" DefaultUnifiedPushGatewayResolver " ).i(" Checking for UnifiedPush endpoint yielded 404, using fallback" )
68+ Timber .tag(loggerTag.value ).i(" Checking for UnifiedPush endpoint yielded 404, using fallback" )
6669 UnifiedPushGatewayResolverResult .NoMatrixGateway
6770 } else {
68- Timber .tag(" DefaultUnifiedPushGatewayResolver " ).e(throwable, " Error checking for UnifiedPush endpoint" )
71+ Timber .tag(loggerTag.value ).e(throwable, " Error checking for UnifiedPush endpoint" )
6972 UnifiedPushGatewayResolverResult .Error (customUrl)
7073 }
7174 }
0 commit comments