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 607dc48772
commit 1e08967ece

View File

@@ -109,9 +109,11 @@ struct NotificationContentBuilder {
notificationContent.body = body
let name = notificationItem.senderDisplayName ?? notificationItem.roomDisplayName
await addSenderIcon(notificationContent: &notificationContent,
senderID: notificationItem.senderID,
senderName: notificationItem.senderDisplayName ?? notificationItem.roomDisplayName,
senderAvatarDisplayName: name,
senderDisplayName: name,
icon: icon(for: notificationItem),
forcePlaceholder: userSession.inviteAvatarsVisibility == .off,
mediaProvider: mediaProvider)
@@ -126,15 +128,18 @@ struct NotificationContentBuilder {
}
notificationContent.categoryIdentifier = NotificationConstants.Category.message
let senderName = if let displayName = notificationItem.senderDisplayName {
notificationItem.hasMention ? L10n.notificationSenderMentionReply(displayName) : displayName
let senderAvatarDisplayName = if let displayName = notificationItem.senderDisplayName {
displayName
} else {
notificationItem.roomDisplayName
notificationItem.senderID
}
let senderDisplayName = notificationItem.hasMention ? L10n.notificationSenderMentionReply(senderAvatarDisplayName) : senderAvatarDisplayName
await addSenderIcon(notificationContent: &notificationContent,
senderID: notificationItem.senderID,
senderName: senderName,
senderAvatarDisplayName: senderAvatarDisplayName,
senderDisplayName: senderDisplayName,
icon: icon(for: notificationItem),
mediaProvider: mediaProvider)
}
@@ -143,7 +148,8 @@ struct NotificationContentBuilder {
if notificationItem.isDM {
if userSession.appSettings.threadsEnabled, let threadRootEventID = notificationItem.threadRootEventID {
.init(mediaSource: notificationItem.senderAvatarMediaSource,
groupInfo: .init(name: L10n.commonThread,
groupInfo: .init(avatarDisplayName: notificationItem.senderDisplayName ?? notificationItem.senderID,
displayName: L10n.commonThread,
id: "\(notificationItem.roomID)\(threadRootEventID)"))
} else {
.init(mediaSource: notificationItem.senderAvatarMediaSource, groupInfo: nil)
@@ -151,11 +157,13 @@ struct NotificationContentBuilder {
} else {
if userSession.appSettings.threadsEnabled, let threadRootEventID = notificationItem.threadRootEventID {
.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)"))
} else {
.init(mediaSource: notificationItem.roomAvatarMediaSource,
groupInfo: .init(name: notificationItem.roomDisplayName,
groupInfo: .init(avatarDisplayName: notificationItem.roomDisplayName,
displayName: notificationItem.roomDisplayName,
id: notificationItem.roomID))
}
}
@@ -225,7 +233,8 @@ struct NotificationContentBuilder {
private func addSenderIcon(notificationContent: inout UNMutableNotificationContent,
senderID: String,
senderName: String,
senderAvatarDisplayName: String,
senderDisplayName: String,
icon: NotificationIcon,
forcePlaceholder: Bool = false,
mediaProvider: MediaProviderProtocol) async {
@@ -243,7 +252,7 @@ struct NotificationContentBuilder {
if let 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) {
image = INImage(imageData: data)
} else {
@@ -253,7 +262,7 @@ struct NotificationContentBuilder {
let senderHandle = INPersonHandle(value: senderID, type: .unknown)
let sender = INPerson(personHandle: senderHandle,
nameComponents: nil,
displayName: senderName,
displayName: senderDisplayName,
image: !icon.shouldDisplayAsGroup ? image : nil,
contactIdentifier: nil,
customIdentifier: nil)
@@ -264,7 +273,7 @@ struct NotificationContentBuilder {
if let groupInfo = icon.groupInfo {
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)
speakableGroupName = INSpeakableString(spokenPhrase: groupInfo.name)
speakableGroupName = INSpeakableString(spokenPhrase: groupInfo.displayName)
recipients = [sender, me]
}
@@ -330,7 +339,8 @@ struct NotificationContentBuilder {
private struct NotificationIcon {
struct GroupInfo {
let name: String
let avatarDisplayName: String
let displayName: String
let id: String
}