Skip to content

Commit 531d316

Browse files
committed
Treat an absent namespaces field as unknown, not as no Jetpack
An absent namespaces list now carries the stored Jetpack state forward instead of definitively clearing it, and the stored-row lookup tries both schemes even when the caller's URL already has one.
1 parent fd1fbcc commit 531d316

2 files changed

Lines changed: 14 additions & 18 deletions

File tree

libs/fluxc/src/main/java/org/wordpress/android/fluxc/network/rest/wpapi/site/SiteWPAPIRestClient.kt

Lines changed: 11 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -148,8 +148,9 @@ class SiteWPAPIRestClient @Inject constructor(
148148
* The `jetpack/` REST namespace is only a first filter: it's registered by the shared
149149
* `automattic/jetpack-connection` package, which also ships inside Jetpack Boost, Protect, Social and
150150
* VaultPress Backup, so its presence does *not* mean the Jetpack plugin is installed. What it does give
151-
* us for free is a reliable negative -- no namespace, no active Jetpack -- which keeps the plugin lookup
152-
* off the refresh path for the sites that have nothing to do with Jetpack.
151+
* us for free is a reliable negative -- a namespace list without `jetpack/` means no active Jetpack --
152+
* which keeps the plugin lookup off the refresh path for the sites that have nothing to do with Jetpack.
153+
* That only holds when the list is present: an absent field is "couldn't read", not "no Jetpack".
153154
*
154155
* Reading the plugin list needs credentials and the `activate_plugins` capability, so it returns null for
155156
* sites without an application password and for users who aren't administrators. Callers must read null
@@ -159,17 +160,14 @@ class SiteWPAPIRestClient @Inject constructor(
159160
namespaces: List<String>?,
160161
apiRootUrl: String,
161162
payload: FetchWPAPISitePayload
162-
): JetpackPluginState? {
163-
val hasJetpackNamespace = namespaces?.any { it.startsWith(JETPACK_API_NAMESPACE_PREFIX) } ?: false
164-
if (!hasJetpackNamespace) return JetpackPluginState(isActive = false, version = null)
165-
166-
val username = payload.username
167-
val password = payload.password
168-
return if (payload.isApplicationPassword && !username.isNullOrEmpty() && !password.isNullOrEmpty()) {
169-
requestJetpackPlugin(apiRootUrl, username, password)
170-
} else {
171-
null
172-
}
163+
): JetpackPluginState? = when {
164+
namespaces == null -> null
165+
namespaces.none { it.startsWith(JETPACK_API_NAMESPACE_PREFIX) } ->
166+
JetpackPluginState(isActive = false, version = null)
167+
payload.isApplicationPassword &&
168+
!payload.username.isNullOrEmpty() && !payload.password.isNullOrEmpty() ->
169+
requestJetpackPlugin(apiRootUrl, payload.username.orEmpty(), payload.password.orEmpty())
170+
else -> null
173171
}
174172

175173
private suspend fun requestJetpackPlugin(

libs/fluxc/src/main/java/org/wordpress/android/fluxc/store/SiteStore.kt

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1469,11 +1469,9 @@ open class SiteStore @Inject constructor(
14691469
*/
14701470
private fun storedWPAPISite(url: String?): SiteModel? {
14711471
if (url.isNullOrEmpty()) return null
1472-
return if (url.contains("://")) {
1473-
siteSqlUtils.getWPAPISiteByUrl(url)
1474-
} else {
1475-
siteSqlUtils.getWPAPISiteByUrl("http://$url") ?: siteSqlUtils.getWPAPISiteByUrl("https://$url")
1476-
}
1472+
val bareUrl = url.substringAfter("://")
1473+
return siteSqlUtils.getWPAPISiteByUrl("https://$bareUrl")
1474+
?: siteSqlUtils.getWPAPISiteByUrl("http://$bareUrl")
14771475
}
14781476

14791477
suspend fun fetchWPAPISite(payload: FetchWPAPISitePayload): OnSiteChanged {

0 commit comments

Comments
 (0)