Return faster if list is empty

This commit is contained in:
Benoit Marty 2022-12-16 20:44:26 +01:00
parent b063b25e8c
commit 555cbe5f7d

View file

@ -31,10 +31,15 @@ internal class RoomTypingUsersHandler @Inject constructor(
// TODO This could be handled outside of the Realm transaction. Use the new aggregator?
fun handle(realm: Realm, roomId: String, ephemeralResult: RoomSyncHandler.EphemeralResult?) {
val typingUserIds = ephemeralResult?.typingUserIds
if (typingUserIds.isNullOrEmpty()) {
typingUsersTracker.setTypingUsersFromRoom(roomId, emptyList())
return
}
// Filter ignored users and current user
val filteredUserIds = realm.where(IgnoredUserEntity::class.java).findAll().map { it.userId } + userId
val roomMemberHelper = RoomMemberHelper(realm, roomId)
val typingIds = ephemeralResult?.typingUserIds?.filter { it !in filteredUserIds }.orEmpty()
val typingIds = typingUserIds.filter { it !in filteredUserIds }
val senderInfo = typingIds.map { userId ->
val roomMemberSummaryEntity = roomMemberHelper.getLastRoomMember(userId)
SenderInfo(