mirror of
https://github.com/element-hq/element-android
synced 2024-11-27 20:06:51 +03:00
LoadRoomMembers: handle room member event a bit more efficiently
This commit is contained in:
parent
63f0cce561
commit
61c5bbc444
1 changed files with 13 additions and 17 deletions
|
@ -83,23 +83,19 @@ internal class RoomMemberEventHandler @Inject constructor(
|
||||||
userId: String,
|
userId: String,
|
||||||
roomMember: RoomMemberContent
|
roomMember: RoomMemberContent
|
||||||
) {
|
) {
|
||||||
val roomMemberEntity = RoomMemberEntityFactory.create(
|
val existingRoomMemberSummary = RoomMemberSummaryEntity.where(realm, roomId, userId).findFirst()
|
||||||
roomId,
|
if (existingRoomMemberSummary != null) {
|
||||||
userId,
|
existingRoomMemberSummary.displayName = roomMember.displayName
|
||||||
roomMember,
|
existingRoomMemberSummary.avatarUrl = roomMember.avatarUrl
|
||||||
// When an update is happening, insertOrUpdate replace existing values with null if they are not provided,
|
existingRoomMemberSummary.membership = roomMember.membership
|
||||||
// but we want to preserve presence record value and not replace it with null
|
} else {
|
||||||
getExistingPresenceState(realm, roomId, userId)
|
val roomMemberEntity = RoomMemberEntityFactory.create(
|
||||||
)
|
roomId,
|
||||||
realm.insertOrUpdate(roomMemberEntity)
|
userId,
|
||||||
}
|
roomMember
|
||||||
|
)
|
||||||
/**
|
realm.insert(roomMemberEntity)
|
||||||
* Get the already existing presence state for a specific user & room in order NOT to be replaced in RoomMemberSummaryEntity
|
}
|
||||||
* by NULL value.
|
|
||||||
*/
|
|
||||||
private fun getExistingPresenceState(realm: Realm, roomId: String, userId: String): UserPresenceEntity? {
|
|
||||||
return RoomMemberSummaryEntity.where(realm, roomId, userId).findFirst()?.userPresenceEntity
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private fun saveUserEntityLocallyIfNecessary(
|
private fun saveUserEntityLocallyIfNecessary(
|
||||||
|
|
Loading…
Reference in a new issue