mirror of
https://github.com/element-hq/element-android
synced 2024-11-28 05:31:21 +03:00
Benoit Review: cleanup
This commit is contained in:
parent
b380fa0653
commit
46290f1ed4
10 changed files with 48 additions and 32 deletions
|
@ -60,7 +60,7 @@ class SpaceCreationTest : InstrumentedTest {
|
||||||
val spaceId: String
|
val spaceId: String
|
||||||
runBlocking {
|
runBlocking {
|
||||||
spaceId = session.spaceService().createSpace(roomName, topic, null, true)
|
spaceId = session.spaceService().createSpace(roomName, topic, null, true)
|
||||||
// wait a bit to let the summry update it self :/
|
// wait a bit to let the summary update it self :/
|
||||||
delay(400)
|
delay(400)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -100,14 +100,14 @@ class SpaceCreationTest : InstrumentedTest {
|
||||||
@Test
|
@Test
|
||||||
fun testJoinSimplePublicSpace() {
|
fun testJoinSimplePublicSpace() {
|
||||||
val aliceSession = commonTestHelper.createAccount("alice", SessionTestParams(true))
|
val aliceSession = commonTestHelper.createAccount("alice", SessionTestParams(true))
|
||||||
val bobSession = commonTestHelper.createAccount("alice", SessionTestParams(true))
|
val bobSession = commonTestHelper.createAccount("bob", SessionTestParams(true))
|
||||||
|
|
||||||
val roomName = "My Space"
|
val roomName = "My Space"
|
||||||
val topic = "A public space for test"
|
val topic = "A public space for test"
|
||||||
val spaceId: String
|
val spaceId: String
|
||||||
runBlocking {
|
runBlocking {
|
||||||
spaceId = aliceSession.spaceService().createSpace(roomName, topic, null, true)
|
spaceId = aliceSession.spaceService().createSpace(roomName, topic, null, true)
|
||||||
// wait a bit to let the summry update it self :/
|
// wait a bit to let the summary update it self :/
|
||||||
delay(400)
|
delay(400)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -131,7 +131,7 @@ class SpaceCreationTest : InstrumentedTest {
|
||||||
@Test
|
@Test
|
||||||
fun testSimplePublicSpaceWithChildren() {
|
fun testSimplePublicSpaceWithChildren() {
|
||||||
val aliceSession = commonTestHelper.createAccount("alice", SessionTestParams(true))
|
val aliceSession = commonTestHelper.createAccount("alice", SessionTestParams(true))
|
||||||
val bobSession = commonTestHelper.createAccount("alice", SessionTestParams(true))
|
val bobSession = commonTestHelper.createAccount("bob", SessionTestParams(true))
|
||||||
|
|
||||||
val roomName = "My Space"
|
val roomName = "My Space"
|
||||||
val topic = "A public space for test"
|
val topic = "A public space for test"
|
||||||
|
|
|
@ -48,13 +48,13 @@ class SpaceHierarchyTest : InstrumentedTest {
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
fun createCanonicalChildRelation() {
|
fun createCanonicalChildRelation() {
|
||||||
val session = commonTestHelper.createAccount("Jhon", SessionTestParams(true))
|
val session = commonTestHelper.createAccount("John", SessionTestParams(true))
|
||||||
val spaceName = "My Space"
|
val spaceName = "My Space"
|
||||||
val topic = "A public space for test"
|
val topic = "A public space for test"
|
||||||
val spaceId: String
|
val spaceId: String
|
||||||
runBlocking {
|
runBlocking {
|
||||||
spaceId = session.spaceService().createSpace(spaceName, topic, null, true)
|
spaceId = session.spaceService().createSpace(spaceName, topic, null, true)
|
||||||
// wait a bit to let the summry update it self :/
|
// wait a bit to let the summary update it self :/
|
||||||
delay(400)
|
delay(400)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -94,5 +94,8 @@ interface Room :
|
||||||
afterLimit: Int,
|
afterLimit: Int,
|
||||||
includeProfile: Boolean): SearchResult
|
includeProfile: Boolean): SearchResult
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Use this room as a Space, if the type is correct.
|
||||||
|
*/
|
||||||
fun asSpace(): Space?
|
fun asSpace(): Space?
|
||||||
}
|
}
|
||||||
|
|
|
@ -31,10 +31,11 @@ fun spaceSummaryQueryParams(init: (RoomSummaryQueryParams.Builder.() -> Unit) =
|
||||||
return RoomSummaryQueryParams.Builder()
|
return RoomSummaryQueryParams.Builder()
|
||||||
.apply(init)
|
.apply(init)
|
||||||
.apply {
|
.apply {
|
||||||
this.includeType = listOf(RoomType.SPACE)
|
includeType = listOf(RoomType.SPACE)
|
||||||
this.excludeType = null
|
excludeType = null
|
||||||
this.roomCategoryFilter = RoomCategoryFilter.ONLY_ROOMS
|
roomCategoryFilter = RoomCategoryFilter.ONLY_ROOMS
|
||||||
}.build()
|
}
|
||||||
|
.build()
|
||||||
}
|
}
|
||||||
|
|
||||||
enum class RoomCategoryFilter {
|
enum class RoomCategoryFilter {
|
||||||
|
@ -42,6 +43,7 @@ enum class RoomCategoryFilter {
|
||||||
ONLY_ROOMS,
|
ONLY_ROOMS,
|
||||||
ALL
|
ALL
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* This class can be used to filter room summaries to use with:
|
* This class can be used to filter room summaries to use with:
|
||||||
* [org.matrix.android.sdk.api.session.room.Room] and [org.matrix.android.sdk.api.session.room.RoomService]
|
* [org.matrix.android.sdk.api.session.room.Room] and [org.matrix.android.sdk.api.session.room.RoomService]
|
||||||
|
|
|
@ -16,13 +16,20 @@
|
||||||
|
|
||||||
package org.matrix.android.sdk.api.session.space
|
package org.matrix.android.sdk.api.session.space
|
||||||
|
|
||||||
|
import org.matrix.android.sdk.api.MatrixCallback
|
||||||
import org.matrix.android.sdk.api.session.room.Room
|
import org.matrix.android.sdk.api.session.room.Room
|
||||||
import org.matrix.android.sdk.api.session.room.model.RoomSummary
|
import org.matrix.android.sdk.api.session.room.model.RoomSummary
|
||||||
|
import org.matrix.android.sdk.api.util.Cancelable
|
||||||
|
|
||||||
interface Space {
|
interface Space {
|
||||||
|
|
||||||
fun asRoom(): Room
|
fun asRoom(): Room
|
||||||
|
|
||||||
|
val spaceId: String
|
||||||
|
|
||||||
|
fun leave(reason: String? = null,
|
||||||
|
callback: MatrixCallback<Unit>): Cancelable
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* A current snapshot of [RoomSummary] associated with the space
|
* A current snapshot of [RoomSummary] associated with the space
|
||||||
*/
|
*/
|
||||||
|
|
|
@ -16,10 +16,7 @@
|
||||||
|
|
||||||
package org.matrix.android.sdk.internal.session.room
|
package org.matrix.android.sdk.internal.session.room
|
||||||
|
|
||||||
import org.matrix.android.sdk.api.session.room.model.RoomType
|
|
||||||
import org.matrix.android.sdk.api.session.space.Space
|
import org.matrix.android.sdk.api.session.space.Space
|
||||||
import org.matrix.android.sdk.internal.session.room.summary.RoomSummaryDataSource
|
|
||||||
import org.matrix.android.sdk.internal.session.space.DefaultSpace
|
|
||||||
import javax.inject.Inject
|
import javax.inject.Inject
|
||||||
|
|
||||||
internal interface SpaceGetter {
|
internal interface SpaceGetter {
|
||||||
|
@ -27,13 +24,10 @@ internal interface SpaceGetter {
|
||||||
}
|
}
|
||||||
|
|
||||||
internal class DefaultSpaceGetter @Inject constructor(
|
internal class DefaultSpaceGetter @Inject constructor(
|
||||||
private val roomGetter: RoomGetter,
|
private val roomGetter: RoomGetter
|
||||||
private val spaceSummaryDataSource: RoomSummaryDataSource
|
|
||||||
) : SpaceGetter {
|
) : SpaceGetter {
|
||||||
|
|
||||||
override fun get(spaceId: String): Space? {
|
override fun get(spaceId: String): Space? {
|
||||||
return roomGetter.getRoom(spaceId)
|
return roomGetter.getRoom(spaceId)?.asSpace()
|
||||||
?.takeIf { it.roomSummary()?.roomType == RoomType.SPACE }
|
|
||||||
?.let { DefaultSpace(it, spaceSummaryDataSource) }
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -98,9 +98,8 @@ internal class RoomSummaryDataSource @Inject constructor(@SessionDatabase privat
|
||||||
}
|
}
|
||||||
|
|
||||||
fun getSpaceSummary(roomIdOrAlias: String): RoomSummary? {
|
fun getSpaceSummary(roomIdOrAlias: String): RoomSummary? {
|
||||||
return getRoomSummary(roomIdOrAlias).let {
|
return getRoomSummary(roomIdOrAlias)
|
||||||
it?.takeIf { it.roomType == RoomType.SPACE }
|
?.takeIf { it.roomType == RoomType.SPACE }
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
fun getSpaceSummaryLive(roomId: String): LiveData<Optional<RoomSummary>> {
|
fun getSpaceSummaryLive(roomId: String): LiveData<Optional<RoomSummary>> {
|
||||||
|
|
|
@ -16,6 +16,7 @@
|
||||||
|
|
||||||
package org.matrix.android.sdk.internal.session.space
|
package org.matrix.android.sdk.internal.session.space
|
||||||
|
|
||||||
|
import org.matrix.android.sdk.api.MatrixCallback
|
||||||
import org.matrix.android.sdk.api.query.QueryStringValue
|
import org.matrix.android.sdk.api.query.QueryStringValue
|
||||||
import org.matrix.android.sdk.api.session.events.model.EventType
|
import org.matrix.android.sdk.api.session.events.model.EventType
|
||||||
import org.matrix.android.sdk.api.session.events.model.toContent
|
import org.matrix.android.sdk.api.session.events.model.toContent
|
||||||
|
@ -24,23 +25,33 @@ import org.matrix.android.sdk.api.session.room.Room
|
||||||
import org.matrix.android.sdk.api.session.room.model.RoomSummary
|
import org.matrix.android.sdk.api.session.room.model.RoomSummary
|
||||||
import org.matrix.android.sdk.api.session.space.Space
|
import org.matrix.android.sdk.api.session.space.Space
|
||||||
import org.matrix.android.sdk.api.session.space.model.SpaceChildContent
|
import org.matrix.android.sdk.api.session.space.model.SpaceChildContent
|
||||||
|
import org.matrix.android.sdk.api.util.Cancelable
|
||||||
import org.matrix.android.sdk.internal.session.room.summary.RoomSummaryDataSource
|
import org.matrix.android.sdk.internal.session.room.summary.RoomSummaryDataSource
|
||||||
|
|
||||||
internal class DefaultSpace(private val room: Room, private val spaceSummaryDataSource: RoomSummaryDataSource) : Space {
|
internal class DefaultSpace(
|
||||||
|
private val room: Room,
|
||||||
|
private val spaceSummaryDataSource: RoomSummaryDataSource
|
||||||
|
) : Space {
|
||||||
|
|
||||||
override fun asRoom(): Room {
|
override fun asRoom(): Room {
|
||||||
return room
|
return room
|
||||||
}
|
}
|
||||||
|
|
||||||
|
override val spaceId = room.roomId
|
||||||
|
|
||||||
|
override fun leave(reason: String?, callback: MatrixCallback<Unit>): Cancelable {
|
||||||
|
return room.leave(reason, callback)
|
||||||
|
}
|
||||||
|
|
||||||
override fun spaceSummary(): RoomSummary? {
|
override fun spaceSummary(): RoomSummary? {
|
||||||
return spaceSummaryDataSource.getSpaceSummary(asRoom().roomId)
|
return spaceSummaryDataSource.getSpaceSummary(room.roomId)
|
||||||
}
|
}
|
||||||
|
|
||||||
override suspend fun addChildren(roomId: String, viaServers: List<String>,
|
override suspend fun addChildren(roomId: String, viaServers: List<String>,
|
||||||
order: String?,
|
order: String?,
|
||||||
autoJoin: Boolean,
|
autoJoin: Boolean,
|
||||||
suggested: Boolean?) {
|
suggested: Boolean?) {
|
||||||
asRoom().sendStateEvent(
|
room.sendStateEvent(
|
||||||
eventType = EventType.STATE_SPACE_CHILD,
|
eventType = EventType.STATE_SPACE_CHILD,
|
||||||
stateKey = roomId,
|
stateKey = roomId,
|
||||||
body = SpaceChildContent(
|
body = SpaceChildContent(
|
||||||
|
@ -53,14 +64,14 @@ internal class DefaultSpace(private val room: Room, private val spaceSummaryData
|
||||||
}
|
}
|
||||||
|
|
||||||
override suspend fun removeRoom(roomId: String) {
|
override suspend fun removeRoom(roomId: String) {
|
||||||
val existing = asRoom().getStateEvents(setOf(EventType.STATE_SPACE_CHILD), QueryStringValue.Equals(roomId))
|
val existing = room.getStateEvents(setOf(EventType.STATE_SPACE_CHILD), QueryStringValue.Equals(roomId))
|
||||||
.firstOrNull()
|
.firstOrNull()
|
||||||
?.content.toModel<SpaceChildContent>()
|
?.content.toModel<SpaceChildContent>()
|
||||||
?: // should we throw here?
|
?: // should we throw here?
|
||||||
return
|
return
|
||||||
|
|
||||||
// edit state event and set via to null
|
// edit state event and set via to null
|
||||||
asRoom().sendStateEvent(
|
room.sendStateEvent(
|
||||||
eventType = EventType.STATE_SPACE_CHILD,
|
eventType = EventType.STATE_SPACE_CHILD,
|
||||||
stateKey = roomId,
|
stateKey = roomId,
|
||||||
body = SpaceChildContent(
|
body = SpaceChildContent(
|
||||||
|
@ -72,13 +83,13 @@ internal class DefaultSpace(private val room: Room, private val spaceSummaryData
|
||||||
}
|
}
|
||||||
|
|
||||||
override suspend fun setChildrenOrder(roomId: String, order: String?) {
|
override suspend fun setChildrenOrder(roomId: String, order: String?) {
|
||||||
val existing = asRoom().getStateEvents(setOf(EventType.STATE_SPACE_CHILD), QueryStringValue.Equals(roomId))
|
val existing = room.getStateEvents(setOf(EventType.STATE_SPACE_CHILD), QueryStringValue.Equals(roomId))
|
||||||
.firstOrNull()
|
.firstOrNull()
|
||||||
?.content.toModel<SpaceChildContent>()
|
?.content.toModel<SpaceChildContent>()
|
||||||
?: throw IllegalArgumentException("$roomId is not a child of this space")
|
?: throw IllegalArgumentException("$roomId is not a child of this space")
|
||||||
|
|
||||||
// edit state event and set via to null
|
// edit state event and set via to null
|
||||||
asRoom().sendStateEvent(
|
room.sendStateEvent(
|
||||||
eventType = EventType.STATE_SPACE_CHILD,
|
eventType = EventType.STATE_SPACE_CHILD,
|
||||||
stateKey = roomId,
|
stateKey = roomId,
|
||||||
body = SpaceChildContent(
|
body = SpaceChildContent(
|
||||||
|
@ -90,13 +101,13 @@ internal class DefaultSpace(private val room: Room, private val spaceSummaryData
|
||||||
}
|
}
|
||||||
|
|
||||||
override suspend fun setChildrenAutoJoin(roomId: String, autoJoin: Boolean) {
|
override suspend fun setChildrenAutoJoin(roomId: String, autoJoin: Boolean) {
|
||||||
val existing = asRoom().getStateEvents(setOf(EventType.STATE_SPACE_CHILD), QueryStringValue.Equals(roomId))
|
val existing = room.getStateEvents(setOf(EventType.STATE_SPACE_CHILD), QueryStringValue.Equals(roomId))
|
||||||
.firstOrNull()
|
.firstOrNull()
|
||||||
?.content.toModel<SpaceChildContent>()
|
?.content.toModel<SpaceChildContent>()
|
||||||
?: throw IllegalArgumentException("$roomId is not a child of this space")
|
?: throw IllegalArgumentException("$roomId is not a child of this space")
|
||||||
|
|
||||||
// edit state event and set via to null
|
// edit state event and set via to null
|
||||||
asRoom().sendStateEvent(
|
room.sendStateEvent(
|
||||||
eventType = EventType.STATE_SPACE_CHILD,
|
eventType = EventType.STATE_SPACE_CHILD,
|
||||||
stateKey = roomId,
|
stateKey = roomId,
|
||||||
body = SpaceChildContent(
|
body = SpaceChildContent(
|
||||||
|
|
|
@ -176,7 +176,7 @@ class SpacesListViewModel @AssistedInject constructor(@Assisted initialState: Sp
|
||||||
viewModelScope.launch {
|
viewModelScope.launch {
|
||||||
awaitCallback {
|
awaitCallback {
|
||||||
tryOrNull("Failed to leave space ${action.spaceSummary.roomId}") {
|
tryOrNull("Failed to leave space ${action.spaceSummary.roomId}") {
|
||||||
session.spaceService().getSpace(action.spaceSummary.roomId)?.asRoom()?.leave(null, it)
|
session.spaceService().getSpace(action.spaceSummary.roomId)?.leave(null, it)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -80,7 +80,7 @@ class CreateSpaceViewModelTask @Inject constructor(
|
||||||
// set canonical
|
// set canonical
|
||||||
session.spaceService().setSpaceParent(
|
session.spaceService().setSpaceParent(
|
||||||
roomId,
|
roomId,
|
||||||
createdSpace.asRoom().roomId,
|
createdSpace.spaceId,
|
||||||
true,
|
true,
|
||||||
via
|
via
|
||||||
)
|
)
|
||||||
|
|
Loading…
Reference in a new issue