Skip to content

Commit

Permalink
Groups notification updates
Browse files Browse the repository at this point in the history
Updated to handle empty notifications
  • Loading branch information
Alex Risch authored and Alex Risch committed Jun 25, 2024
1 parent 35ce82d commit 32f940b
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 3 deletions.
2 changes: 2 additions & 0 deletions ios/ConverseNotificationExtension/NotificationService.swift
Original file line number Diff line number Diff line change
Expand Up @@ -92,6 +92,8 @@ func handleNotificationAsync(contentHandler: ((UNNotificationContent) -> Void),
incrementBadge(for: content)
contentHandler(content)
} else {
content.title = ""
content.body = ""
cancelNotification(contentHandler: contentHandler)
return
}
Expand Down
1 change: 1 addition & 0 deletions ios/ConverseNotificationExtension/Spam.swift
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
9 changes: 6 additions & 3 deletions ios/ConverseNotificationExtension/Xmtp/Messages.swift
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand All @@ -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
}
Expand All @@ -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)
}
Expand Down

0 comments on commit 32f940b

Please sign in to comment.