mirror of
https://github.com/Novaloop-AG/element-x-ios.git
synced 2026-10-31 08:15:24 +00:00
Run SwiftFormat.
This commit is contained in:
@@ -17,11 +17,11 @@ enum BootDetectionManager {
|
||||
guard let dummyData = dummyString.data(using: .utf8) else {
|
||||
return true
|
||||
}
|
||||
|
||||
|
||||
do {
|
||||
// add a unique filename
|
||||
let url = containerURL.appendingPathComponent(ProcessInfo.processInfo.globallyUniqueString)
|
||||
|
||||
|
||||
try dummyData.write(to: url, options: .completeFileProtectionUntilFirstUserAuthentication)
|
||||
let readData = try Data(contentsOf: url)
|
||||
let readString = String(data: readData, encoding: .utf8)
|
||||
|
||||
@@ -17,7 +17,7 @@ extension CommonSettingsProtocol {
|
||||
return UNNotificationSoundName(NotificationToneManager.selectedToneFilename)
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/// A `UNNotificationSound` built from `notificationSoundName`, ready to attach to a notification content object.
|
||||
var notificationSound: UNNotificationSound {
|
||||
UNNotificationSound(named: notificationSoundName)
|
||||
|
||||
@@ -55,7 +55,7 @@ final class NSEUserSession: NSEUserSessionProtocol {
|
||||
var threadsEnabled: Bool {
|
||||
appSettings.threadsEnabled
|
||||
}
|
||||
|
||||
|
||||
init(credentials: KeychainCredentials,
|
||||
roomID: String,
|
||||
clientSessionDelegate: ClientSessionDelegate,
|
||||
@@ -95,7 +95,7 @@ final class NSEUserSession: NSEUserSessionProtocol {
|
||||
func notificationItemProxy(roomID: String, eventID: String) async -> NotificationItemProxyProtocol? {
|
||||
do {
|
||||
let notificationStatus = try await notificationClient.getNotification(roomId: roomID, eventId: eventID)
|
||||
|
||||
|
||||
switch notificationStatus {
|
||||
case .event(let notification):
|
||||
return NotificationItemProxy(notificationItem: notification,
|
||||
@@ -134,7 +134,7 @@ final class NSEUserSession: NSEUserSessionProtocol {
|
||||
|
||||
private final class ClientDelegateWrapper: ClientDelegate {
|
||||
// MARK: - ClientDelegate
|
||||
|
||||
|
||||
func didReceiveAuthError(isSoftLogout: Bool) {
|
||||
MXLog.error("Received authentication error, the NSE can't handle this.")
|
||||
}
|
||||
|
||||
@@ -85,7 +85,7 @@ struct NotificationContentBuilder {
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
// MARK: - Private
|
||||
|
||||
private func processEmpty(_ notificationContent: inout UNMutableNotificationContent) {
|
||||
@@ -93,7 +93,7 @@ struct NotificationContentBuilder {
|
||||
notificationContent.body = L10n.notification
|
||||
notificationContent.categoryIdentifier = NotificationConstants.Category.message
|
||||
}
|
||||
|
||||
|
||||
private func processInvited(notificationContent: inout UNMutableNotificationContent,
|
||||
notificationItem: NotificationItemProxyProtocol,
|
||||
mediaProvider: MediaProviderProtocol) async {
|
||||
@@ -166,7 +166,7 @@ struct NotificationContentBuilder {
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
private func processRoomMessage(notificationContent: inout UNMutableNotificationContent,
|
||||
notificationItem: NotificationItemProxyProtocol,
|
||||
messageType: MessageType,
|
||||
@@ -228,7 +228,7 @@ struct NotificationContentBuilder {
|
||||
MXLog.error("Couldn't load the file for media attachment: \(error)")
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
private func addCommunicationContext(notificationContent: inout UNMutableNotificationContent,
|
||||
senderID: String,
|
||||
senderAvatarDisplayName: String,
|
||||
@@ -247,7 +247,7 @@ struct NotificationContentBuilder {
|
||||
MXLog.error("Couldn't add sender icon: \(error)")
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
if let fetchedImage {
|
||||
image = fetchedImage
|
||||
} else if let data = await Self.getPlaceholderAvatarImageData(name: icon.groupInfo?.avatarDisplayName ?? senderAvatarDisplayName,
|
||||
@@ -256,7 +256,7 @@ struct NotificationContentBuilder {
|
||||
} else {
|
||||
image = INImage(named: "")
|
||||
}
|
||||
|
||||
|
||||
let senderHandle = INPersonHandle(value: senderID, type: .unknown)
|
||||
let sender = INPerson(personHandle: senderHandle,
|
||||
nameComponents: nil,
|
||||
@@ -264,7 +264,7 @@ struct NotificationContentBuilder {
|
||||
image: !icon.shouldDisplayAsGroup ? image : nil,
|
||||
contactIdentifier: nil,
|
||||
customIdentifier: nil)
|
||||
|
||||
|
||||
// These are required to show the group name as subtitle
|
||||
var speakableGroupName: INSpeakableString?
|
||||
var recipients: [INPerson]?
|
||||
@@ -274,7 +274,7 @@ struct NotificationContentBuilder {
|
||||
speakableGroupName = INSpeakableString(spokenPhrase: groupInfo.displayName)
|
||||
recipients = [sender, me]
|
||||
}
|
||||
|
||||
|
||||
let intent = INSendMessageIntent(recipients: recipients,
|
||||
outgoingMessageType: .outgoingMessageText,
|
||||
content: nil,
|
||||
@@ -286,14 +286,14 @@ struct NotificationContentBuilder {
|
||||
if speakableGroupName != nil {
|
||||
intent.setImage(image, forParameterNamed: \.speakableGroupName)
|
||||
}
|
||||
|
||||
|
||||
// Use the intent to initialize the interaction.
|
||||
let interaction = INInteraction(intent: intent, response: nil)
|
||||
|
||||
|
||||
// Interaction direction is incoming because the user is
|
||||
// receiving this message.
|
||||
interaction.direction = .incoming
|
||||
|
||||
|
||||
// Donate the interaction before updating notification content.
|
||||
if !ProcessInfo.isRunningTests {
|
||||
try? await interaction.donate()
|
||||
@@ -307,7 +307,7 @@ struct NotificationContentBuilder {
|
||||
notificationContent = content
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@MainActor
|
||||
static func getPlaceholderAvatarImageData(name: String, id: String) async -> Data? {
|
||||
// The version value is used in case the design of the placeholder is updated to force a replacement
|
||||
|
||||
@@ -19,7 +19,7 @@ class NotificationHandler {
|
||||
private let tag: String
|
||||
|
||||
private let notificationContentBuilder: NotificationContentBuilder
|
||||
|
||||
|
||||
init(userSession: NSEUserSession,
|
||||
settings: CommonSettingsProtocol,
|
||||
contentHandler: @escaping (UNNotificationContent) -> Void,
|
||||
@@ -33,7 +33,7 @@ class NotificationHandler {
|
||||
|
||||
let eventStringBuilder = RoomMessageEventStringBuilder(attributedStringBuilder: AttributedStringBuilder(mentionBuilder: PlainMentionBuilder()),
|
||||
style: .plain)
|
||||
|
||||
|
||||
notificationContentBuilder = NotificationContentBuilder(messageEventStringBuilder: eventStringBuilder,
|
||||
notificationSoundName: settings.notificationSoundName,
|
||||
userSession: userSession)
|
||||
@@ -82,7 +82,7 @@ class NotificationHandler {
|
||||
MXLog.info("\(tag) Delivering notification")
|
||||
contentHandler(notificationContent)
|
||||
}
|
||||
|
||||
|
||||
private func discardNotification() {
|
||||
MXLog.info("\(tag) Discarding notification")
|
||||
|
||||
@@ -199,11 +199,11 @@ class NotificationHandler {
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
try? await expiringTask.run(timeout: Duration.seconds(5)) // Wait 5 seconds or just use whatever is available
|
||||
// Release the SDK subscription explicitly once we no longer need updates.
|
||||
observationToken.withLock { $0 = nil }
|
||||
|
||||
|
||||
guard room.hasActiveRoomCall() else {
|
||||
MXLog.info("The room no longer has an ongoing call, handling as push notification")
|
||||
return .shouldDisplay
|
||||
|
||||
@@ -15,15 +15,15 @@ struct NotificationItemProxy: NotificationItemProxyProtocol {
|
||||
let eventID: String
|
||||
let receiverID: String
|
||||
let roomID: String
|
||||
|
||||
|
||||
var event: NotificationEvent? {
|
||||
notificationItem.event
|
||||
}
|
||||
|
||||
|
||||
var senderDisplayName: String? {
|
||||
notificationItem.senderInfo.displayName
|
||||
}
|
||||
|
||||
|
||||
var senderID: String {
|
||||
switch notificationItem.event {
|
||||
case .timeline(let event):
|
||||
@@ -32,7 +32,7 @@ struct NotificationItemProxy: NotificationItemProxyProtocol {
|
||||
return senderID
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
var roomDisplayName: String {
|
||||
notificationItem.roomInfo.displayName
|
||||
}
|
||||
@@ -40,7 +40,7 @@ struct NotificationItemProxy: NotificationItemProxyProtocol {
|
||||
var isRoomSpace: Bool {
|
||||
notificationItem.roomInfo.isSpace
|
||||
}
|
||||
|
||||
|
||||
var isRoomDirect: Bool {
|
||||
notificationItem.roomInfo.isDirect
|
||||
}
|
||||
@@ -57,11 +57,11 @@ struct NotificationItemProxy: NotificationItemProxyProtocol {
|
||||
false
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
var roomJoinedMembers: Int {
|
||||
Int(notificationItem.roomInfo.joinedMembersCount)
|
||||
}
|
||||
|
||||
|
||||
var isNoisy: Bool {
|
||||
notificationItem.isNoisy ?? false
|
||||
}
|
||||
@@ -69,7 +69,7 @@ struct NotificationItemProxy: NotificationItemProxyProtocol {
|
||||
var hasMention: Bool {
|
||||
notificationItem.hasMention ?? false
|
||||
}
|
||||
|
||||
|
||||
var senderAvatarMediaSource: MediaSourceProxy? {
|
||||
if let senderAvatarURLString = notificationItem.senderInfo.avatarUrl,
|
||||
let senderAvatarURL = URL(string: senderAvatarURLString) {
|
||||
@@ -77,7 +77,7 @@ struct NotificationItemProxy: NotificationItemProxyProtocol {
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
|
||||
var roomAvatarMediaSource: MediaSourceProxy? {
|
||||
if let roomAvatarURLString = notificationItem.roomInfo.avatarUrl,
|
||||
let roomAvatarURL = URL(string: roomAvatarURLString) {
|
||||
@@ -93,19 +93,19 @@ struct NotificationItemProxy: NotificationItemProxyProtocol {
|
||||
|
||||
struct EmptyNotificationItemProxy: NotificationItemProxyProtocol {
|
||||
let eventID: String
|
||||
|
||||
|
||||
var event: NotificationEvent? {
|
||||
nil
|
||||
}
|
||||
|
||||
|
||||
let roomID: String
|
||||
|
||||
|
||||
let receiverID: String
|
||||
|
||||
|
||||
var senderID: String {
|
||||
""
|
||||
}
|
||||
|
||||
|
||||
var senderDisplayName: String? {
|
||||
nil
|
||||
}
|
||||
@@ -113,11 +113,11 @@ struct EmptyNotificationItemProxy: NotificationItemProxyProtocol {
|
||||
var roomDisplayName: String {
|
||||
""
|
||||
}
|
||||
|
||||
|
||||
var isNoisy: Bool {
|
||||
false
|
||||
}
|
||||
|
||||
|
||||
var isRoomSpace: Bool {
|
||||
false
|
||||
}
|
||||
@@ -133,15 +133,15 @@ struct EmptyNotificationItemProxy: NotificationItemProxyProtocol {
|
||||
var isRoomPrivate: Bool {
|
||||
false
|
||||
}
|
||||
|
||||
|
||||
var senderAvatarMediaSource: MediaSourceProxy? {
|
||||
nil
|
||||
}
|
||||
|
||||
|
||||
var roomAvatarMediaSource: MediaSourceProxy? {
|
||||
nil
|
||||
}
|
||||
|
||||
|
||||
var roomJoinedMembers: Int {
|
||||
0
|
||||
}
|
||||
|
||||
@@ -15,31 +15,31 @@ protocol NotificationItemProxyProtocol {
|
||||
var event: NotificationEvent? { get }
|
||||
|
||||
var senderID: String { get }
|
||||
|
||||
|
||||
var roomID: String { get }
|
||||
|
||||
|
||||
var receiverID: String { get }
|
||||
|
||||
|
||||
var senderDisplayName: String? { get }
|
||||
|
||||
|
||||
var senderAvatarMediaSource: MediaSourceProxy? { get }
|
||||
|
||||
|
||||
var roomDisplayName: String { get }
|
||||
|
||||
|
||||
var roomAvatarMediaSource: MediaSourceProxy? { get }
|
||||
|
||||
|
||||
var roomJoinedMembers: Int { get }
|
||||
|
||||
var isRoomSpace: Bool { get }
|
||||
|
||||
|
||||
var isRoomDirect: Bool { get }
|
||||
|
||||
var isRoomPrivate: Bool { get }
|
||||
|
||||
var isDM: Bool { get }
|
||||
|
||||
|
||||
var isNoisy: Bool { get }
|
||||
|
||||
|
||||
var hasMention: Bool { get }
|
||||
|
||||
var threadRootEventID: String? { get }
|
||||
|
||||
@@ -53,11 +53,11 @@ final class NotificationServiceExtension: UNNotificationServiceExtension {
|
||||
|
||||
actor NotificationServiceExtensionActor {
|
||||
static let receivedWhileOfflineNotificationID = "io.element.elementx.receivedWhileOfflineNotification"
|
||||
|
||||
|
||||
/// Process-wide target configuration, `Mutex`-protected so it can be read/written from any
|
||||
/// thread (in particular, from the actor's synchronous `init` without spawning a Task).
|
||||
private static let targetConfiguration = Mutex<Target.ConfigurationResult?>(nil)
|
||||
|
||||
|
||||
@MainActor
|
||||
private static var hasHandledFirstNotificationSinceBoot = false
|
||||
|
||||
@@ -72,7 +72,7 @@ actor NotificationServiceExtensionActor {
|
||||
private nonisolated(unsafe) var notificationHandler: NotificationHandler?
|
||||
private let keychainController = KeychainController(service: .sessions,
|
||||
accessGroup: InfoPlistReader.main.keychainAccessGroupIdentifier)
|
||||
|
||||
|
||||
deinit {
|
||||
ExtensionLogger.logMemory(with: tag)
|
||||
MXLog.info("\(tag) deinit")
|
||||
@@ -86,7 +86,7 @@ actor NotificationServiceExtensionActor {
|
||||
|
||||
appHooks = AppHooks()
|
||||
appHooks.setUp()
|
||||
|
||||
|
||||
// If the device is still locked then we can't write to the app group container and
|
||||
// the target configuration will fail. We could call exit(0) here, however with the
|
||||
// notification filtering entitlement that results in the notification being discarded
|
||||
@@ -260,13 +260,13 @@ actor NotificationServiceExtensionActor {
|
||||
content.body = L10n.notificationReceivedWhileOfflineIos
|
||||
content.badge = originalRequest.content.unreadCount as NSNumber?
|
||||
content.sound = settings.notificationSound
|
||||
|
||||
|
||||
let request = UNNotificationRequest(identifier: Self.receivedWhileOfflineNotificationID, content: content, trigger: nil)
|
||||
UNUserNotificationCenter.current().add(request)
|
||||
}
|
||||
|
||||
// MARK: - Logging
|
||||
|
||||
|
||||
private nonisolated var tag: String {
|
||||
"[NSE][\(Unmanaged.passUnretained(self).toOpaque())][\(Unmanaged.passUnretained(Thread.current).toOpaque())][\(ProcessInfo.processInfo.processIdentifier)]"
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user