Skip to content

Conversation

leojaygoogle
Copy link

Copy link

Summary of Changes

Hello @leojaygoogle, I'm Gemini Code Assist1! I'm currently reviewing this pull request and will post my feedback shortly. In the meantime, here's a summary to help you and other reviewers quickly get up to speed!

This pull request enhances the MessagingExampleSwift application by incorporating a Notification Service Extension. This addition allows the app to leverage advanced push notification features, specifically enabling the display of rich media like images directly within notifications. Furthermore, it sets up the necessary infrastructure to automatically export FCM delivery data to Google BigQuery, providing comprehensive analytics on message delivery and engagement.

Highlights

  • Notification Service Extension: Introduced a new Notification Service Extension to the MessagingExampleSwift application.
  • Rich Notifications: Enabled support for displaying images within push notifications.
  • FCM BigQuery Export: Integrated functionality to export Firebase Cloud Messaging (FCM) delivery metrics to BigQuery.
Using Gemini Code Assist

The full guide for Gemini Code Assist can be found on our documentation page, here are some quick tips.

Invoking Gemini

You can request assistance from Gemini at any point by creating a comment using either /gemini <command> or @gemini-code-assist <command>. Below is a summary of the supported commands on the current page.

Feature Command Description
Code Review /gemini review Performs a code review for the current pull request in its current state.
Pull Request Summary /gemini summary Provides a summary of the current pull request in its current state.
Comment @gemini-code-assist Responds in comments when explicitly tagged, both in pull request comments and review comments.
Help /gemini help Displays a list of available commands.

Customization

To customize Gemini Code Assist for GitHub experience, repository maintainers can create a configuration file and/or provide a custom code review style guide (such as PEP-8 for Python) by creating and adding files to a .gemini/ folder in the base of the repository. Detailed instructions can be found here.

Limitations & Feedback

Gemini Code Assist may make mistakes. Please leave feedback on any instances where its feedback is incorrect or counter productive. You can react with 👍 and 👎 on @gemini-code-assist comments. If you're interested in giving your feedback about your experience with Gemini Code Assist for Github and other Google products, sign up here.

You can also get AI-powered code generation, chat, as well as code reviews directly in the IDE at no cost with the Gemini Code Assist IDE Extension.

Footnotes

  1. Review the Privacy Notices, Generative AI Prohibited Use Policy, Terms of Service, and learn how to configure Gemini Code Assist in GitHub here. Gemini can make mistakes, so double check it and use code with caution.

Copy link

@gemini-code-assist gemini-code-assist bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Code Review

This pull request successfully adds a Notification Service Extension to the MessagingExampleSwift project, enabling support for rich notifications with images and exporting delivery metrics to BigQuery. The implementation is solid, but I have a couple of suggestions to improve the code's robustness and remove a redundant call. My feedback focuses on making the new NotificationService more resilient to potential failures and cleaning up the AppDelegate.

Comment on lines +75 to +76
print("Call exportDeliveryMetricsToBigQuery() from AppDelegate")
Messaging.serviceExtension().exportDeliveryMetricsToBigQuery(withMessageInfo: userInfo)

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

medium

This call to exportDeliveryMetricsToBigQuery(withMessageInfo:) appears to be redundant. Since you've implemented a NotificationServiceExtension which also calls this method, this one in the AppDelegate is not needed and should be removed. According to the Firebase documentation, this method should be called from the service extension if one exists; otherwise, it should be called from the AppDelegate. Having it in both places could lead to duplicated metrics.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Comment on lines +11 to +26
self.contentHandler = contentHandler
bestAttemptContent = (request.content.mutableCopy() as? UNMutableNotificationContent)

if let bestAttemptContent = bestAttemptContent {
// Modify the notification content here...
bestAttemptContent.title = "\(bestAttemptContent.title) [modified]"

// Log Delivery signals and export to BigQuery.
print("Call exportDeliveryMetricsToBigQuery() from NotificationService")
Messaging.serviceExtension()
.exportDeliveryMetricsToBigQuery(withMessageInfo: request.content.userInfo)

// Add image, call this last to finish with the content handler.
Messaging.serviceExtension()
.populateNotificationContent(bestAttemptContent, withContentHandler: contentHandler)
}

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

medium

The implementation in didReceive can be made more robust. If request.content.mutableCopy() fails and returns nil, the current code implicitly relies on a timeout to deliver the original notification. It's better practice to handle this case explicitly. Using a guard let statement to safely unwrap the mutable content and calling the contentHandler with the original content in the else block would make the code more robust and easier to read.

Suggested change
self.contentHandler = contentHandler
bestAttemptContent = (request.content.mutableCopy() as? UNMutableNotificationContent)
if let bestAttemptContent = bestAttemptContent {
// Modify the notification content here...
bestAttemptContent.title = "\(bestAttemptContent.title) [modified]"
// Log Delivery signals and export to BigQuery.
print("Call exportDeliveryMetricsToBigQuery() from NotificationService")
Messaging.serviceExtension()
.exportDeliveryMetricsToBigQuery(withMessageInfo: request.content.userInfo)
// Add image, call this last to finish with the content handler.
Messaging.serviceExtension()
.populateNotificationContent(bestAttemptContent, withContentHandler: contentHandler)
}
self.contentHandler = contentHandler
guard let bestAttemptContent = (request.content.mutableCopy() as? UNMutableNotificationContent) else {
// If we're unable to create a mutable copy, deliver the original content.
contentHandler(request.content)
return
}
self.bestAttemptContent = bestAttemptContent
// Modify the notification content here...
bestAttemptContent.title = "\(bestAttemptContent.title) [modified]"
// Log Delivery signals and export to BigQuery.
print("Call exportDeliveryMetricsToBigQuery() from NotificationService")
Messaging.serviceExtension()
.exportDeliveryMetricsToBigQuery(withMessageInfo: request.content.userInfo)
// Add image, call this last to finish with the content handler.
Messaging.serviceExtension()
.populateNotificationContent(bestAttemptContent, withContentHandler: contentHandler)

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It's very unlikely that request.content.mutableCopy() returns nil. I'd like to keep the example app simple.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant