Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Added notifications #33

Merged
merged 1 commit into from
Nov 2, 2024
Merged

Added notifications #33

merged 1 commit into from
Nov 2, 2024

Conversation

Abhimanyu-dev
Copy link
Collaborator

@Abhimanyu-dev Abhimanyu-dev commented Oct 29, 2024

Description

Motivation and Context

How Has This Been Tested?

Screenshots (if appropriate):

Types of changes

  • Bug fix (non-breaking change which fixes an issue)
  • New feature (non-breaking change which adds functionality)
  • Breaking change (fix or feature that would cause existing functionality to change)

Checklist:

  • My code follows the code style of this project.
  • My change requires a change to the documentation.
  • I have updated the documentation accordingly.
  • I have added tests to cover my changes.
  • All new and existing tests passed.

Summary by Sourcery

Implement a Firebase-based notification system, including initialization and handling of notifications, and update the Android package configuration.

New Features:

  • Introduce Firebase-based notification system with initialization, registration, and handling of notifications.

Enhancements:

  • Refactor package structure to include Firebase and notification configurations.

Build:

  • Add Firebase and notification-related dependencies to the project.

Deployment:

  • Update Android package name and application label in the manifest file.

Copy link
Contributor

sourcery-ai bot commented Oct 29, 2024

Reviewer's Guide by Sourcery

This PR implements Firebase Cloud Messaging (FCM) and local notifications in the Flutter application. The implementation includes Firebase initialization, notification handling for both foreground and background messages, local storage setup using Hive, and proper Android configuration for notifications.

Sequence diagram for notification handling

sequenceDiagram
    participant User
    participant App
    participant Firebase
    participant LocalStorage
    participant NotificationConfig

    User->>App: Open App
    App->>Firebase: Initialize Firebase
    Firebase-->>App: Initialization Complete
    App->>Firebase: Register Notification
    Firebase-->>App: Notification Token
    App->>Firebase: Check for Initial Message
    Firebase-->>App: Initial Message (if any)
    App->>Firebase: Listen for Notifications
    Firebase-->>App: Notification Received
    App->>NotificationConfig: Show Notification
    NotificationConfig->>LocalStorage: Add Notification to Storage
Loading

Class diagram for Firebase and Notification configuration

classDiagram
    class FirebaseConfig {
        +initialize()
        +listenNotification()
        +checkForInitialMessage()
        +registerNotification()
        +_firebaseMessagingBackgroundHandler()
    }
    class NotificationConfig {
        +initialize()
        +showNotification(RemoteMessage message)
    }
    class LocalStorage {
        +addNotification(notification)
        +getNotifications()
    }
    class Storage {
        +initialize()
    }
    FirebaseConfig --> NotificationConfig : uses
    FirebaseConfig --> LocalStorage : uses
    FirebaseConfig --> Storage : uses
    NotificationConfig --> LocalStorage : uses
Loading

File-Level Changes

Change Details Files
Implemented Firebase initialization and notification handling
  • Added Firebase initialization with platform-specific options
  • Implemented notification permission handling
  • Set up FCM message listeners for foreground and background messages
  • Created notification display configuration with support for image notifications
lib/config/firebase.dart
lib/config/firebase_options.dart
lib/config/notification.dart
Added local storage functionality using Hive
  • Implemented Hive initialization
  • Created methods for storing and retrieving notifications
  • Set up local storage configuration
lib/config/storage.dart
lib/config/localStorage.dart
Updated Android configuration and dependencies
  • Modified package name to com.pclub.attendance
  • Added Firebase configuration file
  • Updated app label
  • Added required dependencies for Firebase, notifications, and Hive
android/app/src/main/AndroidManifest.xml
android/app/src/main/kotlin/com/pclub/attendance/MainActivity.kt
android/app/google-services.json
pubspec.yaml
firebase.json
Modified main application entry point
  • Added initialization calls for Firebase and storage
  • Set up notification listeners
  • Added required imports
lib/main.dart

Tips and commands

