Replace matrix ids by displayname in notice events (#8395)

This commit is contained in:
Yoan Pintas 2023-05-10 10:30:21 +02:00 committed by GitHub
parent da9dd57d64
commit 36b1e9b5e4
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
3 changed files with 8 additions and 3 deletions

1
changelog.d/8365.misc Normal file
View file

@ -0,0 +1 @@
Matrix-Ids are sometimes shown in notice events instead of display names

View file

@ -39,7 +39,9 @@
<string name="notice_avatar_url_changed_by_you">You changed your avatar</string>
<string name="notice_display_name_set">%1$s set their display name to %2$s</string>
<string name="notice_display_name_set_by_you">You set your display name to %1$s</string>
<string name="notice_display_name_changed_from">%1$s changed their display name from %2$s to %3$s</string>
<!-- TODO TO BE REMOVED -->
<string tools:ignore="UnusedResources" name="notice_display_name_changed_from">%1$s changed their display name from %2$s to %3$s</string>
<string name="notice_display_name_changed_to">%1$s changed their display name to %2$s</string>
<string name="notice_display_name_changed_from_by_you">You changed your display name from %1$s to %2$s</string>
<string name="notice_display_name_removed">%1$s removed their display name (it was %2$s)</string>
<string name="notice_display_name_removed_by_you">You removed your display name (it was %1$s)</string>

View file

@ -124,6 +124,7 @@ class NoticeEventFormatter @Inject constructor(
private fun formatRoomPowerLevels(event: Event, disambiguatedDisplayName: String): CharSequence? {
val powerLevelsContent: PowerLevelsContent = event.content.toModel() ?: return null
val previousPowerLevelsContent: PowerLevelsContent = event.resolvedPrevContent().toModel() ?: return null
val roomService = activeSessionDataSource.currentValue?.orNull()?.roomService()
val userIds = HashSet<String>()
userIds.addAll(powerLevelsContent.users.orEmpty().keys)
userIds.addAll(previousPowerLevelsContent.users.orEmpty().keys)
@ -134,7 +135,8 @@ class NoticeEventFormatter @Inject constructor(
if (from != to) {
val fromStr = roleFormatter.format(from)
val toStr = roleFormatter.format(to)
val diff = sp.getString(R.string.notice_power_level_diff, userId, fromStr, toStr)
val displayName = event.roomId?.let { roomService?.getRoomMember(userId, it)?.displayName } ?: userId
val diff = sp.getString(R.string.notice_power_level_diff, displayName, fromStr, toStr)
diffs.add(diff)
}
}
@ -644,7 +646,7 @@ class NoticeEventFormatter @Inject constructor(
if (event.isSentByCurrentUser()) {
sp.getString(R.string.notice_display_name_changed_from_by_you, prevEventContent?.displayName, eventContent?.displayName)
} else {
sp.getString(R.string.notice_display_name_changed_from, event.senderId, prevEventContent?.displayName, eventContent?.displayName)
sp.getString(R.string.notice_display_name_changed_to, prevEventContent?.displayName, eventContent?.displayName)
}
}
displayText.append(displayNameText)