Code review

This commit is contained in:
Benoit Marty 2021-05-07 12:33:01 +02:00
parent 64f1834913
commit e969d663a5
5 changed files with 14 additions and 19 deletions

View File

@ -26,7 +26,7 @@ import org.matrix.android.sdk.api.session.room.timeline.TimelineEvent
* This class holds some data of a room. * 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] * 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, val roomId: String,
// Computed display name // Computed display name
val displayName: String = "", val displayName: String = "",
@ -35,6 +35,7 @@ data class RoomSummary constructor(
val avatarUrl: String = "", val avatarUrl: String = "",
val canonicalAlias: String? = null, val canonicalAlias: String? = null,
val aliases: List<String> = emptyList(), val aliases: List<String> = emptyList(),
val joinRules: RoomJoinRules? = null,
val isDirect: Boolean = false, val isDirect: Boolean = false,
val directUserId: String? = null, val directUserId: String? = null,
val joinedMembersCount: Int? = 0, val joinedMembersCount: Int? = 0,
@ -59,8 +60,7 @@ data class RoomSummary constructor(
val roomType: String? = null, val roomType: String? = null,
val spaceParents: List<SpaceParentInfo>? = null, val spaceParents: List<SpaceParentInfo>? = null,
val spaceChildren: List<SpaceChildInfo>? = null, val spaceChildren: List<SpaceChildInfo>? = null,
val flattenParentIds: List<String> = emptyList(), val flattenParentIds: List<String> = emptyList()
val joinRules: RoomJoinRules? = null
) { ) {
val isVersioned: Boolean val isVersioned: Boolean

View File

@ -44,6 +44,7 @@ internal class RoomSummaryMapper @Inject constructor(private val timelineEventMa
name = roomSummaryEntity.name ?: "", name = roomSummaryEntity.name ?: "",
topic = roomSummaryEntity.topic ?: "", topic = roomSummaryEntity.topic ?: "",
avatarUrl = roomSummaryEntity.avatarUrl ?: "", avatarUrl = roomSummaryEntity.avatarUrl ?: "",
joinRules = roomSummaryEntity.joinRules,
isDirect = roomSummaryEntity.isDirect, isDirect = roomSummaryEntity.isDirect,
directUserId = roomSummaryEntity.directUserId, directUserId = roomSummaryEntity.directUserId,
latestPreviewableEvent = latestEvent, latestPreviewableEvent = latestEvent,
@ -91,8 +92,7 @@ internal class RoomSummaryMapper @Inject constructor(private val timelineEventMa
parentRoomId = roomSummaryEntity.roomId parentRoomId = roomSummaryEntity.roomId
) )
}, },
flattenParentIds = roomSummaryEntity.flattenParentIds?.split("|") ?: emptyList(), flattenParentIds = roomSummaryEntity.flattenParentIds?.split("|") ?: emptyList()
joinRules = roomSummaryEntity.joinnRules
) )
} }
} }

View File

@ -21,6 +21,7 @@ import io.realm.RealmObject
import io.realm.annotations.Index import io.realm.annotations.Index
import io.realm.annotations.PrimaryKey import io.realm.annotations.PrimaryKey
import org.matrix.android.sdk.api.crypto.RoomEncryptionTrustLevel 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.Membership
import org.matrix.android.sdk.api.session.room.model.RoomJoinRules import org.matrix.android.sdk.api.session.room.model.RoomJoinRules
import org.matrix.android.sdk.api.session.room.model.RoomSummary import org.matrix.android.sdk.api.session.room.model.RoomSummary
@ -243,20 +244,16 @@ internal open class RoomSummaryEntity(
} }
} }
private var joinnRulesStr: String? = null private var joinRulesStr: String? = null
var joinnRules: RoomJoinRules? var joinRules: RoomJoinRules?
get() { get() {
return joinnRulesStr?.let { return joinRulesStr?.let {
try { tryOrNull { RoomJoinRules.valueOf(it) }
RoomJoinRules.valueOf(it)
} catch (failure: Throwable) {
null
}
} }
} }
set(value) { set(value) {
if (value?.name != joinnRulesStr) { if (value?.name != joinRulesStr) {
joinnRulesStr = value?.name joinRulesStr = value?.name
} }
} }

View File

@ -132,6 +132,7 @@ internal class RoomSummaryUpdater @Inject constructor(
roomSummaryEntity.avatarUrl = roomAvatarResolver.resolve(realm, roomId) roomSummaryEntity.avatarUrl = roomAvatarResolver.resolve(realm, roomId)
roomSummaryEntity.name = ContentMapper.map(lastNameEvent?.content).toModel<RoomNameContent>()?.name roomSummaryEntity.name = ContentMapper.map(lastNameEvent?.content).toModel<RoomNameContent>()?.name
roomSummaryEntity.topic = ContentMapper.map(lastTopicEvent?.content).toModel<RoomTopicContent>()?.topic roomSummaryEntity.topic = ContentMapper.map(lastTopicEvent?.content).toModel<RoomTopicContent>()?.topic
roomSummaryEntity.joinRules = ContentMapper.map(joinRulesEvent?.content).toModel<RoomJoinRulesContent>()?.joinRules
roomSummaryEntity.latestPreviewableEvent = latestPreviewableEvent roomSummaryEntity.latestPreviewableEvent = latestPreviewableEvent
roomSummaryEntity.canonicalAlias = ContentMapper.map(lastCanonicalAliasEvent?.content).toModel<RoomCanonicalAliasContent>() roomSummaryEntity.canonicalAlias = ContentMapper.map(lastCanonicalAliasEvent?.content).toModel<RoomCanonicalAliasContent>()
?.canonicalAlias ?.canonicalAlias
@ -173,8 +174,6 @@ internal class RoomSummaryUpdater @Inject constructor(
crossSigningService.onUsersDeviceUpdate(otherRoomMembers) crossSigningService.onUsersDeviceUpdate(otherRoomMembers)
} }
} }
roomSummaryEntity.joinnRules = ContentMapper.map(joinRulesEvent?.content).toModel<RoomJoinRulesContent>()?.joinRules
} }
private fun RoomSummaryEntity.updateHasFailedSending() { private fun RoomSummaryEntity.updateHasFailedSending() {

View File

@ -123,8 +123,7 @@ internal class DefaultSpaceService @Inject constructor(
encryptionEventTs = null, encryptionEventTs = null,
typingUsers = emptyList(), typingUsers = emptyList(),
isEncrypted = false, isEncrypted = false,
flattenParentIds = emptyList(), flattenParentIds = emptyList()
joinRules = null
), ),
second = response.rooms second = response.rooms
?.filter { it.roomId != spaceId } ?.filter { it.roomId != spaceId }