Fix avatar for DM when other user has left

This commit is contained in:
Benoit Marty 2021-04-02 18:20:12 +02:00 committed by Benoit Marty
parent 15a463d748
commit 5dc28c0564
3 changed files with 13 additions and 3 deletions

View File

@ -56,7 +56,13 @@ internal class RoomAvatarResolver @Inject constructor(@UserId private val userId
if (isDirectRoom) { if (isDirectRoom) {
if (members.size == 1) { if (members.size == 1) {
return members.firstOrNull()?.avatarUrl // Use avatar of a left user
val firstLeftAvatarUrl = roomMembers.queryLeftRoomMembersEvent()
.findAll()
.firstOrNull { !it.avatarUrl.isNullOrEmpty() }
?.avatarUrl
return firstLeftAvatarUrl ?: members.firstOrNull()?.avatarUrl
} else if (members.size == 2) { } else if (members.size == 2) {
val firstOtherMember = members.where().notEqualTo(RoomMemberSummaryEntityFields.USER_ID, userId).findFirst() val firstOtherMember = members.where().notEqualTo(RoomMemberSummaryEntityFields.USER_ID, userId).findFirst()
return firstOtherMember?.avatarUrl return firstOtherMember?.avatarUrl

View File

@ -107,9 +107,8 @@ internal class RoomDisplayNameResolver @Inject constructor(
name = when (otherMembersCount) { name = when (otherMembersCount) {
0 -> { 0 -> {
// Get left members if any // Get left members if any
val leftMembersNames = roomMembers.queryRoomMembersEvent() val leftMembersNames = roomMembers.queryLeftRoomMembersEvent()
.findAll() .findAll()
.filter { it.membership == Membership.LEAVE }
.map { it.getBestName() } .map { it.getBestName() }
roomDisplayNameFallbackProvider.getNameForEmptyRoom(roomSummary?.isDirect.orFalse(), leftMembersNames) roomDisplayNameFallbackProvider.getNameForEmptyRoom(roomSummary?.isDirect.orFalse(), leftMembersNames)
} }

View File

@ -75,6 +75,11 @@ internal class RoomMemberHelper(private val realm: Realm,
.equalTo(RoomMemberSummaryEntityFields.MEMBERSHIP_STR, Membership.INVITE.name) .equalTo(RoomMemberSummaryEntityFields.MEMBERSHIP_STR, Membership.INVITE.name)
} }
fun queryLeftRoomMembersEvent(): RealmQuery<RoomMemberSummaryEntity> {
return queryRoomMembersEvent()
.equalTo(RoomMemberSummaryEntityFields.MEMBERSHIP_STR, Membership.LEAVE.name)
}
fun queryActiveRoomMembersEvent(): RealmQuery<RoomMemberSummaryEntity> { fun queryActiveRoomMembersEvent(): RealmQuery<RoomMemberSummaryEntity> {
return queryRoomMembersEvent() return queryRoomMembersEvent()
.beginGroup() .beginGroup()