Permalink: move method implementation from service to factory

This commit is contained in:
Florian Renaud 2021-09-07 15:59:59 +02:00 committed by Florian Renaud
parent 744523b200
commit afb49430be
2 changed files with 5 additions and 10 deletions

View file

@ -18,7 +18,6 @@ package org.matrix.android.sdk.internal.session.permalinks
import org.matrix.android.sdk.api.session.events.model.Event
import org.matrix.android.sdk.api.session.permalinks.PermalinkService
import org.matrix.android.sdk.api.session.permalinks.PermalinkService.Companion.MATRIX_TO_URL_BASE
import javax.inject.Inject
internal class DefaultPermalinkService @Inject constructor(
@ -42,9 +41,6 @@ internal class DefaultPermalinkService @Inject constructor(
}
override fun getLinkedId(url: String): String? {
return url
.takeIf { it.startsWith(MATRIX_TO_URL_BASE) }
?.substring(MATRIX_TO_URL_BASE.length)
?.substringBeforeLast("?")
return permalinkFactory.getLinkedId(url)
}
}

View file

@ -60,11 +60,10 @@ internal class PermalinkFactory @Inject constructor(
}
fun getLinkedId(url: String): String? {
val isSupported = url.startsWith(MATRIX_TO_URL_BASE)
return if (isSupported) {
url.substring(MATRIX_TO_URL_BASE.length)
} else null
return url
.takeIf { it.startsWith(MATRIX_TO_URL_BASE) }
?.substring(MATRIX_TO_URL_BASE.length)
?.substringBeforeLast("?")
}
/**