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 78a79dedb2..e06d70d4f9 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 @@ -26,7 +26,7 @@ import org.matrix.android.sdk.api.session.room.timeline.TimelineEvent * This class holds some data of a room. * It can be retrieved by [org.matrix.android.sdk.api.session.room.Room] and [org.matrix.android.sdk.api.session.room.RoomService] */ -data class RoomSummary constructor( +data class RoomSummary( val roomId: String, // Computed display name val displayName: String = "", @@ -35,6 +35,7 @@ data class RoomSummary constructor( val avatarUrl: String = "", val canonicalAlias: String? = null, val aliases: List = emptyList(), + val joinRules: RoomJoinRules? = null, val isDirect: Boolean = false, val directUserId: String? = null, val joinedMembersCount: Int? = 0, @@ -59,8 +60,7 @@ data class RoomSummary constructor( val roomType: String? = null, val spaceParents: List? = null, val spaceChildren: List? = null, - val flattenParentIds: List = emptyList(), - val joinRules: RoomJoinRules? = null + val flattenParentIds: List = emptyList() ) { val isVersioned: Boolean 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 e7f1e67c0a..0b057ec6fc 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 @@ -44,6 +44,7 @@ internal class RoomSummaryMapper @Inject constructor(private val timelineEventMa name = roomSummaryEntity.name ?: "", topic = roomSummaryEntity.topic ?: "", avatarUrl = roomSummaryEntity.avatarUrl ?: "", + joinRules = roomSummaryEntity.joinRules, isDirect = roomSummaryEntity.isDirect, directUserId = roomSummaryEntity.directUserId, latestPreviewableEvent = latestEvent, @@ -91,8 +92,7 @@ internal class RoomSummaryMapper @Inject constructor(private val timelineEventMa parentRoomId = roomSummaryEntity.roomId ) }, - flattenParentIds = roomSummaryEntity.flattenParentIds?.split("|") ?: emptyList(), - joinRules = roomSummaryEntity.joinnRules + flattenParentIds = roomSummaryEntity.flattenParentIds?.split("|") ?: emptyList() ) } } diff --git a/matrix-sdk-android/src/main/java/org/matrix/android/sdk/internal/database/model/RoomSummaryEntity.kt b/matrix-sdk-android/src/main/java/org/matrix/android/sdk/internal/database/model/RoomSummaryEntity.kt index d5e847f362..1001f9cd66 100644 --- a/matrix-sdk-android/src/main/java/org/matrix/android/sdk/internal/database/model/RoomSummaryEntity.kt +++ b/matrix-sdk-android/src/main/java/org/matrix/android/sdk/internal/database/model/RoomSummaryEntity.kt @@ -21,6 +21,7 @@ import io.realm.RealmObject import io.realm.annotations.Index import io.realm.annotations.PrimaryKey import org.matrix.android.sdk.api.crypto.RoomEncryptionTrustLevel +import org.matrix.android.sdk.api.extensions.tryOrNull import org.matrix.android.sdk.api.session.room.model.Membership import org.matrix.android.sdk.api.session.room.model.RoomJoinRules import org.matrix.android.sdk.api.session.room.model.RoomSummary @@ -243,20 +244,16 @@ internal open class RoomSummaryEntity( } } - private var joinnRulesStr: String? = null - var joinnRules: RoomJoinRules? + private var joinRulesStr: String? = null + var joinRules: RoomJoinRules? get() { - return joinnRulesStr?.let { - try { - RoomJoinRules.valueOf(it) - } catch (failure: Throwable) { - null - } + return joinRulesStr?.let { + tryOrNull { RoomJoinRules.valueOf(it) } } } set(value) { - if (value?.name != joinnRulesStr) { - joinnRulesStr = value?.name + if (value?.name != joinRulesStr) { + joinRulesStr = value?.name } } diff --git a/matrix-sdk-android/src/main/java/org/matrix/android/sdk/internal/session/room/summary/RoomSummaryUpdater.kt b/matrix-sdk-android/src/main/java/org/matrix/android/sdk/internal/session/room/summary/RoomSummaryUpdater.kt index 45cf3248cd..63fcb557a8 100644 --- a/matrix-sdk-android/src/main/java/org/matrix/android/sdk/internal/session/room/summary/RoomSummaryUpdater.kt +++ b/matrix-sdk-android/src/main/java/org/matrix/android/sdk/internal/session/room/summary/RoomSummaryUpdater.kt @@ -132,6 +132,7 @@ internal class RoomSummaryUpdater @Inject constructor( roomSummaryEntity.avatarUrl = roomAvatarResolver.resolve(realm, roomId) roomSummaryEntity.name = ContentMapper.map(lastNameEvent?.content).toModel()?.name roomSummaryEntity.topic = ContentMapper.map(lastTopicEvent?.content).toModel()?.topic + roomSummaryEntity.joinRules = ContentMapper.map(joinRulesEvent?.content).toModel()?.joinRules roomSummaryEntity.latestPreviewableEvent = latestPreviewableEvent roomSummaryEntity.canonicalAlias = ContentMapper.map(lastCanonicalAliasEvent?.content).toModel() ?.canonicalAlias @@ -173,8 +174,6 @@ internal class RoomSummaryUpdater @Inject constructor( crossSigningService.onUsersDeviceUpdate(otherRoomMembers) } } - - roomSummaryEntity.joinnRules = ContentMapper.map(joinRulesEvent?.content).toModel()?.joinRules } private fun RoomSummaryEntity.updateHasFailedSending() { 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 3e58c51a6f..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 @@ -123,8 +123,7 @@ internal class DefaultSpaceService @Inject constructor( encryptionEventTs = null, typingUsers = emptyList(), isEncrypted = false, - flattenParentIds = emptyList(), - joinRules = null + flattenParentIds = emptyList() ), second = response.rooms ?.filter { it.roomId != spaceId }