From 276bcba9562e43cf8b4dfc523de0d85d87d87063 Mon Sep 17 00:00:00 2001 From: Elias Nahum Date: Wed, 1 Mar 2023 12:59:07 +0200 Subject: [PATCH] Fix iOS push notification when set as generic message with sender name (#7171) --- ios/NotificationService/NotificationService.swift | 14 +++++++++++--- 1 file changed, 11 insertions(+), 3 deletions(-) diff --git a/ios/NotificationService/NotificationService.swift b/ios/NotificationService/NotificationService.swift index 5ac2d24d4a..8ec1f5d778 100644 --- a/ios/NotificationService/NotificationService.swift +++ b/ios/NotificationService/NotificationService.swift @@ -83,8 +83,9 @@ class NotificationService: UNNotificationServiceExtension { let isCRTEnabled = notification.userInfo["is_crt_enabled"] as? Bool ?? false let rootId = notification.userInfo["root_id"] as? String ?? "" - let channelName = notification.userInfo["channel_name"] as? String ?? "" - let message = (notification.userInfo["message"] as? String ?? "") + let senderName = notification.userInfo["sender_name"] as? String + let channelName = notification.userInfo["channel_name"] as? String + var message = (notification.userInfo["message"] as? String ?? "") let overrideUsername = notification.userInfo["override_username"] as? String let senderId = notification.userInfo["sender_id"] as? String let senderIdentifier = overrideUsername ?? senderId @@ -94,11 +95,18 @@ class NotificationService: UNNotificationServiceExtension { if isCRTEnabled && !rootId.isEmpty { conversationId = rootId } + + if channelName == nil && message == "", + let senderName = senderName, + let body = bestAttemptContent?.body { + message = body.replacingOccurrences(of: "\(senderName) ", with: "") + bestAttemptContent?.body = message + } let handle = INPersonHandle(value: senderIdentifier, type: .unknown) let sender = INPerson(personHandle: handle, nameComponents: nil, - displayName: channelName, + displayName: channelName ?? senderName, image: avatar, contactIdentifier: nil, customIdentifier: nil)