Improve room name for invitation

This commit is contained in:
Benoit Marty 2021-04-02 11:43:52 +02:00 committed by Benoit Marty
parent 2df8eb199b
commit bd14c77ff0
2 changed files with 11 additions and 9 deletions

View file

@ -39,5 +39,7 @@ internal open class RoomMemberSummaryEntity(@PrimaryKey var primaryKey: String =
membershipStr = value.name
}
fun getBestName() = displayName?.takeIf { it.isNotBlank() } ?: userId
companion object
}

View file

@ -77,14 +77,14 @@ internal class RoomDisplayNameResolver @Inject constructor(
if (roomEntity?.membership == Membership.INVITE) {
val inviteMeEvent = roomMembers.getLastStateEvent(userId)
val inviterId = inviteMeEvent?.sender
name = if (inviterId != null) {
activeMembers.where()
.equalTo(RoomMemberSummaryEntityFields.USER_ID, inviterId)
.findFirst()
?.displayName
} else {
roomDisplayNameFallbackProvider.getNameForRoomInvite()
}
name = inviterId
?.let {
activeMembers.where()
.equalTo(RoomMemberSummaryEntityFields.USER_ID, it)
.findFirst()
?.getBestName()
}
?: roomDisplayNameFallbackProvider.getNameForRoomInvite()
} else if (roomEntity?.membership == Membership.JOIN) {
val roomSummary = RoomSummaryEntity.where(realm, roomId).findFirst()
val invitedCount = roomSummary?.invitedMembersCount ?: 0
@ -150,7 +150,7 @@ internal class RoomDisplayNameResolver @Inject constructor(
if (roomMemberSummary == null) return null
val isUnique = roomMemberHelper.isUniqueDisplayName(roomMemberSummary.displayName)
return if (isUnique) {
roomMemberSummary.displayName
roomMemberSummary.getBestName()
} else {
"${roomMemberSummary.displayName} (${roomMemberSummary.userId})"
}