From 66ac298e9529edcc84bcf129ea808d0a3fe9623c Mon Sep 17 00:00:00 2001 From: Benoit Marty Date: Fri, 26 Mar 2021 19:23:13 +0100 Subject: [PATCH] Benoit Review: cleanup 2 --- .../java/org/matrix/android/sdk/rx/RxSession.kt | 4 ++-- .../sdk/session/space/SpaceHierarchyTest.kt | 10 +++++----- .../android/sdk/api/session/room/RoomService.kt | 6 +++++- .../room/model/RoomThirdPartyInviteContent.kt | 2 +- .../session/room/model/create/CreateRoomParams.kt | 3 +++ .../matrix/android/sdk/api/session/space/Space.kt | 5 +++-- .../android/sdk/api/session/space/SpaceService.kt | 12 +++++++----- .../api/session/space/model/SpaceChildContent.kt | 6 ++---- .../sdk/internal/crypto/DefaultCryptoService.kt | 2 +- .../sdk/internal/database/RealmQueryLatch.kt | 2 -- .../sdk/internal/session/DefaultSession.kt | 4 ++-- .../internal/session/room/DefaultRoomService.kt | 4 ++-- .../internal/session/room/peeking/PeekRoomTask.kt | 4 +++- .../room/relationship/RoomChildRelationInfo.kt | 7 ++++--- .../room/summary/HierarchyLiveDataHelper.kt | 2 +- .../session/room/summary/RoomSummaryDataSource.kt | 14 +++++--------- .../sdk/internal/session/space/DefaultSpace.kt | 5 +++-- .../internal/session/space/DefaultSpaceService.kt | 10 +++++----- .../sdk/internal/session/space/JoinSpaceTask.kt | 6 ++---- .../session/space/ResolveSpaceInfoTask.kt | 15 ++++++++++++--- .../sdk/internal/session/space/SpaceApi.kt | 3 +-- .../sdk/internal/session/space/SpaceModule.kt | 4 ++-- .../session/space/peeking/PeekSpaceTask.kt | 4 +++- .../session/space/peeking/SpacePeekResult.kt | 1 + .../sdk/internal/session/sync/RoomSyncHandler.kt | 2 +- .../session/sync/model/RoomSyncAccountData.kt | 2 +- .../session/sync/model/RoomSyncEphemeral.kt | 2 +- .../internal/session/sync/model/RoomSyncState.kt | 2 +- .../session/sync/model/RoomSyncTimeline.kt | 2 +- 29 files changed, 80 insertions(+), 65 deletions(-) diff --git a/matrix-sdk-android-rx/src/main/java/org/matrix/android/sdk/rx/RxSession.kt b/matrix-sdk-android-rx/src/main/java/org/matrix/android/sdk/rx/RxSession.kt index 38b0a3a343..7f794be399 100644 --- a/matrix-sdk-android-rx/src/main/java/org/matrix/android/sdk/rx/RxSession.kt +++ b/matrix-sdk-android-rx/src/main/java/org/matrix/android/sdk/rx/RxSession.kt @@ -75,9 +75,9 @@ class RxSession(private val session: Session) { } fun liveFlattenRoomSummaryChildOf(spaceId: String?): Observable> { - return session.getFlattenRoomSummaryChildOfLive(spaceId).asObservable() + return session.getFlattenRoomSummaryChildrenOfLive(spaceId).asObservable() .startWithCallable { - session.getFlattenRoomSummaryChildOf(spaceId) + session.getFlattenRoomSummaryChildrenOf(spaceId) } } diff --git a/matrix-sdk-android/src/androidTest/java/org/matrix/android/sdk/session/space/SpaceHierarchyTest.kt b/matrix-sdk-android/src/androidTest/java/org/matrix/android/sdk/session/space/SpaceHierarchyTest.kt index 4e0284469b..e3b4fba901 100644 --- a/matrix-sdk-android/src/androidTest/java/org/matrix/android/sdk/session/space/SpaceHierarchyTest.kt +++ b/matrix-sdk-android/src/androidTest/java/org/matrix/android/sdk/session/space/SpaceHierarchyTest.kt @@ -180,13 +180,13 @@ class SpaceHierarchyTest : InstrumentedTest { assertEquals(9, allRooms.size, "Unexpected number of rooms") - val orphans = session.getFlattenRoomSummaryChildOf(null) + val orphans = session.getFlattenRoomSummaryChildrenOf(null) assertEquals(2, orphans.size, "Unexpected number of orphan rooms") assertTrue(orphans.indexOfFirst { it.roomId == orphan1 } != -1, "O1 should be an orphan") assertTrue(orphans.indexOfFirst { it.roomId == orphan2 } != -1, "O2 should be an orphan ${orphans.map { it.name }}") - val aChildren = session.getFlattenRoomSummaryChildOf(spaceAInfo.spaceId) + val aChildren = session.getFlattenRoomSummaryChildrenOf(spaceAInfo.spaceId) assertEquals(4, aChildren.size, "Unexpected number of flatten child rooms") assertTrue(aChildren.indexOfFirst { it.name == "A1" } != -1, "A1 should be a child of A") @@ -204,7 +204,7 @@ class SpaceHierarchyTest : InstrumentedTest { // here we do not set the parent!! } - val orphansUpdate = session.getFlattenRoomSummaryChildOf(null) + val orphansUpdate = session.getFlattenRoomSummaryChildrenOf(null) assertEquals(2, orphansUpdate.size, "Unexpected number of orphan rooms ${orphansUpdate.map { it.name }}") } @@ -240,7 +240,7 @@ class SpaceHierarchyTest : InstrumentedTest { // A -> C -> A - val aChildren = session.getFlattenRoomSummaryChildOf(spaceAInfo.spaceId) + val aChildren = session.getFlattenRoomSummaryChildrenOf(spaceAInfo.spaceId) assertEquals(4, aChildren.size, "Unexpected number of flatten child rooms ${aChildren.map { it.name }}") assertTrue(aChildren.indexOfFirst { it.name == "A1" } != -1, "A1 should be a child of A") @@ -273,7 +273,7 @@ class SpaceHierarchyTest : InstrumentedTest { } val flatAChildren = runBlocking(Dispatchers.Main) { - session.getFlattenRoomSummaryChildOfLive(spaceAInfo.spaceId) + session.getFlattenRoomSummaryChildrenOfLive(spaceAInfo.spaceId) } commonTestHelper.waitWithLatch { latch -> diff --git a/matrix-sdk-android/src/main/java/org/matrix/android/sdk/api/session/room/RoomService.kt b/matrix-sdk-android/src/main/java/org/matrix/android/sdk/api/session/room/RoomService.kt index 5296ad58b0..982a67c4c2 100644 --- a/matrix-sdk-android/src/main/java/org/matrix/android/sdk/api/session/room/RoomService.kt +++ b/matrix-sdk-android/src/main/java/org/matrix/android/sdk/api/session/room/RoomService.kt @@ -201,5 +201,9 @@ interface RoomService { fun getFlattenRoomSummaryChildOf(spaceId: String?, memberships: List = Membership.activeMemberships()) : List - fun getFlattenRoomSummaryChildOfLive(spaceId: String?, memberships: List = Membership.activeMemberships()): LiveData> + /** + * Returns all the children of this space, as LiveData + */ + fun getFlattenRoomSummaryChildrenOfLive(spaceId: String?, + memberships: List = Membership.activeMemberships()): LiveData> } diff --git a/matrix-sdk-android/src/main/java/org/matrix/android/sdk/api/session/room/model/RoomThirdPartyInviteContent.kt b/matrix-sdk-android/src/main/java/org/matrix/android/sdk/api/session/room/model/RoomThirdPartyInviteContent.kt index 56503e3e35..a8a2cfb68b 100644 --- a/matrix-sdk-android/src/main/java/org/matrix/android/sdk/api/session/room/model/RoomThirdPartyInviteContent.kt +++ b/matrix-sdk-android/src/main/java/org/matrix/android/sdk/api/session/room/model/RoomThirdPartyInviteContent.kt @@ -47,7 +47,7 @@ data class RoomThirdPartyInviteContent( /** * Keys with which the token may be signed. */ - @Json(name = "public_keys") val publicKeys: List? = emptyList() + @Json(name = "public_keys") val publicKeys: List? ) @JsonClass(generateAdapter = true) diff --git a/matrix-sdk-android/src/main/java/org/matrix/android/sdk/api/session/room/model/create/CreateRoomParams.kt b/matrix-sdk-android/src/main/java/org/matrix/android/sdk/api/session/room/model/create/CreateRoomParams.kt index 24e4fe36d2..82c6e187f8 100644 --- a/matrix-sdk-android/src/main/java/org/matrix/android/sdk/api/session/room/model/create/CreateRoomParams.kt +++ b/matrix-sdk-android/src/main/java/org/matrix/android/sdk/api/session/room/model/create/CreateRoomParams.kt @@ -69,6 +69,9 @@ open class CreateRoomParams { */ val invite3pids = mutableListOf() + /** + * Initial Guest Access + */ var guestAccess: GuestAccess? = null /** diff --git a/matrix-sdk-android/src/main/java/org/matrix/android/sdk/api/session/space/Space.kt b/matrix-sdk-android/src/main/java/org/matrix/android/sdk/api/session/space/Space.kt index fda1465ac8..7de40b0019 100644 --- a/matrix-sdk-android/src/main/java/org/matrix/android/sdk/api/session/space/Space.kt +++ b/matrix-sdk-android/src/main/java/org/matrix/android/sdk/api/session/space/Space.kt @@ -35,12 +35,13 @@ interface Space { */ fun spaceSummary(): RoomSummary? - suspend fun addChildren(roomId: String, viaServers: List, + suspend fun addChildren(roomId: String, + viaServers: List, order: String?, autoJoin: Boolean = false, suggested: Boolean? = false) - suspend fun removeRoom(roomId: String) + suspend fun removeChildren(roomId: String) @Throws suspend fun setChildrenOrder(roomId: String, order: String?) diff --git a/matrix-sdk-android/src/main/java/org/matrix/android/sdk/api/session/space/SpaceService.kt b/matrix-sdk-android/src/main/java/org/matrix/android/sdk/api/session/space/SpaceService.kt index 604d06d9ff..1f88403eab 100644 --- a/matrix-sdk-android/src/main/java/org/matrix/android/sdk/api/session/space/SpaceService.kt +++ b/matrix-sdk-android/src/main/java/org/matrix/android/sdk/api/session/space/SpaceService.kt @@ -28,7 +28,8 @@ typealias SpaceSummaryQueryParams = RoomSummaryQueryParams interface SpaceService { /** - * Create a room asynchronously + * Create a space asynchronously + * @return the spaceId of the created space */ suspend fun createSpace(params: CreateSpaceParams): String @@ -39,8 +40,8 @@ interface SpaceService { /** * Get a space from a roomId - * @param roomId the roomId to look for. - * @return a room with roomId or null if room type is not space + * @param spaceId the roomId to look for. + * @return a space with spaceId or null if room type is not space */ fun getSpace(spaceId: String): Space? @@ -54,8 +55,9 @@ interface SpaceService { /** * Get's information of a space by querying the server */ - suspend fun querySpaceChildren(spaceId: String, suggestedOnly: Boolean? = null, autoJoinedOnly: Boolean? = null) - : Pair> + suspend fun querySpaceChildren(spaceId: String, + suggestedOnly: Boolean? = null, + autoJoinedOnly: Boolean? = null): Pair> /** * Get a live list of space summaries. This list is refreshed as soon as the data changes. diff --git a/matrix-sdk-android/src/main/java/org/matrix/android/sdk/api/session/space/model/SpaceChildContent.kt b/matrix-sdk-android/src/main/java/org/matrix/android/sdk/api/session/space/model/SpaceChildContent.kt index f84d781eb6..e7936d00e5 100644 --- a/matrix-sdk-android/src/main/java/org/matrix/android/sdk/api/session/space/model/SpaceChildContent.kt +++ b/matrix-sdk-android/src/main/java/org/matrix/android/sdk/api/session/space/model/SpaceChildContent.kt @@ -60,11 +60,9 @@ data class SpaceChildContent( * or consist of more than 50 characters, are forbidden and should be ignored if received.) */ fun validOrder(): String? { - order?.let { - if (order.length > 50) return null - if (!ORDER_VALID_CHAR_REGEX.matches(it)) return null - } return order + ?.takeIf { it.length <= 50 } + ?.takeIf { ORDER_VALID_CHAR_REGEX.matches(it) } } companion object { diff --git a/matrix-sdk-android/src/main/java/org/matrix/android/sdk/internal/crypto/DefaultCryptoService.kt b/matrix-sdk-android/src/main/java/org/matrix/android/sdk/internal/crypto/DefaultCryptoService.kt index 4a18c29544..fac4e0d0b6 100755 --- a/matrix-sdk-android/src/main/java/org/matrix/android/sdk/internal/crypto/DefaultCryptoService.kt +++ b/matrix-sdk-android/src/main/java/org/matrix/android/sdk/internal/crypto/DefaultCryptoService.kt @@ -894,7 +894,7 @@ internal class DefaultCryptoService @Inject constructor( } } - private fun onRoomHistoryVisibilityEvent(roomId: String, event: Event) { + private fun onRoomHistoryVisibilityEvent(roomId: String, event: Event) { val eventContent = event.content.toModel() eventContent?.safeHistoryVisibility()?.let { cryptoStore.setShouldEncryptForInvitedMembers(roomId, it != RoomHistoryVisibility.JOINED) diff --git a/matrix-sdk-android/src/main/java/org/matrix/android/sdk/internal/database/RealmQueryLatch.kt b/matrix-sdk-android/src/main/java/org/matrix/android/sdk/internal/database/RealmQueryLatch.kt index 04f47bfccd..c9c797304a 100644 --- a/matrix-sdk-android/src/main/java/org/matrix/android/sdk/internal/database/RealmQueryLatch.kt +++ b/matrix-sdk-android/src/main/java/org/matrix/android/sdk/internal/database/RealmQueryLatch.kt @@ -26,7 +26,6 @@ import kotlinx.coroutines.CompletableDeferred import kotlinx.coroutines.Dispatchers import kotlinx.coroutines.withContext import kotlinx.coroutines.withTimeout -import timber.log.Timber internal suspend fun awaitNotEmptyResult(realmConfiguration: RealmConfiguration, timeoutMillis: Long, @@ -41,7 +40,6 @@ internal suspend fun awaitNotEmptyResult(realmConfiguration: RealmConfigurat val listener = object : RealmChangeListener> { override fun onChange(it: RealmResults) { - Timber.v("## Space: $it") if (it.isNotEmpty()) { result.removeChangeListener(this) latch.complete(Unit) diff --git a/matrix-sdk-android/src/main/java/org/matrix/android/sdk/internal/session/DefaultSession.kt b/matrix-sdk-android/src/main/java/org/matrix/android/sdk/internal/session/DefaultSession.kt index ecb680c691..6c574be826 100644 --- a/matrix-sdk-android/src/main/java/org/matrix/android/sdk/internal/session/DefaultSession.kt +++ b/matrix-sdk-android/src/main/java/org/matrix/android/sdk/internal/session/DefaultSession.kt @@ -121,9 +121,9 @@ internal class DefaultSession @Inject constructor( private val integrationManagerService: IntegrationManagerService, private val thirdPartyService: Lazy, private val callSignalingService: Lazy, + private val spaceService: Lazy, @UnauthenticatedWithCertificate - private val unauthenticatedWithCertificateOkHttpClient: Lazy, - private val spaceService: Lazy + private val unauthenticatedWithCertificateOkHttpClient: Lazy ) : Session, RoomService by roomService.get(), RoomDirectoryService by roomDirectoryService.get(), diff --git a/matrix-sdk-android/src/main/java/org/matrix/android/sdk/internal/session/room/DefaultRoomService.kt b/matrix-sdk-android/src/main/java/org/matrix/android/sdk/internal/session/room/DefaultRoomService.kt index cd39e633dd..070270aac9 100644 --- a/matrix-sdk-android/src/main/java/org/matrix/android/sdk/internal/session/room/DefaultRoomService.kt +++ b/matrix-sdk-android/src/main/java/org/matrix/android/sdk/internal/session/room/DefaultRoomService.kt @@ -173,14 +173,14 @@ internal class DefaultRoomService @Inject constructor( return peekRoomTask.execute(PeekRoomTask.Params(roomIdOrAlias)) } - override fun getFlattenRoomSummaryChildOf(spaceId: String?, memberships: List): List { + override fun getFlattenRoomSummaryChildrenOf(spaceId: String?, memberships: List): List { if (spaceId == null) { return roomSummaryDataSource.getFlattenOrphanRooms() } return roomSummaryDataSource.getAllRoomSummaryChildOf(spaceId, memberships) } - override fun getFlattenRoomSummaryChildOfLive(spaceId: String?, memberships: List): LiveData> { + override fun getFlattenRoomSummaryChildrenOfLive(spaceId: String?, memberships: List): LiveData> { if (spaceId == null) { return roomSummaryDataSource.getFlattenOrphanRoomsLive() } diff --git a/matrix-sdk-android/src/main/java/org/matrix/android/sdk/internal/session/room/peeking/PeekRoomTask.kt b/matrix-sdk-android/src/main/java/org/matrix/android/sdk/internal/session/room/peeking/PeekRoomTask.kt index ac37b3c812..c6f4bbb4e1 100644 --- a/matrix-sdk-android/src/main/java/org/matrix/android/sdk/internal/session/room/peeking/PeekRoomTask.kt +++ b/matrix-sdk-android/src/main/java/org/matrix/android/sdk/internal/session/room/peeking/PeekRoomTask.kt @@ -145,7 +145,9 @@ internal class DefaultPeekRoomTask @Inject constructor( val roomType = stateEvents .lastOrNull { it.type == EventType.STATE_ROOM_CREATE } - ?.let { it.content?.toModel()?.type } + ?.content + ?.toModel() + ?.type return PeekResult.Success( roomId = roomId, diff --git a/matrix-sdk-android/src/main/java/org/matrix/android/sdk/internal/session/room/relationship/RoomChildRelationInfo.kt b/matrix-sdk-android/src/main/java/org/matrix/android/sdk/internal/session/room/relationship/RoomChildRelationInfo.kt index 5c478c9b25..cff1019893 100644 --- a/matrix-sdk-android/src/main/java/org/matrix/android/sdk/internal/session/room/relationship/RoomChildRelationInfo.kt +++ b/matrix-sdk-android/src/main/java/org/matrix/android/sdk/internal/session/room/relationship/RoomChildRelationInfo.kt @@ -34,10 +34,11 @@ import timber.log.Timber * The state_key is the ID of a child room or space, and the content should contain a via key which gives * a list of candidate servers that can be used to join the room. present: true key is included to distinguish from a deleted state event. * - * - Separately, rooms can claim parents via the m.room.parent state event: + * - Separately, rooms can claim parents via the m.room.parent state event. */ -internal class RoomChildRelationInfo(private val realm: Realm, - private val roomId: String +internal class RoomChildRelationInfo( + private val realm: Realm, + private val roomId: String ) { data class SpaceChildInfo( diff --git a/matrix-sdk-android/src/main/java/org/matrix/android/sdk/internal/session/room/summary/HierarchyLiveDataHelper.kt b/matrix-sdk-android/src/main/java/org/matrix/android/sdk/internal/session/room/summary/HierarchyLiveDataHelper.kt index ced1ad963e..29db8431fd 100644 --- a/matrix-sdk-android/src/main/java/org/matrix/android/sdk/internal/session/room/summary/HierarchyLiveDataHelper.kt +++ b/matrix-sdk-android/src/main/java/org/matrix/android/sdk/internal/session/room/summary/HierarchyLiveDataHelper.kt @@ -29,7 +29,7 @@ internal class HierarchyLiveDataHelper( private val sources = HashMap>>() private val mediatorLiveData = MediatorLiveData>() - fun liveData() = mediatorLiveData + fun liveData(): LiveData> = mediatorLiveData init { onChange() diff --git a/matrix-sdk-android/src/main/java/org/matrix/android/sdk/internal/session/room/summary/RoomSummaryDataSource.kt b/matrix-sdk-android/src/main/java/org/matrix/android/sdk/internal/session/room/summary/RoomSummaryDataSource.kt index d91f3acfb1..335198af68 100644 --- a/matrix-sdk-android/src/main/java/org/matrix/android/sdk/internal/session/room/summary/RoomSummaryDataSource.kt +++ b/matrix-sdk-android/src/main/java/org/matrix/android/sdk/internal/session/room/summary/RoomSummaryDataSource.kt @@ -251,14 +251,10 @@ internal class RoomSummaryDataSource @Inject constructor(@SessionDatabase privat queryParams.includeType?.forEach { query.equalTo(RoomSummaryEntityFields.ROOM_TYPE, it) } - queryParams.roomCategoryFilter?.let { - when (it) { - RoomCategoryFilter.ONLY_DM -> query.equalTo(RoomSummaryEntityFields.IS_DIRECT, true) - RoomCategoryFilter.ONLY_ROOMS -> query.equalTo(RoomSummaryEntityFields.IS_DIRECT, false) - RoomCategoryFilter.ALL -> { - // nop - } - } + when (queryParams.roomCategoryFilter) { + RoomCategoryFilter.ONLY_DM -> query.equalTo(RoomSummaryEntityFields.IS_DIRECT, true) + RoomCategoryFilter.ONLY_ROOMS -> query.equalTo(RoomSummaryEntityFields.IS_DIRECT, false) + RoomCategoryFilter.ALL -> Unit // nop } return query } @@ -272,7 +268,7 @@ internal class RoomSummaryDataSource @Inject constructor(@SessionDatabase privat fun getAllRoomSummaryChildOfLive(spaceId: String, memberShips: List): LiveData> { // we want to listen to all spaces in hierarchy and on change compute back all childs - // and switch map to listen thoose? + // and switch map to listen those? val mediatorLiveData = HierarchyLiveDataHelper(spaceId, memberShips, this).liveData() return Transformations.switchMap(mediatorLiveData) { allIds -> diff --git a/matrix-sdk-android/src/main/java/org/matrix/android/sdk/internal/session/space/DefaultSpace.kt b/matrix-sdk-android/src/main/java/org/matrix/android/sdk/internal/session/space/DefaultSpace.kt index 6bcdf63bd8..cfd88c8ec6 100644 --- a/matrix-sdk-android/src/main/java/org/matrix/android/sdk/internal/session/space/DefaultSpace.kt +++ b/matrix-sdk-android/src/main/java/org/matrix/android/sdk/internal/session/space/DefaultSpace.kt @@ -47,7 +47,8 @@ internal class DefaultSpace( return spaceSummaryDataSource.getSpaceSummary(room.roomId) } - override suspend fun addChildren(roomId: String, viaServers: List, + override suspend fun addChildren(roomId: String, + viaServers: List, order: String?, autoJoin: Boolean, suggested: Boolean?) { @@ -63,7 +64,7 @@ internal class DefaultSpace( ) } - override suspend fun removeRoom(roomId: String) { + override suspend fun removeChildren(roomId: String) { val existing = room.getStateEvents(setOf(EventType.STATE_SPACE_CHILD), QueryStringValue.Equals(roomId)) .firstOrNull() ?.content.toModel() diff --git a/matrix-sdk-android/src/main/java/org/matrix/android/sdk/internal/session/space/DefaultSpaceService.kt b/matrix-sdk-android/src/main/java/org/matrix/android/sdk/internal/session/space/DefaultSpaceService.kt index 1dd49ae6ba..a116d4fe15 100644 --- a/matrix-sdk-android/src/main/java/org/matrix/android/sdk/internal/session/space/DefaultSpaceService.kt +++ b/matrix-sdk-android/src/main/java/org/matrix/android/sdk/internal/session/space/DefaultSpaceService.kt @@ -18,7 +18,6 @@ package org.matrix.android.sdk.internal.session.space import android.net.Uri import androidx.lifecycle.LiveData -import com.zhuinden.monarchy.Monarchy 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.toContent @@ -37,7 +36,6 @@ import org.matrix.android.sdk.api.session.space.SpaceService import org.matrix.android.sdk.api.session.space.SpaceSummaryQueryParams import org.matrix.android.sdk.api.session.space.model.SpaceChildContent import org.matrix.android.sdk.api.session.space.model.SpaceParentContent -import org.matrix.android.sdk.internal.di.SessionDatabase import org.matrix.android.sdk.internal.di.UserId import org.matrix.android.sdk.internal.session.room.RoomGetter import org.matrix.android.sdk.internal.session.room.SpaceGetter @@ -49,7 +47,6 @@ import org.matrix.android.sdk.internal.session.space.peeking.SpacePeekResult import javax.inject.Inject internal class DefaultSpaceService @Inject constructor( - @SessionDatabase private val monarchy: Monarchy, @UserId private val userId: String, private val createSpaceTask: CreateSpaceTask, private val joinSpaceTask: JoinSpaceTask, @@ -97,11 +94,14 @@ internal class DefaultSpaceService @Inject constructor( override fun getRootSpaceSummaries(): List { return roomSummaryDataSource.getRootSpaceSummaries() } + override suspend fun peekSpace(spaceId: String): SpacePeekResult { return peekSpaceTask.execute(PeekSpaceTask.Params(spaceId)) } - override suspend fun querySpaceChildren(spaceId: String, suggestedOnly: Boolean?, autoJoinedOnly: Boolean?): Pair> { + override suspend fun querySpaceChildren(spaceId: String, + suggestedOnly: Boolean?, + autoJoinedOnly: Boolean?): Pair> { return resolveSpaceInfoTask.execute(ResolveSpaceInfoTask.Params.withId(spaceId, suggestedOnly, autoJoinedOnly)).let { response -> val spaceDesc = response.rooms?.firstOrNull { it.roomId == spaceId } Pair( @@ -136,7 +136,7 @@ internal class DefaultSpaceService @Inject constructor( activeMemberCount = childSummary.numJoinedMembers, parentRoomId = childStateEv?.roomId ) - } ?: emptyList() + }.orEmpty() ) } } diff --git a/matrix-sdk-android/src/main/java/org/matrix/android/sdk/internal/session/space/JoinSpaceTask.kt b/matrix-sdk-android/src/main/java/org/matrix/android/sdk/internal/session/space/JoinSpaceTask.kt index 9379c0d650..7e9f2235b9 100644 --- a/matrix-sdk-android/src/main/java/org/matrix/android/sdk/internal/session/space/JoinSpaceTask.kt +++ b/matrix-sdk-android/src/main/java/org/matrix/android/sdk/internal/session/space/JoinSpaceTask.kt @@ -25,7 +25,6 @@ import org.matrix.android.sdk.internal.database.awaitNotEmptyResult import org.matrix.android.sdk.internal.database.model.RoomSummaryEntity import org.matrix.android.sdk.internal.database.model.RoomSummaryEntityFields import org.matrix.android.sdk.internal.di.SessionDatabase -import org.matrix.android.sdk.internal.session.room.RoomAPI import org.matrix.android.sdk.internal.session.room.membership.joining.JoinRoomTask import org.matrix.android.sdk.internal.session.room.summary.RoomSummaryDataSource import org.matrix.android.sdk.internal.task.Task @@ -42,7 +41,6 @@ internal interface JoinSpaceTask : Task() + val errors = mutableMapOf() Timber.v("## Space: > Sync done ...") // after that i should have the children (? do I need to paginate to get state) val summary = roomSummaryDataSource.getSpaceSummary(params.roomIdOrAlias) @@ -93,7 +91,7 @@ internal class DefaultJoinSpaceTask @Inject constructor( // I should try to join as well if (it.roomType == RoomType.SPACE) { // recursively join auto-joined child of this space? - when (val subspaceJoinResult = this.execute(JoinSpaceTask.Params(it.childRoomId, null, it.viaServers))) { + when (val subspaceJoinResult = execute(JoinSpaceTask.Params(it.childRoomId, null, it.viaServers))) { SpaceService.JoinSpaceResult.Success -> { // nop } diff --git a/matrix-sdk-android/src/main/java/org/matrix/android/sdk/internal/session/space/ResolveSpaceInfoTask.kt b/matrix-sdk-android/src/main/java/org/matrix/android/sdk/internal/session/space/ResolveSpaceInfoTask.kt index 4326b1934e..9bf6fa0256 100644 --- a/matrix-sdk-android/src/main/java/org/matrix/android/sdk/internal/session/space/ResolveSpaceInfoTask.kt +++ b/matrix-sdk-android/src/main/java/org/matrix/android/sdk/internal/session/space/ResolveSpaceInfoTask.kt @@ -16,6 +16,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 javax.inject.Inject @@ -31,13 +32,21 @@ internal interface ResolveSpaceInfoTask : Task(null) { + return executeRequest(globalErrorReceiver) { apiCall = spaceApi.getSpaces(params.spaceId, body) } } diff --git a/matrix-sdk-android/src/main/java/org/matrix/android/sdk/internal/session/space/SpaceApi.kt b/matrix-sdk-android/src/main/java/org/matrix/android/sdk/internal/session/space/SpaceApi.kt index 3a63cd0c01..8e64e89da7 100644 --- a/matrix-sdk-android/src/main/java/org/matrix/android/sdk/internal/session/space/SpaceApi.kt +++ b/matrix-sdk-android/src/main/java/org/matrix/android/sdk/internal/session/space/SpaceApi.kt @@ -38,6 +38,5 @@ internal interface SpaceApi { */ @POST(NetworkConstants.URI_API_PREFIX_PATH_UNSTABLE + "org.matrix.msc2946/rooms/{roomId}/spaces") fun getSpaces(@Path("roomId") spaceId: String, - @Body params: SpaceSummaryParams - ): Call + @Body params: SpaceSummaryParams): Call } diff --git a/matrix-sdk-android/src/main/java/org/matrix/android/sdk/internal/session/space/SpaceModule.kt b/matrix-sdk-android/src/main/java/org/matrix/android/sdk/internal/session/space/SpaceModule.kt index 84a2d5267f..34bc66baa0 100644 --- a/matrix-sdk-android/src/main/java/org/matrix/android/sdk/internal/session/space/SpaceModule.kt +++ b/matrix-sdk-android/src/main/java/org/matrix/android/sdk/internal/session/space/SpaceModule.kt @@ -49,8 +49,8 @@ internal abstract class SpaceModule { abstract fun bindJoinSpaceTask(task: DefaultJoinSpaceTask): JoinSpaceTask @Binds - abstract fun bindSpaceGetter(getter: DefaultSpaceGetter): SpaceGetter + abstract fun bindCreateSpaceTask(task: DefaultCreateSpaceTask): CreateSpaceTask @Binds - abstract fun bindCreateSpaceTask(getter: DefaultCreateSpaceTask): CreateSpaceTask + abstract fun bindSpaceGetter(getter: DefaultSpaceGetter): SpaceGetter } diff --git a/matrix-sdk-android/src/main/java/org/matrix/android/sdk/internal/session/space/peeking/PeekSpaceTask.kt b/matrix-sdk-android/src/main/java/org/matrix/android/sdk/internal/session/space/peeking/PeekSpaceTask.kt index 8faed5f784..f6b156a6fb 100644 --- a/matrix-sdk-android/src/main/java/org/matrix/android/sdk/internal/session/space/peeking/PeekSpaceTask.kt +++ b/matrix-sdk-android/src/main/java/org/matrix/android/sdk/internal/session/space/peeking/PeekSpaceTask.kt @@ -55,7 +55,9 @@ internal class DefaultPeekSpaceTask @Inject constructor( } val isSpace = stateEvents .lastOrNull { it.type == EventType.STATE_ROOM_CREATE && it.stateKey == "" } - ?.let { it.content?.toModel()?.type } == RoomType.SPACE + ?.content + ?.toModel() + ?.type == RoomType.SPACE if (!isSpace) return SpacePeekResult.NotSpaceType(params.roomIdOrAlias) diff --git a/matrix-sdk-android/src/main/java/org/matrix/android/sdk/internal/session/space/peeking/SpacePeekResult.kt b/matrix-sdk-android/src/main/java/org/matrix/android/sdk/internal/session/space/peeking/SpacePeekResult.kt index a854dd25d3..1df62e94e8 100644 --- a/matrix-sdk-android/src/main/java/org/matrix/android/sdk/internal/session/space/peeking/SpacePeekResult.kt +++ b/matrix-sdk-android/src/main/java/org/matrix/android/sdk/internal/session/space/peeking/SpacePeekResult.kt @@ -18,6 +18,7 @@ package org.matrix.android.sdk.internal.session.space.peeking import org.matrix.android.sdk.api.session.room.peeking.PeekResult +// TODO Move to api package data class SpacePeekSummary( val idOrAlias: String, val roomPeekResult: PeekResult.Success, diff --git a/matrix-sdk-android/src/main/java/org/matrix/android/sdk/internal/session/sync/RoomSyncHandler.kt b/matrix-sdk-android/src/main/java/org/matrix/android/sdk/internal/session/sync/RoomSyncHandler.kt index 5a1de41b95..acba679ad3 100644 --- a/matrix-sdk-android/src/main/java/org/matrix/android/sdk/internal/session/sync/RoomSyncHandler.kt +++ b/matrix-sdk-android/src/main/java/org/matrix/android/sdk/internal/session/sync/RoomSyncHandler.kt @@ -215,7 +215,7 @@ internal class RoomSyncHandler @Inject constructor(private val readReceiptHandle val ageLocalTs = event.unsignedData?.age?.let { syncLocalTimestampMillis - it } val eventEntity = event.toEntity(roomId, SendState.SYNCED, ageLocalTs).copyToRealmOrIgnore(realm, insertType) CurrentStateEventEntity.getOrCreate(realm, roomId, event.stateKey, event.type).apply { - Timber.v("## Space state event: $eventEntity") + // Timber.v("## Space state event: $eventEntity") eventId = event.eventId root = eventEntity } diff --git a/matrix-sdk-android/src/main/java/org/matrix/android/sdk/internal/session/sync/model/RoomSyncAccountData.kt b/matrix-sdk-android/src/main/java/org/matrix/android/sdk/internal/session/sync/model/RoomSyncAccountData.kt index 9e0ccde16b..a2375507d8 100644 --- a/matrix-sdk-android/src/main/java/org/matrix/android/sdk/internal/session/sync/model/RoomSyncAccountData.kt +++ b/matrix-sdk-android/src/main/java/org/matrix/android/sdk/internal/session/sync/model/RoomSyncAccountData.kt @@ -25,5 +25,5 @@ internal data class RoomSyncAccountData( /** * List of account data events (array of Event). */ - @Json(name = "events") val events: List? = emptyList() + @Json(name = "events") val events: List? = null ) diff --git a/matrix-sdk-android/src/main/java/org/matrix/android/sdk/internal/session/sync/model/RoomSyncEphemeral.kt b/matrix-sdk-android/src/main/java/org/matrix/android/sdk/internal/session/sync/model/RoomSyncEphemeral.kt index a2e044d947..f2135db6b7 100644 --- a/matrix-sdk-android/src/main/java/org/matrix/android/sdk/internal/session/sync/model/RoomSyncEphemeral.kt +++ b/matrix-sdk-android/src/main/java/org/matrix/android/sdk/internal/session/sync/model/RoomSyncEphemeral.kt @@ -26,5 +26,5 @@ internal data class RoomSyncEphemeral( /** * List of ephemeral events (array of Event). */ - @Json(name = "events") val events: List? = emptyList() + @Json(name = "events") val events: List? = null ) diff --git a/matrix-sdk-android/src/main/java/org/matrix/android/sdk/internal/session/sync/model/RoomSyncState.kt b/matrix-sdk-android/src/main/java/org/matrix/android/sdk/internal/session/sync/model/RoomSyncState.kt index c825cbf31c..f86f05d000 100644 --- a/matrix-sdk-android/src/main/java/org/matrix/android/sdk/internal/session/sync/model/RoomSyncState.kt +++ b/matrix-sdk-android/src/main/java/org/matrix/android/sdk/internal/session/sync/model/RoomSyncState.kt @@ -27,5 +27,5 @@ internal data class RoomSyncState( /** * List of state events (array of Event). The resulting state corresponds to the *start* of the timeline. */ - @Json(name = "events") val events: List? = emptyList() + @Json(name = "events") val events: List? = null ) diff --git a/matrix-sdk-android/src/main/java/org/matrix/android/sdk/internal/session/sync/model/RoomSyncTimeline.kt b/matrix-sdk-android/src/main/java/org/matrix/android/sdk/internal/session/sync/model/RoomSyncTimeline.kt index ce51958f73..27bbc4343f 100644 --- a/matrix-sdk-android/src/main/java/org/matrix/android/sdk/internal/session/sync/model/RoomSyncTimeline.kt +++ b/matrix-sdk-android/src/main/java/org/matrix/android/sdk/internal/session/sync/model/RoomSyncTimeline.kt @@ -27,7 +27,7 @@ internal data class RoomSyncTimeline( /** * List of events (array of Event). */ - @Json(name = "events") val events: List? = emptyList(), + @Json(name = "events") val events: List? = null, /** * Boolean which tells whether there are more events on the server