mirror of
https://github.com/SchildiChat/SchildiChat-android.git
synced 2024-11-23 01:45:52 +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,
|
||||
roomMember: RoomMemberContent
|
||||
) {
|
||||
val roomMemberEntity = RoomMemberEntityFactory.create(
|
||||
roomId,
|
||||
userId,
|
||||
roomMember,
|
||||
// When an update is happening, insertOrUpdate replace existing values with null if they are not provided,
|
||||
// but we want to preserve presence record value and not replace it with null
|
||||
getExistingPresenceState(realm, roomId, userId)
|
||||
)
|
||||
realm.insertOrUpdate(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
|
||||
val existingRoomMemberSummary = RoomMemberSummaryEntity.where(realm, roomId, userId).findFirst()
|
||||
if (existingRoomMemberSummary != null) {
|
||||
existingRoomMemberSummary.displayName = roomMember.displayName
|
||||
existingRoomMemberSummary.avatarUrl = roomMember.avatarUrl
|
||||
existingRoomMemberSummary.membership = roomMember.membership
|
||||
} else {
|
||||
val roomMemberEntity = RoomMemberEntityFactory.create(
|
||||
roomId,
|
||||
userId,
|
||||
roomMember
|
||||
)
|
||||
realm.insert(roomMemberEntity)
|
||||
}
|
||||
}
|
||||
|
||||
private fun saveUserEntityLocallyIfNecessary(
|
||||
|
|
Loading…
Reference in a new issue