Interacting with Sourcery

  • Trigger a new review: Comment @sourcery-ai review on the pull request.
  • Continue discussions: Reply directly to Sourcery's review comments.
  • Generate a GitHub issue from a review comment: Ask Sourcery to create an
    issue from a review comment by replying to it.
  • Generate a pull request title: Write @sourcery-ai anywhere in the pull
    request title to generate a title at any time.
  • Generate a pull request summary: Write @sourcery-ai summary anywhere in
    the pull request body to generate a PR summary at any time. You can also use
    this command to specify where the summary should be inserted.

Customizing Your Experience

Access your dashboard to:

  • Enable or disable review features such as the Sourcery-generated pull request
    summary, the reviewer's guide, and others.
  • Change the review language.
  • Add, remove or edit custom review instructions.
  • Adjust other review settings.

Getting Help

Copy link
Contributor

@sourcery-ai sourcery-ai bot left a comment

Choose a reason for hiding this comment

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

Hey @Abhimanyu-dev - I've reviewed your changes and found some issues that need to be addressed.

Blocking issues:

  • Avoid logging sensitive FCM tokens in production code (link)
  • Hardcoded Firebase API key found. (link)
  • Hardcoded Firebase API key found in google-services.json. (link)

Overall Comments:

  • Please remove sensitive information (API keys, Firebase config) from version control and use environment variables or a secure configuration management system instead.
  • The PR description sections are empty. Please fill out the description, motivation, and testing sections to help reviewers understand the changes.
Here's what I looked at during the review
  • 🟡 General issues: 3 issues found
  • 🔴 Security: 3 blocking issues
  • 🟢 Testing: all looks good
  • 🟢 Complexity: all looks good
  • 🟢 Documentation: all looks good

Sourcery is free for open source - if you like our reviews please consider sharing them ✨
Help me be more useful! Please click 👍 or 👎 on each comment and I'll use the feedback to improve your reviews.

import 'firebase_options.dart';

class FirebaseConfig {
static Future<void> initialize() async {
Copy link
Contributor

Choose a reason for hiding this comment

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

suggestion: Consider adding error handling for Firebase initialization

The initialization could fail for various reasons (network issues, invalid config). Consider wrapping this in a try-catch block and handling potential errors appropriately.

  static Future<void> initialize() async {
    try {
      await Firebase.initializeApp();
    } catch (e) {
      throw FirebaseException(
        plugin: 'firebase_core',
        message: 'Failed to initialize Firebase: $e',
      );
    }

print(status);
}
var messaging = FirebaseMessaging.instance;
print("FCM TOKEN: ${await messaging.getToken()}");
Copy link
Contributor

Choose a reason for hiding this comment

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

🚨 issue (security): Avoid logging sensitive FCM tokens in production code

The FCM token should be treated as sensitive information. Consider removing this log or limiting it to debug builds with more secure logging practices.

);
}

static void listenNotification() {
Copy link
Contributor

Choose a reason for hiding this comment

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

issue: Empty notification listener could miss important events

The empty listener for onMessageOpenedApp means you're not handling notifications when the app is opened from a notification tap.

await flutterLocalNotificationsPlugin.initialize(initializationsSettings);
}

static Future showNotification(RemoteMessage message) async {
Copy link
Contributor

Choose a reason for hiding this comment

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

suggestion: Consider refactoring duplicate notification configuration code

The AndroidNotificationDetails configuration is largely duplicated. Consider extracting common configuration into a separate method.

  static Future<void> showNotification(RemoteMessage message, {AndroidNotificationDetails? androidDetails}) async {

}

static const FirebaseOptions android = FirebaseOptions(
apiKey: 'AIzaSyATmGPGCnhEzncmC9lYhixCTn0jvXrhykA',
Copy link
Contributor

Choose a reason for hiding this comment

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

🚨 issue (security): Hardcoded Firebase API key found.

This Firebase API key is hardcoded in the source code. Consider using environment variables or a secure vault to manage API keys.

"oauth_client": [],
"api_key": [
{
"current_key": "AIzaSyATmGPGCnhEzncmC9lYhixCTn0jvXrhykA"
Copy link
Contributor

Choose a reason for hiding this comment

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

🚨 issue (security): Hardcoded Firebase API key found in google-services.json.

The Firebase API key is present in the google-services.json file. Ensure this file is not exposed publicly and consider using environment variables for sensitive information.

@its-me-yps its-me-yps merged commit 26e3408 into pclubiitk:main Nov 2, 2024
1 check passed
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.

2 participants