Class NotificationService

java.lang.Object
com.example.breeze_seas.NotificationService

public class NotificationService extends Object
Handles sending and fetching of notifications to the database. TODO: Add push notifications
  • Constructor Details

    • NotificationService

      public NotificationService()
  • Method Details

    • newNotificationDocument

      @NonNull public com.google.firebase.firestore.DocumentReference newNotificationDocument()
      Returns a fresh notification document reference for callers that need to include a notification write inside a larger Firestore transaction.
      Returns:
      Empty notification document reference in the shared notifications collection.
    • sendNotification

      public com.google.android.gms.tasks.Task<Void> sendNotification(Notification notification)
      Writes the notification to the database.
      Parameters:
      notification - the notification that is sent to the database.
    • buildNotificationData

      @NonNull public Map<String,Object> buildNotificationData(@NonNull Notification notification)
      Builds the shared Firestore payload used for notification documents.
      Parameters:
      notification - Notification being serialized for Firestore.
      Returns:
      Map matching the existing notification collection schema.
    • sendNotification

      public com.google.android.gms.tasks.Task<Void> sendNotification(@NonNull Notification notification, @NonNull com.google.firebase.firestore.DocumentReference documentReference)
      Writes the notification to a caller-provided document reference.
      Parameters:
      notification - Notification being serialized.
      documentReference - Destination notification document.
      Returns:
      Firestore task for the write.
    • getNotifications

      public void getNotifications(String userId, NotificationService.OnNotificationLoadedListener listener)
      Gets the notifications that were meant for a specific user from the database.
      Parameters:
      userId - This user id is for filtering in the query.
      listener - this makes sure that data is actually received by the program.
    • getAllNotifications

      public void getAllNotifications(NotificationService.OnNotificationLoadedListener listener)
      Get all notifications
      Parameters:
      listener - Callback to handle the retrieved data or errors.
    • startNotificationsListen

      public void startNotificationsListen(String userId, NotificationService.OnNotificationLoadedListener listener)
      Starts a realtime listener for one user's inbox.
      Parameters:
      userId - Device identifier for the current user.
      listener - Callback receiving the current inbox snapshot.
    • stopNotificationsListen

      public void stopNotificationsListen()
      Stops the active realtime inbox listener.
    • markNotificationSeen

      public com.google.android.gms.tasks.Task<Void> markNotificationSeen(String notificationId)
      Marks one notification as seen.
      Parameters:
      notificationId - Notification document id.
      Returns:
      Firestore task for the update.