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 { }
+3 -3
View File
@@ -66,8 +66,8 @@ targets:
DEVELOPMENT_TEAM: $(DEVELOPMENT_TEAM)
CODE_SIGN_ENTITLEMENTS: NSE/SupportingFiles/NSE.entitlements
SWIFT_OBJC_INTERFACE_HEADER_NAME: GeneratedInterface-Swift.h
debug:
release:
OTHER_SWIFT_FLAGS:
- "-DIS_NSE"
sources:
- path: ../Sources
@@ -91,7 +91,6 @@ targets:
- path: ../../ElementX/Sources/Other/Logging
- path: ../../ElementX/Sources/Other/MatrixEntityRegex.swift
- path: ../../ElementX/Sources/Other/PermalinkBuilder.swift
- path: ../../ElementX/Sources/Other/SharedUserDefaultsKeys.swift
- path: ../../ElementX/Sources/Other/SwiftUI/Views/PlaceholderAvatarImage.swift
- path: ../../ElementX/Sources/Other/UserAgentBuilder.swift
- path: ../../ElementX/Sources/Other/UserPreference.swift
@@ -107,3 +106,4 @@ targets:
- path: ../../ElementX/Sources/Services/Notification/Proxy
- path: ../../ElementX/Sources/Services/Room/RoomSummary/RoomMessageEventStringBuilder.swift
- path: ../../ElementX/Sources/Services/UserSession/RestorationToken.swift
- path: ../../ElementX/Sources/Application/AppSettings.swift