diff --git a/Mastodon/In Progress New Layout and Datamodel/NotificationRowView.swift b/Mastodon/In Progress New Layout and Datamodel/NotificationRowView.swift index 690d64ba7..9d549644b 100644 --- a/Mastodon/In Progress New Layout and Datamodel/NotificationRowView.swift +++ b/Mastodon/In Progress New Layout and Datamodel/NotificationRowView.swift @@ -13,13 +13,13 @@ import SwiftUI enum AuthorName { case me - case other(named: String) + case other(named: String, emojis: [MastodonContent.Shortcode : String ]) - var string: String { + var plainString: String { switch self { case .me: return "You" - case .other(let name): + case .other(let name, _): return name } } @@ -118,7 +118,7 @@ extension GroupedNotificationType { assert(totalAuthorCount == 1) //assert(self == .poll) return AttributedString(L10n.Scene.Notification.GroupedNotificationDescription.yourPollHasEnded) - case .other(let firstAuthorName): + case .other(let firstAuthorName, let emojis): var plainString: String if totalAuthorCount == 1 { switch self { @@ -159,13 +159,10 @@ extension GroupedNotificationType { var composedString = AttributedString(plainString) if let range = composedString.range(of: firstAuthorName) { - let authorNameComponent = stylableNameComponent(firstAuthorName) - composedString.replaceSubrange(range, with: authorNameComponent) let nameStyling = AttributeContainer.font( .system(.body, weight: .bold)) - let nameContainer = AttributeContainer.personNameComponent( - .givenName) - composedString.replaceAttributes(nameContainer, with: nameStyling) + let authorNameComponent = styledNameComponent(firstAuthorName, style: nameStyling, emojis: emojis) + composedString.replaceSubrange(range, with: authorNameComponent) } return composedString } @@ -177,7 +174,8 @@ extension Mastodon.Entity.Report { // "Someone reported X posts from someone else for rule violation" var summary: AttributedString { if let targetedAccountName = targetAccount?.displayNameWithFallback { - let boldedName = stylableNameComponent(targetedAccountName) + let boldedName = styledNameComponent(targetedAccountName, style: AttributeContainer.font( + .system(.body, weight: .bold)), emojis: targetAccount?.emojiMeta) if let postCount = flaggedStatusIDs?.count { return AttributedString( "Someone reported \(postCount) posts from ") + boldedName @@ -762,9 +760,9 @@ enum NotificationViewComponent: Identifiable { } } -func stylableNameComponent(_ name: String) -> AttributedString { - let nameComponent = PersonNameComponents(givenName: name).formatted( - .name(style: .long).attributed) +func styledNameComponent(_ name: String, style: AttributeContainer, emojis: [MastodonContent.Shortcode: String]?) -> AttributedString { + var nameComponent = attributedString(fromHtml: name, emojis: emojis ?? [:]) + nameComponent.setAttributes(style) return nameComponent } diff --git a/Mastodon/In Progress New Layout and Datamodel/NotificationRowViewModel.swift b/Mastodon/In Progress New Layout and Datamodel/NotificationRowViewModel.swift index 629b6cc3d..522ade6ef 100644 --- a/Mastodon/In Progress New Layout and Datamodel/NotificationRowViewModel.swift +++ b/Mastodon/In Progress New Layout and Datamodel/NotificationRowViewModel.swift @@ -753,7 +753,7 @@ extension NotificationSourceAccounts { switch authorName { case .me, .none: return nil - case .other(let name): + case .other(let name, _): if totalActorCount > 1 { let formatter = ListFormatter() return formatter.string(from: [name, L10n.Plural.Count.others(totalActorCount - 1)]) diff --git a/Mastodon/Scene/Notification/NotificationView/NotificationView+Configuration.swift b/Mastodon/Scene/Notification/NotificationView/NotificationView+Configuration.swift index 091b4109b..39e373820 100644 --- a/Mastodon/Scene/Notification/NotificationView/NotificationView+Configuration.swift +++ b/Mastodon/Scene/Notification/NotificationView/NotificationView+Configuration.swift @@ -641,7 +641,7 @@ extension AccountInfo { return .me } else { guard let fullAccount else { return nil } - return .other(named: fullAccount.displayNameWithFallback) + return .other(named: fullAccount.displayNameWithFallback, emojis: fullAccount.emojiMeta) } } }