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 membershipStr = value.name
} }
fun getBestName() = displayName?.takeIf { it.isNotBlank() } ?: userId
companion object companion object
} }

View file

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