From 7d3d080603eae13baf9f8160834ce28c8677a689 Mon Sep 17 00:00:00 2001 From: Valere Date: Tue, 27 Apr 2021 18:51:43 +0200 Subject: [PATCH] Code review --- .../org/matrix/android/sdk/rx/RxSession.kt | 7 --- .../sdk/session/space/SpaceCreationTest.kt | 10 ++-- .../room/model/RoomJoinRulesContent.kt | 2 +- .../sdk/api/session/room/model/RoomSummary.kt | 2 +- .../sdk/api/session/space/JoinSpaceResult.kt | 27 +++++++++ .../sdk/api/session/space/SpaceService.kt | 10 ---- .../matrix/android/sdk/api/util/MatrixItem.kt | 9 ++- .../SessionRealmConfigurationFactory.kt | 3 +- .../database/mapper/RoomSummaryMapper.kt | 2 +- .../query/QueryStringValueProcessor.kt | 14 ++--- .../room/create/CreateRoomBodyBuilder.kt | 3 +- .../summary/{GrapUtils.kt => GraphUtils.kt} | 0 .../room/summary/RoomSummaryDataSource.kt | 6 +- .../internal/session/space/CreateSpaceTask.kt | 56 ------------------- .../session/space/DefaultSpaceService.kt | 8 ++- .../internal/session/space/JoinSpaceTask.kt | 24 ++++---- .../sdk/internal/session/space/SpaceModule.kt | 3 - .../BottomSheetGenericRadioAction.kt | 10 ++-- .../home/UnreadMessagesSharedViewModel.kt | 25 ++++----- .../home/room/detail/RoomDetailFragment.kt | 3 + .../home/room/list/RoomListFragment.kt | 22 ++++---- .../home/room/list/RoomListViewModel.kt | 9 +++ .../home/room/list/RoomSummaryItemFactory.kt | 3 +- .../matrixto/MatrixToBottomSheetViewModel.kt | 4 +- .../settings/RoomSettingsAction.kt | 2 +- .../features/spaces/SpaceSummaryController.kt | 2 +- .../spaces/create/CreateSpaceState.kt | 2 +- .../create/SpaceDetailEpoxyController.kt | 2 +- .../spaces/explore/SpaceDirectoryViewModel.kt | 17 ++---- .../spaces/manage/SpaceAddRoomsViewModel.kt | 2 +- .../spaces/manage/SpaceManagedSharedAction.kt | 4 +- .../manage/SpaceManagedSharedViewEvents.kt | 4 +- .../spaces/preview/SpacePreviewViewModel.kt | 8 +-- .../ui/SharedPreferencesUiStateRepository.kt | 4 +- .../main/res/layout/fragment_home_detail.xml | 32 +++++------ .../res/layout/fragment_space_add_rooms.xml | 2 +- vector/src/main/res/layout/view_state.xml | 1 - 37 files changed, 149 insertions(+), 195 deletions(-) create mode 100644 matrix-sdk-android/src/main/java/org/matrix/android/sdk/api/session/space/JoinSpaceResult.kt rename matrix-sdk-android/src/main/java/org/matrix/android/sdk/internal/session/room/summary/{GrapUtils.kt => GraphUtils.kt} (100%) delete mode 100644 matrix-sdk-android/src/main/java/org/matrix/android/sdk/internal/session/space/CreateSpaceTask.kt 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 7f794be399..67a35cac2e 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 @@ -74,13 +74,6 @@ class RxSession(private val session: Session) { } } - fun liveFlattenRoomSummaryChildOf(spaceId: String?): Observable> { - return session.getFlattenRoomSummaryChildrenOfLive(spaceId).asObservable() - .startWithCallable { - session.getFlattenRoomSummaryChildrenOf(spaceId) - } - } - fun liveBreadcrumbs(queryParams: RoomSummaryQueryParams): Observable> { return session.getBreadcrumbsLive(queryParams).asObservable() .startWithCallable { diff --git a/matrix-sdk-android/src/androidTest/java/org/matrix/android/sdk/session/space/SpaceCreationTest.kt b/matrix-sdk-android/src/androidTest/java/org/matrix/android/sdk/session/space/SpaceCreationTest.kt index 6f7a2e1f17..278762671b 100644 --- a/matrix-sdk-android/src/androidTest/java/org/matrix/android/sdk/session/space/SpaceCreationTest.kt +++ b/matrix-sdk-android/src/androidTest/java/org/matrix/android/sdk/session/space/SpaceCreationTest.kt @@ -39,7 +39,7 @@ import org.matrix.android.sdk.api.session.room.model.create.CreateRoomParams import org.matrix.android.sdk.api.session.room.model.create.CreateRoomPreset import org.matrix.android.sdk.api.session.room.model.create.RoomCreateContent import org.matrix.android.sdk.api.session.room.roomSummaryQueryParams -import org.matrix.android.sdk.api.session.space.SpaceService +import org.matrix.android.sdk.api.session.space.JoinSpaceResult import org.matrix.android.sdk.common.CommonTestHelper import org.matrix.android.sdk.common.SessionTestParams import kotlin.test.assertEquals @@ -112,12 +112,12 @@ class SpaceCreationTest : InstrumentedTest { // Try to join from bob, it's a public space no need to invite - val joinResult: SpaceService.JoinSpaceResult + val joinResult: JoinSpaceResult runBlocking { joinResult = bobSession.spaceService().joinSpace(spaceId) } - assertEquals(SpaceService.JoinSpaceResult.Success, joinResult) + assertEquals(JoinSpaceResult.Success, joinResult) val spaceBobPov = bobSession.spaceService().getSpace(spaceId) assertEquals(roomName, spaceBobPov?.asRoom()?.roomSummary()?.name, "Room name should be set") @@ -169,7 +169,7 @@ class SpaceCreationTest : InstrumentedTest { bobSession.spaceService().joinSpace(spaceId) } - assertEquals(SpaceService.JoinSpaceResult.Success, joinResult) + assertEquals(JoinSpaceResult.Success, joinResult) val spaceBobPov = bobSession.spaceService().getSpace(spaceId) assertEquals(roomName, spaceBobPov?.asRoom()?.roomSummary()?.name, "Room name should be set") @@ -186,7 +186,7 @@ class SpaceCreationTest : InstrumentedTest { this.memberships = listOf(Membership.JOIN) }).firstOrNull() - assertEquals(2, spaceSummaryBobPov?.children?.size ?: -1, "Unexpected number of children") + assertEquals(2, spaceSummaryBobPov?.spaceChildren?.size ?: -1, "Unexpected number of children") commonTestHelper.signOutAndClose(aliceSession) commonTestHelper.signOutAndClose(bobSession) diff --git a/matrix-sdk-android/src/main/java/org/matrix/android/sdk/api/session/room/model/RoomJoinRulesContent.kt b/matrix-sdk-android/src/main/java/org/matrix/android/sdk/api/session/room/model/RoomJoinRulesContent.kt index 6892cac001..33f402cad3 100644 --- a/matrix-sdk-android/src/main/java/org/matrix/android/sdk/api/session/room/model/RoomJoinRulesContent.kt +++ b/matrix-sdk-android/src/main/java/org/matrix/android/sdk/api/session/room/model/RoomJoinRulesContent.kt @@ -31,7 +31,7 @@ data class RoomJoinRulesContent( /** * If the allow key is an empty list (or not a list at all), then the room reverts to standard public join rules */ - @Json(name = "allow") val allowList:List? = null + @Json(name = "allow") val allowList: List? = null ) { val joinRules: RoomJoinRules? = when (_joinRules) { "public" -> RoomJoinRules.PUBLIC diff --git a/matrix-sdk-android/src/main/java/org/matrix/android/sdk/api/session/room/model/RoomSummary.kt b/matrix-sdk-android/src/main/java/org/matrix/android/sdk/api/session/room/model/RoomSummary.kt index 2a802adcde..9a37975ffa 100644 --- a/matrix-sdk-android/src/main/java/org/matrix/android/sdk/api/session/room/model/RoomSummary.kt +++ b/matrix-sdk-android/src/main/java/org/matrix/android/sdk/api/session/room/model/RoomSummary.kt @@ -57,7 +57,7 @@ data class RoomSummary constructor( val hasFailedSending: Boolean = false, val roomType: String? = null, val spaceParents: List? = null, - val children: List? = null, + val spaceChildren: List? = null, val flattenParentIds: List = emptyList() ) { diff --git a/matrix-sdk-android/src/main/java/org/matrix/android/sdk/api/session/space/JoinSpaceResult.kt b/matrix-sdk-android/src/main/java/org/matrix/android/sdk/api/session/space/JoinSpaceResult.kt new file mode 100644 index 0000000000..e8c69977c6 --- /dev/null +++ b/matrix-sdk-android/src/main/java/org/matrix/android/sdk/api/session/space/JoinSpaceResult.kt @@ -0,0 +1,27 @@ +/* + * 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.api.session.space + +sealed class JoinSpaceResult { + object Success : JoinSpaceResult() + data class Fail(val error: Throwable) : JoinSpaceResult() + + /** Success fully joined the space, but failed to join all or some of it's rooms */ + data class PartialSuccess(val failedRooms: Map) : JoinSpaceResult() + + fun isSuccess() = this is Success || this is PartialSuccess +} 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 1f88403eab..fedf38fe06 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 @@ -67,16 +67,6 @@ interface SpaceService { fun getSpaceSummaries(spaceSummaryQueryParams: SpaceSummaryQueryParams): List - sealed class JoinSpaceResult { - object Success : JoinSpaceResult() - data class Fail(val error: Throwable) : JoinSpaceResult() - - /** Success fully joined the space, but failed to join all or some of it's rooms */ - data class PartialSuccess(val failedRooms: Map) : JoinSpaceResult() - - fun isSuccess() = this is Success || this is PartialSuccess - } - suspend fun joinSpace(spaceIdOrAlias: String, reason: String? = null, viaServers: List = emptyList()): JoinSpaceResult diff --git a/matrix-sdk-android/src/main/java/org/matrix/android/sdk/api/util/MatrixItem.kt b/matrix-sdk-android/src/main/java/org/matrix/android/sdk/api/util/MatrixItem.kt index a904b43faa..7b2fae86ef 100644 --- a/matrix-sdk-android/src/main/java/org/matrix/android/sdk/api/util/MatrixItem.kt +++ b/matrix-sdk-android/src/main/java/org/matrix/android/sdk/api/util/MatrixItem.kt @@ -20,6 +20,7 @@ import org.matrix.android.sdk.BuildConfig import org.matrix.android.sdk.api.session.group.model.GroupSummary import org.matrix.android.sdk.api.session.room.model.RoomMemberSummary import org.matrix.android.sdk.api.session.room.model.RoomSummary +import org.matrix.android.sdk.api.session.room.model.SpaceChildInfo import org.matrix.android.sdk.api.session.room.model.roomdirectory.PublicRoom import org.matrix.android.sdk.api.session.room.sender.SenderInfo import org.matrix.android.sdk.api.session.user.model.User @@ -86,9 +87,9 @@ sealed class MatrixItem( } protected fun checkId() { -// if (!id.startsWith(getIdPrefix())) { -// error("Wrong usage of MatrixItem: check the id $id should start with ${getIdPrefix()}") -// } + if (!id.startsWith(getIdPrefix())) { + error("Wrong usage of MatrixItem: check the id $id should start with ${getIdPrefix()}") + } } /** @@ -157,3 +158,5 @@ fun PublicRoom.toMatrixItem() = MatrixItem.RoomItem(roomId, name ?: getPrimaryAl fun RoomMemberSummary.toMatrixItem() = MatrixItem.UserItem(userId, displayName, avatarUrl) fun SenderInfo.toMatrixItem() = MatrixItem.UserItem(userId, disambiguatedDisplayName, avatarUrl) + +fun SpaceChildInfo.toMatrixItem() = MatrixItem.RoomItem(childRoomId, name, avatarUrl) diff --git a/matrix-sdk-android/src/main/java/org/matrix/android/sdk/internal/database/SessionRealmConfigurationFactory.kt b/matrix-sdk-android/src/main/java/org/matrix/android/sdk/internal/database/SessionRealmConfigurationFactory.kt index 4cce93f9f9..244fe3432a 100644 --- a/matrix-sdk-android/src/main/java/org/matrix/android/sdk/internal/database/SessionRealmConfigurationFactory.kt +++ b/matrix-sdk-android/src/main/java/org/matrix/android/sdk/internal/database/SessionRealmConfigurationFactory.kt @@ -72,8 +72,7 @@ internal class SessionRealmConfigurationFactory @Inject constructor( .allowWritesOnUiThread(true) .modules(SessionRealmModule()) .schemaVersion(RealmSessionStoreMigration.SESSION_STORE_SCHEMA_VERSION) - .deleteRealmIfMigrationNeeded() -// .migration(migration) + .migration(migration) .build() // Try creating a realm instance and if it succeeds we can clear the flag diff --git a/matrix-sdk-android/src/main/java/org/matrix/android/sdk/internal/database/mapper/RoomSummaryMapper.kt b/matrix-sdk-android/src/main/java/org/matrix/android/sdk/internal/database/mapper/RoomSummaryMapper.kt index 9109ef2e8f..ff2793b0ab 100644 --- a/matrix-sdk-android/src/main/java/org/matrix/android/sdk/internal/database/mapper/RoomSummaryMapper.kt +++ b/matrix-sdk-android/src/main/java/org/matrix/android/sdk/internal/database/mapper/RoomSummaryMapper.kt @@ -75,7 +75,7 @@ internal class RoomSummaryMapper @Inject constructor(private val timelineEventMa viaServers = relationInfoEntity.viaServers.toList() ) }, - children = roomSummaryEntity.children.map { + spaceChildren = roomSummaryEntity.children.map { SpaceChildInfo( childRoomId = it.childRoomId ?: "", isKnown = it.childSummaryEntity != null, diff --git a/matrix-sdk-android/src/main/java/org/matrix/android/sdk/internal/query/QueryStringValueProcessor.kt b/matrix-sdk-android/src/main/java/org/matrix/android/sdk/internal/query/QueryStringValueProcessor.kt index c49efaaeef..fd33682231 100644 --- a/matrix-sdk-android/src/main/java/org/matrix/android/sdk/internal/query/QueryStringValueProcessor.kt +++ b/matrix-sdk-android/src/main/java/org/matrix/android/sdk/internal/query/QueryStringValueProcessor.kt @@ -25,12 +25,12 @@ import timber.log.Timber fun RealmQuery.process(field: String, queryStringValue: QueryStringValue): RealmQuery { when (queryStringValue) { is QueryStringValue.NoCondition -> Timber.v("No condition to process") - is QueryStringValue.IsNotNull -> isNotNull(field) - is QueryStringValue.IsNull -> isNull(field) - is QueryStringValue.IsEmpty -> isEmpty(field) - is QueryStringValue.IsNotEmpty -> isNotEmpty(field) - is QueryStringValue.Equals -> equalTo(field, queryStringValue.string, queryStringValue.case.toRealmCase()) - is QueryStringValue.Contains -> contains(field, queryStringValue.string, queryStringValue.case.toRealmCase()) + is QueryStringValue.IsNotNull -> isNotNull(field) + is QueryStringValue.IsNull -> isNull(field) + is QueryStringValue.IsEmpty -> isEmpty(field) + is QueryStringValue.IsNotEmpty -> isNotEmpty(field) + is QueryStringValue.Equals -> equalTo(field, queryStringValue.string, queryStringValue.case.toRealmCase()) + is QueryStringValue.Contains -> contains(field, queryStringValue.string, queryStringValue.case.toRealmCase()) } return this } @@ -38,6 +38,6 @@ fun RealmQuery.process(field: String, queryStringValue: Que private fun QueryStringValue.Case.toRealmCase(): Case { return when (this) { QueryStringValue.Case.INSENSITIVE -> Case.INSENSITIVE - QueryStringValue.Case.SENSITIVE -> Case.SENSITIVE + QueryStringValue.Case.SENSITIVE -> Case.SENSITIVE } } diff --git a/matrix-sdk-android/src/main/java/org/matrix/android/sdk/internal/session/room/create/CreateRoomBodyBuilder.kt b/matrix-sdk-android/src/main/java/org/matrix/android/sdk/internal/session/room/create/CreateRoomBodyBuilder.kt index 49a3ffac5a..018b865388 100644 --- a/matrix-sdk-android/src/main/java/org/matrix/android/sdk/internal/session/room/create/CreateRoomBodyBuilder.kt +++ b/matrix-sdk-android/src/main/java/org/matrix/android/sdk/internal/session/room/create/CreateRoomBodyBuilder.kt @@ -24,7 +24,6 @@ import org.matrix.android.sdk.api.session.events.model.toContent import org.matrix.android.sdk.api.session.identity.IdentityServiceError import org.matrix.android.sdk.api.session.identity.toMedium import org.matrix.android.sdk.api.session.room.model.GuestAccess -import org.matrix.android.sdk.api.session.room.model.RoomGuestAccessContent import org.matrix.android.sdk.api.session.room.model.RoomHistoryVisibility import org.matrix.android.sdk.api.session.room.model.RoomJoinRules import org.matrix.android.sdk.api.session.room.model.RoomJoinRulesContent @@ -144,7 +143,7 @@ internal class CreateRoomBodyBuilder @Inject constructor( Event( type = EventType.STATE_ROOM_GUEST_ACCESS, stateKey = "", - content = RoomGuestAccessContent(it.value).toContent() + content = mapOf("guest_access" to it.value) ) } } diff --git a/matrix-sdk-android/src/main/java/org/matrix/android/sdk/internal/session/room/summary/GrapUtils.kt b/matrix-sdk-android/src/main/java/org/matrix/android/sdk/internal/session/room/summary/GraphUtils.kt similarity index 100% rename from matrix-sdk-android/src/main/java/org/matrix/android/sdk/internal/session/room/summary/GrapUtils.kt rename to matrix-sdk-android/src/main/java/org/matrix/android/sdk/internal/session/room/summary/GraphUtils.kt 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 8b1fd2f404..d2bb51cbef 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 @@ -349,7 +349,7 @@ internal class RoomSummaryDataSource @Inject constructor(@SessionDatabase privat // it may not have a parent relation but could be a child of some other.... for (spaceSummary in getSpaceSummaries(spaceSummaryQueryParams { memberships = Membership.activeMemberships() })) { - if (spaceSummary.children?.any { it.childRoomId == roomSummary.roomId } == true) { + if (spaceSummary.spaceChildren?.any { it.childRoomId == roomSummary.roomId } == true) { return false } } @@ -358,7 +358,7 @@ internal class RoomSummaryDataSource @Inject constructor(@SessionDatabase privat } fun flattenChild(current: RoomSummary, parenting: List, output: MutableList, memberShips: List) { - current.children?.sortedBy { it.order ?: it.name }?.forEach { childInfo -> + current.spaceChildren?.sortedBy { it.order ?: it.name }?.forEach { childInfo -> if (childInfo.roomType == RoomType.SPACE) { // Add recursive if (!parenting.contains(childInfo.childRoomId)) { // avoid cycles! @@ -388,7 +388,7 @@ internal class RoomSummaryDataSource @Inject constructor(@SessionDatabase privat if (includeCurrent) { output.add(current) } - current.children?.sortedBy { it.order ?: it.name }?.forEach { + current.spaceChildren?.sortedBy { it.order ?: it.name }?.forEach { if (it.roomType == RoomType.SPACE) { // Add recursive if (!parenting.contains(it.childRoomId)) { // avoid cycles! diff --git a/matrix-sdk-android/src/main/java/org/matrix/android/sdk/internal/session/space/CreateSpaceTask.kt b/matrix-sdk-android/src/main/java/org/matrix/android/sdk/internal/session/space/CreateSpaceTask.kt deleted file mode 100644 index 826fa76f77..0000000000 --- a/matrix-sdk-android/src/main/java/org/matrix/android/sdk/internal/session/space/CreateSpaceTask.kt +++ /dev/null @@ -1,56 +0,0 @@ -/* - * 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 io.realm.RealmConfiguration -import kotlinx.coroutines.TimeoutCancellationException -import org.matrix.android.sdk.api.session.room.failure.CreateRoomFailure -import org.matrix.android.sdk.api.session.room.model.create.CreateRoomParams -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.create.CreateRoomTask -import org.matrix.android.sdk.internal.task.Task -import java.util.concurrent.TimeUnit -import javax.inject.Inject - -/** - * A simple wrapper of create room task that adds waiting for DB entities of spaces - */ -internal interface CreateSpaceTask : Task - -internal class DefaultCreateSpaceTask @Inject constructor( - private val createRoomTask: CreateRoomTask, - @SessionDatabase private val realmConfiguration: RealmConfiguration -) : CreateSpaceTask { - - override suspend fun execute(params: CreateRoomParams): String { - val spaceId = createRoomTask.execute(params) - - try { - awaitNotEmptyResult(realmConfiguration, TimeUnit.MINUTES.toMillis(1L)) { realm -> - realm.where(RoomSummaryEntity::class.java) - .equalTo(RoomSummaryEntityFields.ROOM_ID, spaceId) - } - } catch (exception: TimeoutCancellationException) { - throw CreateRoomFailure.CreatedWithTimeout(spaceId) - } - - return spaceId - } -} 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 9ae8b25e5d..8fdc563edb 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 @@ -32,6 +32,7 @@ import org.matrix.android.sdk.api.session.room.model.SpaceChildInfo import org.matrix.android.sdk.api.session.room.model.create.CreateRoomPreset import org.matrix.android.sdk.api.session.room.powerlevels.PowerLevelsHelper import org.matrix.android.sdk.api.session.space.CreateSpaceParams +import org.matrix.android.sdk.api.session.space.JoinSpaceResult import org.matrix.android.sdk.api.session.space.Space import org.matrix.android.sdk.api.session.space.SpaceService import org.matrix.android.sdk.api.session.space.SpaceSummaryQueryParams @@ -40,6 +41,7 @@ import org.matrix.android.sdk.api.session.space.model.SpaceParentContent 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 +import org.matrix.android.sdk.internal.session.room.create.CreateRoomTask import org.matrix.android.sdk.internal.session.room.membership.leaving.LeaveRoomTask import org.matrix.android.sdk.internal.session.room.state.StateEventDataSource import org.matrix.android.sdk.internal.session.room.summary.RoomSummaryDataSource @@ -49,7 +51,7 @@ import javax.inject.Inject internal class DefaultSpaceService @Inject constructor( @UserId private val userId: String, - private val createSpaceTask: CreateSpaceTask, + private val createRoomTask: CreateRoomTask, private val joinSpaceTask: JoinSpaceTask, private val spaceGetter: SpaceGetter, private val roomGetter: RoomGetter, @@ -61,7 +63,7 @@ internal class DefaultSpaceService @Inject constructor( ) : SpaceService { override suspend fun createSpace(params: CreateSpaceParams): String { - return createSpaceTask.executeRetry(params, 3) + return createRoomTask.executeRetry(params, 3) } override suspend fun createSpace(name: String, topic: String?, avatarUri: Uri?, isPublic: Boolean): String { @@ -149,7 +151,7 @@ internal class DefaultSpaceService @Inject constructor( override suspend fun joinSpace(spaceIdOrAlias: String, reason: String?, - viaServers: List): SpaceService.JoinSpaceResult { + viaServers: List): JoinSpaceResult { return joinSpaceTask.execute(JoinSpaceTask.Params(spaceIdOrAlias, reason, viaServers)) } 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 7e9f2235b9..5e1b829249 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 @@ -20,7 +20,7 @@ import io.realm.RealmConfiguration import kotlinx.coroutines.TimeoutCancellationException import org.matrix.android.sdk.api.session.room.model.Membership import org.matrix.android.sdk.api.session.room.model.RoomType -import org.matrix.android.sdk.api.session.space.SpaceService +import org.matrix.android.sdk.api.session.space.JoinSpaceResult 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 @@ -32,7 +32,7 @@ import timber.log.Timber import java.util.concurrent.TimeUnit import javax.inject.Inject -internal interface JoinSpaceTask : Task { +internal interface JoinSpaceTask : Task { data class Params( val roomIdOrAlias: String, val reason: String?, @@ -47,7 +47,7 @@ internal class DefaultJoinSpaceTask @Inject constructor( private val roomSummaryDataSource: RoomSummaryDataSource ) : JoinSpaceTask { - override suspend fun execute(params: JoinSpaceTask.Params): SpaceService.JoinSpaceResult { + override suspend fun execute(params: JoinSpaceTask.Params): JoinSpaceResult { Timber.v("## Space: > Joining root space ${params.roomIdOrAlias} ...") try { joinRoomTask.execute(JoinRoomTask.Params( @@ -56,7 +56,7 @@ internal class DefaultJoinSpaceTask @Inject constructor( params.viaServers )) } catch (failure: Throwable) { - return SpaceService.JoinSpaceResult.Fail(failure) + return JoinSpaceResult.Fail(failure) } Timber.v("## Space: < Joining root space done for ${params.roomIdOrAlias}") // we want to wait for sync result to check for auto join rooms @@ -76,15 +76,15 @@ internal class DefaultJoinSpaceTask @Inject constructor( } } catch (exception: TimeoutCancellationException) { Timber.w("## Space: > Error created with timeout") - return SpaceService.JoinSpaceResult.PartialSuccess(emptyMap()) + return JoinSpaceResult.PartialSuccess(emptyMap()) } 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) - Timber.v("## Space: Found space summary Name:[${summary?.name}] children: ${summary?.children?.size}") - summary?.children?.forEach { + Timber.v("## Space: Found space summary Name:[${summary?.name}] children: ${summary?.spaceChildren?.size}") + summary?.spaceChildren?.forEach { // val childRoomSummary = it.roomSummary ?: return@forEach Timber.v("## Space: Processing child :[${it.childRoomId}] autoJoin:${it.autoJoin}") if (it.autoJoin) { @@ -92,13 +92,13 @@ internal class DefaultJoinSpaceTask @Inject constructor( if (it.roomType == RoomType.SPACE) { // recursively join auto-joined child of this space? when (val subspaceJoinResult = execute(JoinSpaceTask.Params(it.childRoomId, null, it.viaServers))) { - SpaceService.JoinSpaceResult.Success -> { + JoinSpaceResult.Success -> { // nop } - is SpaceService.JoinSpaceResult.Fail -> { + is JoinSpaceResult.Fail -> { errors[it.childRoomId] = subspaceJoinResult.error } - is SpaceService.JoinSpaceResult.PartialSuccess -> { + is JoinSpaceResult.PartialSuccess -> { errors.putAll(subspaceJoinResult.failedRooms) } } @@ -119,9 +119,9 @@ internal class DefaultJoinSpaceTask @Inject constructor( } return if (errors.isEmpty()) { - SpaceService.JoinSpaceResult.Success + JoinSpaceResult.Success } else { - SpaceService.JoinSpaceResult.PartialSuccess(errors) + JoinSpaceResult.PartialSuccess(errors) } } } 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 34bc66baa0..87425f4af2 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 @@ -48,9 +48,6 @@ internal abstract class SpaceModule { @Binds abstract fun bindJoinSpaceTask(task: DefaultJoinSpaceTask): JoinSpaceTask - @Binds - abstract fun bindCreateSpaceTask(task: DefaultCreateSpaceTask): CreateSpaceTask - @Binds abstract fun bindSpaceGetter(getter: DefaultSpaceGetter): SpaceGetter } diff --git a/vector/src/main/java/im/vector/app/core/ui/bottomsheet/BottomSheetGenericRadioAction.kt b/vector/src/main/java/im/vector/app/core/ui/bottomsheet/BottomSheetGenericRadioAction.kt index 168e5edc44..516612717a 100644 --- a/vector/src/main/java/im/vector/app/core/ui/bottomsheet/BottomSheetGenericRadioAction.kt +++ b/vector/src/main/java/im/vector/app/core/ui/bottomsheet/BottomSheetGenericRadioAction.kt @@ -29,11 +29,11 @@ open class BottomSheetGenericRadioAction( ) : VectorSharedAction { fun toRadioBottomSheetItem(): BottomSheetRadioActionItem_ { - return BottomSheetRadioActionItem_().apply { - id("action_${this@BottomSheetGenericRadioAction.title}") - title(this@BottomSheetGenericRadioAction.title) - selected(this@BottomSheetGenericRadioAction.isSelected) - description(this@BottomSheetGenericRadioAction.description) + return BottomSheetRadioActionItem_().also { + it.id("action_$title") + it.title(title) + it.selected(isSelected) + it.description(description) } } } diff --git a/vector/src/main/java/im/vector/app/features/home/UnreadMessagesSharedViewModel.kt b/vector/src/main/java/im/vector/app/features/home/UnreadMessagesSharedViewModel.kt index cfafd1f103..77ffe903fc 100644 --- a/vector/src/main/java/im/vector/app/features/home/UnreadMessagesSharedViewModel.kt +++ b/vector/src/main/java/im/vector/app/features/home/UnreadMessagesSharedViewModel.kt @@ -30,7 +30,6 @@ import im.vector.app.core.platform.EmptyAction import im.vector.app.core.platform.EmptyViewEvents import im.vector.app.core.platform.VectorViewModel import io.reactivex.Observable -import io.reactivex.functions.BiFunction import io.reactivex.schedulers.Schedulers import org.matrix.android.sdk.api.query.ActiveSpaceFilter import org.matrix.android.sdk.api.session.Session @@ -66,8 +65,8 @@ class UnreadMessagesSharedViewModel @AssistedInject constructor(@Assisted initia @JvmStatic override fun create(viewModelContext: ViewModelContext, state: UnreadMessagesState): UnreadMessagesSharedViewModel? { val factory = when (viewModelContext) { - is FragmentViewModelContext -> viewModelContext.fragment as? UnreadMessagesSharedViewModel.Factory - is ActivityViewModelContext -> viewModelContext.activity as? UnreadMessagesSharedViewModel.Factory + is FragmentViewModelContext -> viewModelContext.fragment as? Factory + is ActivityViewModelContext -> viewModelContext.activity as? Factory } return factory?.create(state) ?: error("You should let your activity/fragment implements Factory interface") } @@ -84,7 +83,7 @@ class UnreadMessagesSharedViewModel @AssistedInject constructor(@Assisted initia }, sortOrder = RoomSortOrder.NONE ).asObservable() .throttleFirst(300, TimeUnit.MILLISECONDS) - .subscribe { + .execute { val counts = session.getNotificationCountForRooms( roomSummaryQueryParams { this.memberships = listOf(Membership.JOIN) @@ -97,15 +96,13 @@ class UnreadMessagesSharedViewModel @AssistedInject constructor(@Assisted initia this.activeSpaceId = ActiveSpaceFilter.ActiveSpace(null) } ).size - setState { - copy( - homeSpaceUnread = RoomAggregateNotificationCount( - counts.notificationCount + invites, - highlightCount = counts.highlightCount + invites - ) - ) - } - }.disposeOnClear() + copy( + homeSpaceUnread = RoomAggregateNotificationCount( + counts.notificationCount + invites, + highlightCount = counts.highlightCount + invites + ) + ) + } Observable.combineLatest( appStateHandler.selectedRoomGroupingObservable.distinctUntilChanged(), @@ -118,7 +115,7 @@ class UnreadMessagesSharedViewModel @AssistedInject constructor(@Assisted initia .throttleFirst(300, TimeUnit.MILLISECONDS) .observeOn(Schedulers.computation()) }, - BiFunction { groupingMethod, _ -> + { groupingMethod, _ -> when (groupingMethod.orNull()) { is RoomGroupingMethod.ByLegacyGroup -> { // currently not supported diff --git a/vector/src/main/java/im/vector/app/features/home/room/detail/RoomDetailFragment.kt b/vector/src/main/java/im/vector/app/features/home/room/detail/RoomDetailFragment.kt index 1cac86fef5..ff288e2729 100644 --- a/vector/src/main/java/im/vector/app/features/home/room/detail/RoomDetailFragment.kt +++ b/vector/src/main/java/im/vector/app/features/home/room/detail/RoomDetailFragment.kt @@ -644,6 +644,9 @@ class RoomDetailFragment @Inject constructor( private fun handleSpaceShare() { roomDetailArgs.openShareSpaceForId?.let { spaceId -> ShareSpaceBottomSheet.show(childFragmentManager, spaceId) + view?.post { + handleChatEffect(ChatEffect.CONFETTI) + } } } diff --git a/vector/src/main/java/im/vector/app/features/home/room/list/RoomListFragment.kt b/vector/src/main/java/im/vector/app/features/home/room/list/RoomListFragment.kt index eeacdad363..76d7752ea7 100644 --- a/vector/src/main/java/im/vector/app/features/home/room/list/RoomListFragment.kt +++ b/vector/src/main/java/im/vector/app/features/home/room/list/RoomListFragment.kt @@ -92,8 +92,8 @@ class RoomListFragment @Inject constructor( data class SectionAdapterInfo( var section: SectionKey, - val headerHeaderAdapter: SectionHeaderAdapter, - val contentAdapter: EpoxyController + val sectionHeaderAdapter: SectionHeaderAdapter, + val contentEpoxyController: EpoxyController ) private val adapterInfosList = mutableListOf() @@ -126,7 +126,7 @@ class RoomListFragment @Inject constructor( // it's for invites local echo adapterInfosList.filter { it.section.notifyOfLocalEcho } .onEach { - (it.contentAdapter as? RoomSummaryPagedController)?.roomChangeMembershipStates = ms + (it.contentEpoxyController as? RoomSummaryPagedController)?.roomChangeMembershipStates = ms } } } @@ -137,16 +137,16 @@ class RoomListFragment @Inject constructor( val isRoomSectionExpanded = roomsSection.isExpanded.value.orTrue() if (actualBlock.section.isExpanded && !isRoomSectionExpanded) { // mark controller as collapsed - actualBlock.contentAdapter.setCollapsed(true) + actualBlock.contentEpoxyController.setCollapsed(true) } else if (!actualBlock.section.isExpanded && isRoomSectionExpanded) { // we must expand! - actualBlock.contentAdapter.setCollapsed(false) + actualBlock.contentEpoxyController.setCollapsed(false) } actualBlock.section = actualBlock.section.copy( isExpanded = isRoomSectionExpanded ) - actualBlock.headerHeaderAdapter.updateSection( - actualBlock.headerHeaderAdapter.roomsSectionData.copy(isExpanded = isRoomSectionExpanded) + actualBlock.sectionHeaderAdapter.updateSection( + actualBlock.sectionHeaderAdapter.roomsSectionData.copy(isExpanded = isRoomSectionExpanded) ) } } @@ -156,7 +156,7 @@ class RoomListFragment @Inject constructor( } override fun onDestroyView() { - adapterInfosList.onEach { it.contentAdapter.removeModelBuildListener(modelBuildListener) } + adapterInfosList.onEach { it.contentEpoxyController.removeModelBuildListener(modelBuildListener) } adapterInfosList.clear() modelBuildListener = null views.roomListView.cleanup() @@ -401,8 +401,8 @@ class RoomListFragment @Inject constructor( } private fun checkEmptyState() { - val shouldShowEmpty = adapterInfosList.all { it.headerHeaderAdapter.roomsSectionData.isHidden } - && !adapterInfosList.any { it.headerHeaderAdapter.roomsSectionData.isLoading } + val shouldShowEmpty = adapterInfosList.all { it.sectionHeaderAdapter.roomsSectionData.isHidden } + && !adapterInfosList.any { it.sectionHeaderAdapter.roomsSectionData.isLoading } if (shouldShowEmpty) { val emptyState = when (roomListParams.displayMode) { RoomListDisplayMode.NOTIFICATIONS -> { @@ -432,7 +432,7 @@ class RoomListFragment @Inject constructor( views.stateView.state = emptyState } else { // is there something to show already? - if (adapterInfosList.any { !it.headerHeaderAdapter.roomsSectionData.isHidden }) { + if (adapterInfosList.any { !it.sectionHeaderAdapter.roomsSectionData.isHidden }) { views.stateView.state = StateView.State.Content } else { views.stateView.state = StateView.State.Loading diff --git a/vector/src/main/java/im/vector/app/features/home/room/list/RoomListViewModel.kt b/vector/src/main/java/im/vector/app/features/home/room/list/RoomListViewModel.kt index 1044d598c8..bc24705e13 100644 --- a/vector/src/main/java/im/vector/app/features/home/room/list/RoomListViewModel.kt +++ b/vector/src/main/java/im/vector/app/features/home/room/list/RoomListViewModel.kt @@ -65,8 +65,17 @@ class RoomListViewModel @Inject constructor( } enum class SpaceFilterStrategy { + /** + * Filter the rooms if they are part of the current space (children and grand children). + * If current space is null, will return orphan rooms only + */ NORMAL, + /** + * Special case when we don't want to discriminate rooms when current space is null. + * In this case return all. + */ NOT_IF_ALL, + /** Do not filter based on space*/ NONE } diff --git a/vector/src/main/java/im/vector/app/features/home/room/list/RoomSummaryItemFactory.kt b/vector/src/main/java/im/vector/app/features/home/room/list/RoomSummaryItemFactory.kt index 2f073a68c6..283ed0ac85 100644 --- a/vector/src/main/java/im/vector/app/features/home/room/list/RoomSummaryItemFactory.kt +++ b/vector/src/main/java/im/vector/app/features/home/room/list/RoomSummaryItemFactory.kt @@ -32,7 +32,6 @@ import org.matrix.android.sdk.api.session.room.members.ChangeMembershipState import org.matrix.android.sdk.api.session.room.model.Membership import org.matrix.android.sdk.api.session.room.model.RoomSummary import org.matrix.android.sdk.api.session.room.model.SpaceChildInfo -import org.matrix.android.sdk.api.util.MatrixItem import org.matrix.android.sdk.api.util.toMatrixItem import javax.inject.Inject @@ -60,7 +59,7 @@ class RoomSummaryItemFactory @Inject constructor(private val displayableEventFor onJoinClick: View.OnClickListener): VectorEpoxyModel<*> { return SpaceChildInfoItem_() .id("sug_${spaceChildInfo.childRoomId}") - .matrixItem(MatrixItem.RoomItem(spaceChildInfo.childRoomId, spaceChildInfo.name, spaceChildInfo.avatarUrl)) + .matrixItem(spaceChildInfo.toMatrixItem()) .avatarRenderer(avatarRenderer) .topic(spaceChildInfo.topic) .buttonLabel(stringProvider.getString(R.string.join)) diff --git a/vector/src/main/java/im/vector/app/features/matrixto/MatrixToBottomSheetViewModel.kt b/vector/src/main/java/im/vector/app/features/matrixto/MatrixToBottomSheetViewModel.kt index b641779ed5..0d633ac422 100644 --- a/vector/src/main/java/im/vector/app/features/matrixto/MatrixToBottomSheetViewModel.kt +++ b/vector/src/main/java/im/vector/app/features/matrixto/MatrixToBottomSheetViewModel.kt @@ -40,7 +40,7 @@ import org.matrix.android.sdk.api.session.Session import org.matrix.android.sdk.api.session.permalinks.PermalinkData import org.matrix.android.sdk.api.session.room.model.Membership import org.matrix.android.sdk.api.session.room.peeking.PeekResult -import org.matrix.android.sdk.api.session.space.SpaceService +import org.matrix.android.sdk.api.session.space.JoinSpaceResult import org.matrix.android.sdk.api.session.user.model.User import org.matrix.android.sdk.api.util.MatrixItem import org.matrix.android.sdk.api.util.toMatrixItem @@ -281,7 +281,7 @@ class MatrixToBottomSheetViewModel @AssistedInject constructor( if (joinResult.isSuccess()) { _viewEvents.post(MatrixToViewEvents.NavigateToSpace(joinSpace.spaceID)) } else { - val errMsg = errorFormatter.toHumanReadable((joinResult as? SpaceService.JoinSpaceResult.Fail)?.error) + val errMsg = errorFormatter.toHumanReadable((joinResult as? JoinSpaceResult.Fail)?.error) _viewEvents.post(MatrixToViewEvents.ShowModalError(errMsg)) } } catch (failure: Throwable) { diff --git a/vector/src/main/java/im/vector/app/features/roomprofile/settings/RoomSettingsAction.kt b/vector/src/main/java/im/vector/app/features/roomprofile/settings/RoomSettingsAction.kt index 567caa5f97..eb601605e0 100644 --- a/vector/src/main/java/im/vector/app/features/roomprofile/settings/RoomSettingsAction.kt +++ b/vector/src/main/java/im/vector/app/features/roomprofile/settings/RoomSettingsAction.kt @@ -26,7 +26,7 @@ sealed class RoomSettingsAction : VectorViewModelAction { data class SetRoomName(val newName: String) : RoomSettingsAction() data class SetRoomTopic(val newTopic: String) : RoomSettingsAction() data class SetRoomHistoryVisibility(val visibility: RoomHistoryVisibility) : RoomSettingsAction() - data class SetRoomJoinRule(val roomJoinRule: RoomJoinRules?) : RoomSettingsAction() + data class SetRoomJoinRule(val roomJoinRule: RoomJoinRules) : RoomSettingsAction() data class SetRoomGuestAccess(val guestAccess: GuestAccess) : RoomSettingsAction() object Save : RoomSettingsAction() diff --git a/vector/src/main/java/im/vector/app/features/spaces/SpaceSummaryController.kt b/vector/src/main/java/im/vector/app/features/spaces/SpaceSummaryController.kt index c3e730f29e..a26f28a1c4 100644 --- a/vector/src/main/java/im/vector/app/features/spaces/SpaceSummaryController.kt +++ b/vector/src/main/java/im/vector/app/features/spaces/SpaceSummaryController.kt @@ -148,7 +148,7 @@ class SpaceSummaryController @Inject constructor( ?.forEach { groupSummary -> val isSelected = selected is RoomGroupingMethod.BySpace && groupSummary.roomId == selected.space()?.roomId // does it have children? - val subSpaces = groupSummary.children?.filter { childInfo -> + val subSpaces = groupSummary.spaceChildren?.filter { childInfo -> summaries.indexOfFirst { it.roomId == childInfo.childRoomId } != -1 } val hasChildren = (subSpaces?.size ?: 0) > 0 diff --git a/vector/src/main/java/im/vector/app/features/spaces/create/CreateSpaceState.kt b/vector/src/main/java/im/vector/app/features/spaces/create/CreateSpaceState.kt index 7bad36ced2..147fd3a616 100644 --- a/vector/src/main/java/im/vector/app/features/spaces/create/CreateSpaceState.kt +++ b/vector/src/main/java/im/vector/app/features/spaces/create/CreateSpaceState.kt @@ -29,7 +29,7 @@ data class CreateSpaceState( val spaceType: SpaceType? = null, val spaceTopology: SpaceTopology? = null, val nameInlineError: String? = null, - val defaultRooms: Map? = null, + val defaultRooms: Map? = null, val creationResult: Async = Uninitialized ) : MvRxState { diff --git a/vector/src/main/java/im/vector/app/features/spaces/create/SpaceDetailEpoxyController.kt b/vector/src/main/java/im/vector/app/features/spaces/create/SpaceDetailEpoxyController.kt index 96e5ec24c4..d46ae36275 100644 --- a/vector/src/main/java/im/vector/app/features/spaces/create/SpaceDetailEpoxyController.kt +++ b/vector/src/main/java/im/vector/app/features/spaces/create/SpaceDetailEpoxyController.kt @@ -53,7 +53,7 @@ class SpaceDetailEpoxyController @Inject constructor( enabled(true) imageUri(data?.avatarUri) avatarRenderer(avatarRenderer) - matrixItem(data?.name?.let { MatrixItem.RoomItem("", it, null).takeIf { !it.displayName.isNullOrBlank() } }) + matrixItem(data?.name?.let { MatrixItem.RoomItem("!", it, null).takeIf { !it.displayName.isNullOrBlank() } }) clickListener { listener?.onAvatarChange() } deleteListener { listener?.onAvatarDelete() } } diff --git a/vector/src/main/java/im/vector/app/features/spaces/explore/SpaceDirectoryViewModel.kt b/vector/src/main/java/im/vector/app/features/spaces/explore/SpaceDirectoryViewModel.kt index 76d62b58b6..fbe405e641 100644 --- a/vector/src/main/java/im/vector/app/features/spaces/explore/SpaceDirectoryViewModel.kt +++ b/vector/src/main/java/im/vector/app/features/spaces/explore/SpaceDirectoryViewModel.kt @@ -63,7 +63,7 @@ class SpaceDirectoryViewModel @AssistedInject constructor( val spaceSum = session.getRoomSummary(initialState.spaceId) setState { copy( - childList = spaceSum?.children ?: emptyList(), + childList = spaceSum?.spaceChildren ?: emptyList(), spaceSummaryApiResult = Loading() ) } @@ -95,17 +95,12 @@ class SpaceDirectoryViewModel @AssistedInject constructor( session .rx() .liveRoomSummaries(queryParams) - .subscribe { list -> - val joinedRoomIds = list - ?.map { it.roomId } - ?.toSet() - ?: emptySet() - - setState { - copy(joinedRoomsIds = joinedRoomIds) - } + .map { + it.map { it.roomId }.toSet() + } + .execute { + copy(joinedRoomsIds = it.invoke() ?: emptySet()) } - .disposeOnClear() } private fun observeMembershipChanges() { diff --git a/vector/src/main/java/im/vector/app/features/spaces/manage/SpaceAddRoomsViewModel.kt b/vector/src/main/java/im/vector/app/features/spaces/manage/SpaceAddRoomsViewModel.kt index 692f4343ba..e12aa14e83 100644 --- a/vector/src/main/java/im/vector/app/features/spaces/manage/SpaceAddRoomsViewModel.kt +++ b/vector/src/main/java/im/vector/app/features/spaces/manage/SpaceAddRoomsViewModel.kt @@ -44,7 +44,7 @@ import org.matrix.android.sdk.api.session.room.roomSummaryQueryParams class AddRoomError(val errorList: Map) : Throwable() { override fun getLocalizedMessage(): String? { - return errorList.map { it.value.localizedMessage }.joinToString(",") + return errorList.map { it.value.localizedMessage }.joinToString() } } diff --git a/vector/src/main/java/im/vector/app/features/spaces/manage/SpaceManagedSharedAction.kt b/vector/src/main/java/im/vector/app/features/spaces/manage/SpaceManagedSharedAction.kt index f3d7104d71..59e2742379 100644 --- a/vector/src/main/java/im/vector/app/features/spaces/manage/SpaceManagedSharedAction.kt +++ b/vector/src/main/java/im/vector/app/features/spaces/manage/SpaceManagedSharedAction.kt @@ -20,6 +20,6 @@ import im.vector.app.core.platform.VectorViewModelAction sealed class SpaceManagedSharedAction : VectorViewModelAction { object HandleBack : SpaceManagedSharedAction() - object ShowLoading: SpaceManagedSharedAction() - object HideLoading: SpaceManagedSharedAction() + object ShowLoading : SpaceManagedSharedAction() + object HideLoading : SpaceManagedSharedAction() } diff --git a/vector/src/main/java/im/vector/app/features/spaces/manage/SpaceManagedSharedViewEvents.kt b/vector/src/main/java/im/vector/app/features/spaces/manage/SpaceManagedSharedViewEvents.kt index b1a35c3700..067592b6ce 100644 --- a/vector/src/main/java/im/vector/app/features/spaces/manage/SpaceManagedSharedViewEvents.kt +++ b/vector/src/main/java/im/vector/app/features/spaces/manage/SpaceManagedSharedViewEvents.kt @@ -20,6 +20,6 @@ import im.vector.app.core.platform.VectorViewEvents sealed class SpaceManagedSharedViewEvents : VectorViewEvents { object Finish : SpaceManagedSharedViewEvents() - object ShowLoading: SpaceManagedSharedViewEvents() - object HideLoading: SpaceManagedSharedViewEvents() + object ShowLoading : SpaceManagedSharedViewEvents() + object HideLoading : SpaceManagedSharedViewEvents() } diff --git a/vector/src/main/java/im/vector/app/features/spaces/preview/SpacePreviewViewModel.kt b/vector/src/main/java/im/vector/app/features/spaces/preview/SpacePreviewViewModel.kt index 66a702f685..7da6c8a053 100644 --- a/vector/src/main/java/im/vector/app/features/spaces/preview/SpacePreviewViewModel.kt +++ b/vector/src/main/java/im/vector/app/features/spaces/preview/SpacePreviewViewModel.kt @@ -34,7 +34,7 @@ import kotlinx.coroutines.launch import org.matrix.android.sdk.api.session.Session import org.matrix.android.sdk.api.session.room.model.RoomType import org.matrix.android.sdk.api.session.room.peeking.PeekResult -import org.matrix.android.sdk.api.session.space.SpaceService +import org.matrix.android.sdk.api.session.space.JoinSpaceResult import org.matrix.android.sdk.internal.session.space.peeking.SpacePeekResult import org.matrix.android.sdk.internal.session.space.peeking.SpaceSubChildPeekResult import timber.log.Timber @@ -102,12 +102,12 @@ class SpacePreviewViewModel @AssistedInject constructor( viewModelScope.launch(Dispatchers.IO) { val joinResult = session.spaceService().joinSpace(initialState.idOrAlias, null, spaceVia) when (joinResult) { - SpaceService.JoinSpaceResult.Success, - is SpaceService.JoinSpaceResult.PartialSuccess -> { + JoinSpaceResult.Success, + is JoinSpaceResult.PartialSuccess -> { // For now we don't handle partial success, it's just success _viewEvents.post(SpacePreviewViewEvents.JoinSuccess) } - is SpaceService.JoinSpaceResult.Fail -> { + is JoinSpaceResult.Fail -> { _viewEvents.post(SpacePreviewViewEvents.JoinFailure(joinResult.error.toString())) } } diff --git a/vector/src/main/java/im/vector/app/features/ui/SharedPreferencesUiStateRepository.kt b/vector/src/main/java/im/vector/app/features/ui/SharedPreferencesUiStateRepository.kt index 6c6f0908c3..9848cb5bf1 100644 --- a/vector/src/main/java/im/vector/app/features/ui/SharedPreferencesUiStateRepository.kt +++ b/vector/src/main/java/im/vector/app/features/ui/SharedPreferencesUiStateRepository.kt @@ -60,13 +60,13 @@ class SharedPreferencesUiStateRepository @Inject constructor( } override fun storeSelectedSpace(spaceId: String?, sessionId: String) { - sharedPreferences.edit(true) { + sharedPreferences.edit { putString("$KEY_SELECTED_SPACE@$sessionId", spaceId) } } override fun storeSelectedGroup(groupId: String?, sessionId: String) { - sharedPreferences.edit(true) { + sharedPreferences.edit { putString("$KEY_SELECTED_GROUP@$sessionId", groupId) } } diff --git a/vector/src/main/res/layout/fragment_home_detail.xml b/vector/src/main/res/layout/fragment_home_detail.xml index e6ecdd9aa8..fcfe8374d7 100644 --- a/vector/src/main/res/layout/fragment_home_detail.xml +++ b/vector/src/main/res/layout/fragment_home_detail.xml @@ -18,36 +18,36 @@ + android:orientation="horizontal"> + app:layout_constraintTop_toTopOf="parent"> + android:importantForAccessibility="no" + android:src="@drawable/ic_space_icons" + app:tint="?riotx_text_secondary" /> - @@ -90,14 +88,14 @@ android:id="@+id/groupToolbarSpaceTitleView" android:layout_width="wrap_content" android:layout_height="wrap_content" - tools:visibility="visible" - android:visibility="gone" android:ellipsize="end" android:gravity="start" android:maxLines="1" android:textColor="?riotx_text_primary" android:textSize="14sp" - tools:text="@tools:sample/lorem/random" /> + android:visibility="gone" + tools:text="@tools:sample/lorem/random" + tools:visibility="visible" /> diff --git a/vector/src/main/res/layout/fragment_space_add_rooms.xml b/vector/src/main/res/layout/fragment_space_add_rooms.xml index ab2351f814..23b2807151 100644 --- a/vector/src/main/res/layout/fragment_space_add_rooms.xml +++ b/vector/src/main/res/layout/fragment_space_add_rooms.xml @@ -74,9 +74,9 @@ android:id="@+id/publicRoomsFilter" style="@style/VectorSearchView" android:layout_width="match_parent" + android:layout_height="wrap_content" android:layout_marginTop="8dp" android:layout_marginBottom="8dp" - android:layout_height="wrap_content" app:layout_constraintBottom_toBottomOf="parent" app:layout_constraintStart_toStartOf="parent" app:layout_constraintTop_toBottomOf="@+id/addRoomToSpaceToolbar" diff --git a/vector/src/main/res/layout/view_state.xml b/vector/src/main/res/layout/view_state.xml index 51a7afe652..731f3bd5c8 100644 --- a/vector/src/main/res/layout/view_state.xml +++ b/vector/src/main/res/layout/view_state.xml @@ -9,7 +9,6 @@