From 32f940b8c2682a011fa8392b9121a00cfe4018b6 Mon Sep 17 00:00:00 2001 From: Alex Risch Date: Tue, 25 Jun 2024 16:59:56 -0600 Subject: [PATCH] Groups notification updates Updated to handle empty notifications --- .../NotificationService.swift | 2 ++ ios/ConverseNotificationExtension/Spam.swift | 1 + ios/ConverseNotificationExtension/Xmtp/Messages.swift | 9 ++++++--- 3 files changed, 9 insertions(+), 3 deletions(-) diff --git a/ios/ConverseNotificationExtension/NotificationService.swift b/ios/ConverseNotificationExtension/NotificationService.swift index 255d66428..a117c20dd 100644 --- a/ios/ConverseNotificationExtension/NotificationService.swift +++ b/ios/ConverseNotificationExtension/NotificationService.swift @@ -92,6 +92,8 @@ func handleNotificationAsync(contentHandler: ((UNNotificationContent) -> Void), incrementBadge(for: content) contentHandler(content) } else { + content.title = "" + content.body = "" cancelNotification(contentHandler: contentHandler) return } diff --git a/ios/ConverseNotificationExtension/Spam.swift b/ios/ConverseNotificationExtension/Spam.swift index 6415fdf1f..75874cabe 100644 --- a/ios/ConverseNotificationExtension/Spam.swift +++ b/ios/ConverseNotificationExtension/Spam.swift @@ -114,6 +114,7 @@ func computeSpamScoreGroupWelcome(client: XMTP.Client, group: XMTP.Group) async func computeSpamScoreGroupMessage(client: XMTP.Client, group: XMTP.Group, decodedMessage: DecodedMessage, apiURI: String?) async -> Double { var senderSpamScore: Double = 0 do { + try await client.contacts.refreshConsentList() let groupDenied = await client.contacts.isGroupDenied(groupId: group.id) if groupDenied { diff --git a/ios/ConverseNotificationExtension/Xmtp/Messages.swift b/ios/ConverseNotificationExtension/Xmtp/Messages.swift index cf4eeb292..b1b0ac591 100644 --- a/ios/ConverseNotificationExtension/Xmtp/Messages.swift +++ b/ios/ConverseNotificationExtension/Xmtp/Messages.swift @@ -130,8 +130,8 @@ func handleGroupWelcome(xmtpClient: XMTP.Client, apiURI: String?, pushToken: Str } } } catch { - sentryTrackError(error: error, extras: ["message": "NOTIFICATION_SAVE_MESSAGE_ERROR_2", "topic": conversation.topic]) - print("[NotificationExtension] Error fetching messages: \(error)") + sentryTrackError(error: error, extras: ["message": "NOTIFICATION_SAVE_MESSAGE_ERROR_3", "topic": conversation.topic]) + print("[NotificationExtension] Error handling group invites: \(error)") } return (shouldShowNotification, messageId) @@ -155,6 +155,7 @@ func handleGroupMessage(xmtpClient: XMTP.Client, envelope: XMTP.Envelope, apiURI let spamScore = await computeSpamScoreGroupMessage(client: xmtpClient, group: group, decodedMessage: decodedMessage, apiURI: apiURI) if spamScore < 0 { // Message is going to main inbox + shouldShowNotification = true if let groupName = try? group.groupName() { bestAttemptContent.title = groupName } @@ -170,7 +171,9 @@ func handleGroupMessage(xmtpClient: XMTP.Client, envelope: XMTP.Envelope, apiURI } } } catch { - + sentryTrackError(error: error, extras: ["message": "NOTIFICATION_SAVE_MESSAGE_ERROR_4", "topic": contentTopic]) + print("[NotificationExtension] Error handling group message: \(error)") + } return (shouldShowNotification, messageId) }