Custom copy for notifications that contain mentions (#2050)

This commit is contained in:
Mauro
2023-11-09 19:12:11 +01:00
committed by GitHub
parent 019ca625ab
commit a4bc7b8e36
21 changed files with 139 additions and 90 deletions
+13 -2
View File
@@ -99,8 +99,19 @@ struct NotificationContentBuilder {
private func processRoomMessage(notificationItem: NotificationItemProxyProtocol, messageType: MessageType, mediaProvider: MediaProviderProtocol?) async throws -> UNMutableNotificationContent {
var notification = try await processCommonRoomMessage(notificationItem: notificationItem, mediaProvider: mediaProvider)
let senderDisplayName = notificationItem.senderDisplayName ?? notificationItem.roomDisplayName
notification.body = String(messageEventStringBuilder.buildAttributedString(for: messageType, senderDisplayName: senderDisplayName, prefixWithSenderName: false).characters)
let displayName = notificationItem.senderDisplayName ?? notificationItem.roomDisplayName
let message = String(messageEventStringBuilder.buildAttributedString(for: messageType, senderDisplayName: displayName, prefixWithSenderName: false).characters)
let body: String
if notificationItem.hasMention {
if let senderDisplayName = notificationItem.senderDisplayName {
body = L10n.notificationMentionedYouBody(senderDisplayName, message)
} else {
body = L10n.notificationMentionedYouFallbackBody(message)
}
} else {
body = message
}
notification.body = body
switch messageType {
case .image(content: let content):
@@ -40,8 +40,8 @@ import UserNotifications
// We keep a global `environment` singleton to ensure that our app context,
// database, logging, etc. are only ever setup once per *process*
private let settings = NSESettings()
private let notificationContentBuilder = NotificationContentBuilder(messageEventStringBuilder: RoomMessageEventStringBuilder(attributedStringBuilder: AttributedStringBuilder(permalinkBaseURL: .homeDirectory,
private let settings: NSESettingsProtocol = AppSettings()
private let notificationContentBuilder = NotificationContentBuilder(messageEventStringBuilder: RoomMessageEventStringBuilder(attributedStringBuilder: AttributedStringBuilder(permalinkBaseURL: settings.permalinkBaseURL,
mentionBuilder: PlainMentionBuilder())))
private let keychainController = KeychainController(service: .sessions,
accessGroup: InfoPlistReader.main.keychainAccessGroupIdentifier)
@@ -16,13 +16,10 @@
import Foundation
final class NSESettings {
private static var suiteName: String = InfoPlistReader.main.appGroupIdentifier
/// UserDefaults to be used on reads and writes.
private static var store: UserDefaults! = UserDefaults(suiteName: suiteName)
/// The log level that should be used by `MXLog`.
@UserPreference(key: SharedUserDefaultsKeys.logLevel, defaultValue: TracingConfiguration.LogLevel.info, storageType: .userDefaults(store))
var logLevel
protocol NSESettingsProtocol {
var permalinkBaseURL: URL { get }
var logLevel: TracingConfiguration.LogLevel { get }
}
extension AppSettings: NSESettingsProtocol { }