separate displayName from avatarDisplayName in notification icons

This commit is contained in:
Mauro Romito
2025-11-17 16:02:00 +01:00
committed by Mauro
parent 627a10d7d4
commit 8ab5cf849e
+23 -13
View File
@@ -109,9 +109,11 @@ struct NotificationContentBuilder {
notificationContent.body = body notificationContent.body = body
let name = notificationItem.senderDisplayName ?? notificationItem.roomDisplayName
await addSenderIcon(notificationContent: &notificationContent, await addSenderIcon(notificationContent: &notificationContent,
senderID: notificationItem.senderID, senderID: notificationItem.senderID,
senderName: notificationItem.senderDisplayName ?? notificationItem.roomDisplayName, senderAvatarDisplayName: name,
senderDisplayName: name,
icon: icon(for: notificationItem), icon: icon(for: notificationItem),
forcePlaceholder: userSession.inviteAvatarsVisibility == .off, forcePlaceholder: userSession.inviteAvatarsVisibility == .off,
mediaProvider: mediaProvider) mediaProvider: mediaProvider)
@@ -126,15 +128,18 @@ struct NotificationContentBuilder {
} }
notificationContent.categoryIdentifier = NotificationConstants.Category.message notificationContent.categoryIdentifier = NotificationConstants.Category.message
let senderName = if let displayName = notificationItem.senderDisplayName { let senderAvatarDisplayName = if let displayName = notificationItem.senderDisplayName {
notificationItem.hasMention ? L10n.notificationSenderMentionReply(displayName) : displayName displayName
} else { } else {
notificationItem.roomDisplayName notificationItem.senderID
} }
let senderDisplayName = notificationItem.hasMention ? L10n.notificationSenderMentionReply(senderAvatarDisplayName) : senderAvatarDisplayName
await addSenderIcon(notificationContent: &notificationContent, await addSenderIcon(notificationContent: &notificationContent,
senderID: notificationItem.senderID, senderID: notificationItem.senderID,
senderName: senderName, senderAvatarDisplayName: senderAvatarDisplayName,
senderDisplayName: senderDisplayName,
icon: icon(for: notificationItem), icon: icon(for: notificationItem),
mediaProvider: mediaProvider) mediaProvider: mediaProvider)
} }
@@ -143,7 +148,8 @@ struct NotificationContentBuilder {
if notificationItem.isDM { if notificationItem.isDM {
if userSession.appSettings.threadsEnabled, let threadRootEventID = notificationItem.threadRootEventID { if userSession.appSettings.threadsEnabled, let threadRootEventID = notificationItem.threadRootEventID {
.init(mediaSource: notificationItem.senderAvatarMediaSource, .init(mediaSource: notificationItem.senderAvatarMediaSource,
groupInfo: .init(name: L10n.commonThread, groupInfo: .init(avatarDisplayName: notificationItem.senderDisplayName ?? notificationItem.senderID,
displayName: L10n.commonThread,
id: "\(notificationItem.roomID)\(threadRootEventID)")) id: "\(notificationItem.roomID)\(threadRootEventID)"))
} else { } else {
.init(mediaSource: notificationItem.senderAvatarMediaSource, groupInfo: nil) .init(mediaSource: notificationItem.senderAvatarMediaSource, groupInfo: nil)
@@ -151,11 +157,13 @@ struct NotificationContentBuilder {
} else { } else {
if userSession.appSettings.threadsEnabled, let threadRootEventID = notificationItem.threadRootEventID { if userSession.appSettings.threadsEnabled, let threadRootEventID = notificationItem.threadRootEventID {
.init(mediaSource: notificationItem.roomAvatarMediaSource, .init(mediaSource: notificationItem.roomAvatarMediaSource,
groupInfo: .init(name: L10n.notificationThreadInRoom(notificationItem.roomDisplayName), groupInfo: .init(avatarDisplayName: notificationItem.roomDisplayName,
displayName: L10n.notificationThreadInRoom(notificationItem.roomDisplayName),
id: "\(notificationItem.roomID)\(threadRootEventID)")) id: "\(notificationItem.roomID)\(threadRootEventID)"))
} else { } else {
.init(mediaSource: notificationItem.roomAvatarMediaSource, .init(mediaSource: notificationItem.roomAvatarMediaSource,
groupInfo: .init(name: notificationItem.roomDisplayName, groupInfo: .init(avatarDisplayName: notificationItem.roomDisplayName,
displayName: notificationItem.roomDisplayName,
id: notificationItem.roomID)) id: notificationItem.roomID))
} }
} }
@@ -225,7 +233,8 @@ struct NotificationContentBuilder {
private func addSenderIcon(notificationContent: inout UNMutableNotificationContent, private func addSenderIcon(notificationContent: inout UNMutableNotificationContent,
senderID: String, senderID: String,
senderName: String, senderAvatarDisplayName: String,
senderDisplayName: String,
icon: NotificationIcon, icon: NotificationIcon,
forcePlaceholder: Bool = false, forcePlaceholder: Bool = false,
mediaProvider: MediaProviderProtocol) async { mediaProvider: MediaProviderProtocol) async {
@@ -243,7 +252,7 @@ struct NotificationContentBuilder {
if let fetchedImage { if let fetchedImage {
image = fetchedImage image = fetchedImage
} else if let data = await getPlaceholderAvatarImageData(name: icon.groupInfo?.name ?? senderName, } else if let data = await getPlaceholderAvatarImageData(name: icon.groupInfo?.avatarDisplayName ?? senderAvatarDisplayName,
id: icon.groupInfo?.id ?? senderID) { id: icon.groupInfo?.id ?? senderID) {
image = INImage(imageData: data) image = INImage(imageData: data)
} else { } else {
@@ -253,7 +262,7 @@ struct NotificationContentBuilder {
let senderHandle = INPersonHandle(value: senderID, type: .unknown) let senderHandle = INPersonHandle(value: senderID, type: .unknown)
let sender = INPerson(personHandle: senderHandle, let sender = INPerson(personHandle: senderHandle,
nameComponents: nil, nameComponents: nil,
displayName: senderName, displayName: senderDisplayName,
image: !icon.shouldDisplayAsGroup ? image : nil, image: !icon.shouldDisplayAsGroup ? image : nil,
contactIdentifier: nil, contactIdentifier: nil,
customIdentifier: nil) customIdentifier: nil)
@@ -264,7 +273,7 @@ struct NotificationContentBuilder {
if let groupInfo = icon.groupInfo { if let groupInfo = icon.groupInfo {
let meHandle = INPersonHandle(value: notificationContent.receiverID, type: .unknown) let meHandle = INPersonHandle(value: notificationContent.receiverID, type: .unknown)
let me = INPerson(personHandle: meHandle, nameComponents: nil, displayName: nil, image: nil, contactIdentifier: nil, customIdentifier: nil, isMe: true) let me = INPerson(personHandle: meHandle, nameComponents: nil, displayName: nil, image: nil, contactIdentifier: nil, customIdentifier: nil, isMe: true)
speakableGroupName = INSpeakableString(spokenPhrase: groupInfo.name) speakableGroupName = INSpeakableString(spokenPhrase: groupInfo.displayName)
recipients = [sender, me] recipients = [sender, me]
} }
@@ -330,7 +339,8 @@ struct NotificationContentBuilder {
private struct NotificationIcon { private struct NotificationIcon {
struct GroupInfo { struct GroupInfo {
let name: String let avatarDisplayName: String
let displayName: String
let id: String let id: String
} }