-
Notifications
You must be signed in to change notification settings - Fork 743
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes room hierarchy endpoint to stable #5443
Changes from 17 commits
3b0a565
bc3b8d0
0af6ae6
e5299d7
eb46067
82b5fc9
510206a
0892525
54828f7
31f300c
fb374b7
63cd79d
047e767
bbc6e8b
f76f73f
2f706d6
a891f59
a5af478
7226864
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
Adds stable room hierarchy endpoint with a fallback to the unstable one |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -19,6 +19,7 @@ package org.matrix.android.sdk.internal.session.space | |
import org.matrix.android.sdk.internal.network.GlobalErrorReceiver | ||
import org.matrix.android.sdk.internal.network.executeRequest | ||
import org.matrix.android.sdk.internal.task.Task | ||
import retrofit2.HttpException | ||
import javax.inject.Inject | ||
|
||
internal interface ResolveSpaceInfoTask : Task<ResolveSpaceInfoTask.Params, SpacesResponse> { | ||
|
@@ -28,22 +29,39 @@ internal interface ResolveSpaceInfoTask : Task<ResolveSpaceInfoTask.Params, Spac | |
val maxDepth: Int?, | ||
val from: String?, | ||
val suggestedOnly: Boolean? | ||
// val autoJoinOnly: Boolean? | ||
) | ||
} | ||
|
||
internal class DefaultResolveSpaceInfoTask @Inject constructor( | ||
private val spaceApi: SpaceApi, | ||
private val globalErrorReceiver: GlobalErrorReceiver | ||
) : ResolveSpaceInfoTask { | ||
override suspend fun execute(params: ResolveSpaceInfoTask.Params): SpacesResponse { | ||
return executeRequest(globalErrorReceiver) { | ||
|
||
override suspend fun execute(params: ResolveSpaceInfoTask.Params) = executeRequest(globalErrorReceiver) { | ||
getSpaceHierarchy(params) | ||
} | ||
|
||
private suspend fun getSpaceHierarchy(params: ResolveSpaceInfoTask.Params) = try { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I found using override suspend fun execute(params: ResolveSpaceInfoTask.Params) {
executeRequest(globalErrorReceiver) {
try {
getUnstableSpaceHierarchy(params)
} catch (e: HttpException) {
getStableSpaceHierarchy(params)
}
}
} Also I would rename There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Good shout! |
||
getStableSpaceHierarchy(params) | ||
} catch (e: HttpException) { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Why not using There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I think it would be good to protect ourselves from other server related errors (e.g. 500 - internal server error) and fallback to the unstable api in such cases. Anyway happy to discuss this before merging |
||
getUnstableSpaceHierarchy(params) | ||
} | ||
|
||
private suspend fun getStableSpaceHierarchy(params: ResolveSpaceInfoTask.Params) = | ||
spaceApi.getSpaceHierarchy( | ||
spaceId = params.spaceId, | ||
suggestedOnly = params.suggestedOnly, | ||
limit = params.limit, | ||
maxDepth = params.maxDepth, | ||
from = params.from) | ||
} | ||
} | ||
from = params.from, | ||
) | ||
|
||
private suspend fun getUnstableSpaceHierarchy(params: ResolveSpaceInfoTask.Params) = | ||
spaceApi.getSpaceHierarchyUnstable( | ||
spaceId = params.spaceId, | ||
suggestedOnly = params.suggestedOnly, | ||
limit = params.limit, | ||
maxDepth = params.maxDepth, | ||
from = params.from, | ||
) | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,60 @@ | ||
/* | ||
* Copyright 2021 The Matrix.org Foundation C.I.C. | ||
* | ||
* Licensed under the Apache License, Version 2.0 (the "License"); | ||
* you may not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
*/ | ||
|
||
package org.matrix.android.sdk.internal.session.space | ||
|
||
import kotlinx.coroutines.ExperimentalCoroutinesApi | ||
import kotlinx.coroutines.test.runBlockingTest | ||
import okhttp3.ResponseBody.Companion.toResponseBody | ||
import org.amshove.kluent.shouldBeEqualTo | ||
import org.junit.Test | ||
import org.matrix.android.sdk.test.fakes.FakeGlobalErrorReceiver | ||
import org.matrix.android.sdk.test.fakes.FakeSpaceApi | ||
import org.matrix.android.sdk.test.fixtures.SpacesResponseFixture.aSpacesResponse | ||
import retrofit2.HttpException | ||
import retrofit2.Response | ||
|
||
@ExperimentalCoroutinesApi | ||
internal class DefaultResolveSpaceInfoTaskTest { | ||
|
||
private val spaceApi = FakeSpaceApi() | ||
private val globalErrorReceiver = FakeGlobalErrorReceiver() | ||
private val resolveSpaceInfoTask = DefaultResolveSpaceInfoTask(spaceApi.instance, globalErrorReceiver) | ||
|
||
@Test | ||
fun `given stable endpoint works, when execute, then return stable api data`() = runBlockingTest { | ||
spaceApi.givenStableEndpointReturns(response) | ||
|
||
val result = resolveSpaceInfoTask.execute(spaceApi.params) | ||
|
||
result shouldBeEqualTo response | ||
} | ||
|
||
@Test | ||
fun `given stable endpoint fails, when execute, then fallback to unstable endpoint`() = runBlockingTest { | ||
spaceApi.givenStableEndpointThrows(httpException) | ||
spaceApi.givenUnstableEndpointReturns(response) | ||
|
||
val result = resolveSpaceInfoTask.execute(spaceApi.params) | ||
|
||
result shouldBeEqualTo response | ||
} | ||
|
||
companion object { | ||
private val response = aSpacesResponse() | ||
private val httpException = HttpException(Response.error<SpacesResponse>(500, "".toResponseBody())) | ||
} | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,41 @@ | ||
/* | ||
* Copyright 2021 The Matrix.org Foundation C.I.C. | ||
* | ||
* Licensed under the Apache License, Version 2.0 (the "License"); | ||
* you may not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
*/ | ||
|
||
package org.matrix.android.sdk.test.fakes | ||
|
||
import io.mockk.coEvery | ||
import io.mockk.mockk | ||
import org.matrix.android.sdk.internal.session.space.SpaceApi | ||
import org.matrix.android.sdk.internal.session.space.SpacesResponse | ||
import org.matrix.android.sdk.test.fixtures.ResolveSpaceInfoTaskParamsFixture | ||
|
||
internal class FakeSpaceApi { | ||
|
||
val instance: SpaceApi = mockk() | ||
val params = ResolveSpaceInfoTaskParamsFixture.aResolveSpaceInfoTaskParams() | ||
|
||
fun givenStableEndpointReturns(response: SpacesResponse) { | ||
coEvery { instance.getSpaceHierarchy(params.spaceId, params.suggestedOnly, params.limit, params.maxDepth, params.from) } returns response | ||
} | ||
|
||
fun givenStableEndpointThrows(throwable: Throwable) { | ||
coEvery { instance.getSpaceHierarchy(params.spaceId, params.suggestedOnly, params.limit, params.maxDepth, params.from) } throws throwable | ||
} | ||
|
||
fun givenUnstableEndpointReturns(response: SpacesResponse) { | ||
coEvery { instance.getSpaceHierarchyUnstable(params.spaceId, params.suggestedOnly, params.limit, params.maxDepth, params.from) } returns response | ||
} | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@bmarty please pay more attention to this line. This is where
{children_state event}.roomId
was being used. I can only assume its intended use was to point to the space id? Please correct me if I'm wrong.I don't have a great understanding of spacesEdit: Spoke to @clokep to get more info on this. I believe this to be correct
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
👍