Code review

This commit is contained in:
Valere 2021-04-27 18:51:43 +02:00
parent 872c45d5a3
commit 7d3d080603
37 changed files with 149 additions and 195 deletions

View file

@ -74,13 +74,6 @@ class RxSession(private val session: Session) {
}
}
fun liveFlattenRoomSummaryChildOf(spaceId: String?): Observable<List<RoomSummary>> {
return session.getFlattenRoomSummaryChildrenOfLive(spaceId).asObservable()
.startWithCallable {
session.getFlattenRoomSummaryChildrenOf(spaceId)
}
}
fun liveBreadcrumbs(queryParams: RoomSummaryQueryParams): Observable<List<RoomSummary>> {
return session.getBreadcrumbsLive(queryParams).asObservable()
.startWithCallable {

View file

@ -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)

View file

@ -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<RoomJoinRulesAllowEntry>? = null
@Json(name = "allow") val allowList: List<RoomJoinRulesAllowEntry>? = null
) {
val joinRules: RoomJoinRules? = when (_joinRules) {
"public" -> RoomJoinRules.PUBLIC

View file

@ -57,7 +57,7 @@ data class RoomSummary constructor(
val hasFailedSending: Boolean = false,
val roomType: String? = null,
val spaceParents: List<SpaceParentInfo>? = null,
val children: List<SpaceChildInfo>? = null,
val spaceChildren: List<SpaceChildInfo>? = null,
val flattenParentIds: List<String> = emptyList()
) {

View file

@ -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<String, Throwable>) : JoinSpaceResult()
fun isSuccess() = this is Success || this is PartialSuccess
}

View file

@ -67,16 +67,6 @@ interface SpaceService {
fun getSpaceSummaries(spaceSummaryQueryParams: SpaceSummaryQueryParams): List<RoomSummary>
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<String, Throwable>) : JoinSpaceResult()
fun isSuccess() = this is Success || this is PartialSuccess
}
suspend fun joinSpace(spaceIdOrAlias: String,
reason: String? = null,
viaServers: List<String> = emptyList()): JoinSpaceResult

View file

@ -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)

View file

@ -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

View file

@ -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,

View file

@ -25,12 +25,12 @@ import timber.log.Timber
fun <T : RealmObject> RealmQuery<T>.process(field: String, queryStringValue: QueryStringValue): RealmQuery<T> {
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 <T : RealmObject> RealmQuery<T>.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
}
}

View file

@ -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)
)
}
}

View file

@ -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<String>, output: MutableList<RoomSummary>, memberShips: List<Membership>) {
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!

View file

@ -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<CreateRoomParams, String>
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
}
}

View file

@ -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<String>): SpaceService.JoinSpaceResult {
viaServers: List<String>): JoinSpaceResult {
return joinSpaceTask.execute(JoinSpaceTask.Params(spaceIdOrAlias, reason, viaServers))
}

View file

@ -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<JoinSpaceTask.Params, SpaceService.JoinSpaceResult> {
internal interface JoinSpaceTask : Task<JoinSpaceTask.Params, JoinSpaceResult> {
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<String, Throwable>()
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)
}
}
}

View file

@ -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
}

View file

@ -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)
}
}
}

View file

@ -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

View file

@ -644,6 +644,9 @@ class RoomDetailFragment @Inject constructor(
private fun handleSpaceShare() {
roomDetailArgs.openShareSpaceForId?.let { spaceId ->
ShareSpaceBottomSheet.show(childFragmentManager, spaceId)
view?.post {
handleChatEffect(ChatEffect.CONFETTI)
}
}
}

View file

@ -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<SectionAdapterInfo>()
@ -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

View file

@ -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
}

View file

@ -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))

View file

@ -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) {

View file

@ -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()

View file

@ -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

View file

@ -29,7 +29,7 @@ data class CreateSpaceState(
val spaceType: SpaceType? = null,
val spaceTopology: SpaceTopology? = null,
val nameInlineError: String? = null,
val defaultRooms: Map<Int, String?>? = null,
val defaultRooms: Map<Int /** position in form */, String?>? = null,
val creationResult: Async<String> = Uninitialized
) : MvRxState {

View file

@ -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() }
}

View file

@ -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() {

View file

@ -44,7 +44,7 @@ import org.matrix.android.sdk.api.session.room.roomSummaryQueryParams
class AddRoomError(val errorList: Map<String, Throwable>) : Throwable() {
override fun getLocalizedMessage(): String? {
return errorList.map { it.value.localizedMessage }.joinToString(",")
return errorList.map { it.value.localizedMessage }.joinToString()
}
}

View file

@ -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()
}

View file

@ -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()
}

View file

@ -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()))
}
}

View file

@ -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)
}
}

View file

@ -18,36 +18,36 @@
<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:baselineAligned="false"
android:gravity="center_vertical"
android:orientation="horizontal"
android:baselineAligned="false">
android:orientation="horizontal">
<RelativeLayout
android:id="@+id/groupToolbarAvatarImageView"
android:contentDescription="@string/a11y_open_drawer"
android:layout_width="40dp"
android:layout_height="40dp"
android:layout_marginTop="8dp"
android:layout_marginBottom="8dp"
android:contentDescription="@string/a11y_open_drawer"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent"
android:layout_width="40dp"
android:layout_height="40dp">
app:layout_constraintTop_toTopOf="parent">
<ImageView
android:importantForAccessibility="no"
android:layout_width="28dp"
android:layout_height="28dp"
android:layout_centerVertical="true"
android:src="@drawable/ic_space_icons"
app:tint="?riotx_text_secondary"
android:layout_marginStart="4dp"
/>
android:importantForAccessibility="no"
android:src="@drawable/ic_space_icons"
app:tint="?riotx_text_secondary" />
<!-- Not yet done -->
<im.vector.app.features.home.room.list.UnreadCounterBadgeView
android:id="@+id/drawerUnreadCounterBadgeView"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentTop="true"
android:layout_alignParentEnd="true"
android:layout_marginEnd="0dp"
android:gravity="center"
android:minWidth="16dp"
@ -57,20 +57,18 @@
android:textColor="@android:color/white"
android:textSize="10sp"
android:visibility="gone"
android:layout_alignParentTop="true"
android:layout_alignParentEnd="true"
tools:background="@drawable/bg_unread_highlight"
tools:text="4"
tools:visibility="visible" />
</RelativeLayout>
<LinearLayout
android:id="@+id/homeToolbarContent"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="1"
android:gravity="start"
android:orientation="vertical"
android:id="@+id/homeToolbarContent"
android:paddingStart="8dp"
android:paddingEnd="8dp">
@ -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" />
</LinearLayout>

View file

@ -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"

View file

@ -9,7 +9,6 @@
<ProgressBar
android:id="@+id/progressBar"
style="?progressBarStyle"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center" />