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

Handle user states #65

Merged
merged 10 commits into from
Jun 20, 2024
Merged

Handle user states #65

merged 10 commits into from
Jun 20, 2024

Conversation

cp-megh-l
Copy link
Collaborator

@cp-megh-l cp-megh-l commented Jun 10, 2024

Summary by CodeRabbit

  • New Features

    • Added automated function to handle stale user data every 30 minutes.
    • Implemented a notification system triggered on document creation to update user states and send notifications.
  • Refactor

    • Simplified functions for updating battery percentage and session state for users.
    • Enhanced read and update conditions in Firestore rules based on authorization and space membership.
  • Bug Fixes

    • Improved logic for handling user notifications based on geofence events.

Copy link

coderabbitai bot commented Jun 10, 2024

Walkthrough

The updates span across three core files aiming to improve data handling, user state notifications, and database rules. The ApiUserService.kt file sees refactored methods for battery percentage and session state updates. The firestore.rules file's conditions have been adjusted to enhance security checks. Finally, functions/index.js introduces scheduled and event-triggered cloud functions for managing stale user data and notifications.

Changes

File Change Summary
data/src/main/java/.../ApiUserService.kt Refactored updateBatteryPct and updateSessionState methods for simplification and efficiency.
firestore.rules Altered read and update conditions for better authorization and membership checks within a space.
functions/index.js Added serviceCheck (a scheduled function) and updateUserStateNotification (triggered on document creation) to handle stale data and notifications.

Sequence Diagram(s)

sequenceDiagram
    participant Scheduler
    participant CloudFunctions
    participant Database

    Scheduler->>CloudFunctions: Triggers serviceCheck every 30 minutes
    CloudFunctions->>Database: Queries for stale user data
    Database-->>CloudFunctions: Returns stale user data
    CloudFunctions->>Database: Processes and updates stale user data

    participant Firestore
    participant RuleCheck

    User->>Firestore: Requests data read/update
    Firestore->>RuleCheck: Verifies isAuthorized() and isSpaceMember()
    RuleCheck-->>Firestore: Authorization result
    Firestore-->>User: Permits or denies access based on validation

    participant NotificationService
    participant GeoFence

    GeoFence->>CloudFunctions: Triggers updateUserStateNotification on document creation
    CloudFunctions->>NotificationService: Checks user state and condition for notifications
    NotificationService->>User: Sends notification if conditions are met
Loading

Recent review details

Configuration used: CodeRabbit UI
Review profile: CHILL

Commits

Files that changed from the base of the PR and between ab801e2 and de643c3.

Files selected for processing (1)
  • functions/index.js (2 hunks)
Additional context used
Biome
functions/index.js

[error] 272-274: This else clause can be omitted because previous branches break early. (lint/style/noUselessElse)

Unsafe fix: Omit the else clause.


Thank you for using CodeRabbit. We offer it for free to the OSS community and would appreciate your support in helping us grow. If you find it useful, would you consider giving us a shout-out on your favorite social media?

Share
Tips

Chat

There are 3 ways to chat with CodeRabbit:

‼️ IMPORTANT
Auto-reply has been disabled for this repository in the CodeRabbit settings. The CodeRabbit bot will not respond to your replies unless it is explicitly tagged.

  • Files and specific lines of code (under the "Files changed" tab): Tag @coderabbitai in a new review comment at the desired location with your query. Examples:
    • @coderabbitai generate unit testing code for this file.
    • @coderabbitai modularize this function.
  • PR comments: Tag @coderabbitai in a new PR comment to ask questions about the PR branch. For the best results, please provide a very specific query, as very limited context is provided in this mode. Examples:
    • @coderabbitai generate interesting stats about this repository and render them as a table.
    • @coderabbitai show all the console.log statements in this repository.
    • @coderabbitai read src/utils.ts and generate unit testing code.
    • @coderabbitai read the files in the src/scheduler package and generate a class diagram using mermaid and a README in the markdown format.
    • @coderabbitai help me debug CodeRabbit configuration file.

Note: Be mindful of the bot's finite context window. It's strongly recommended to break down tasks such as reading entire modules into smaller chunks. For a focused discussion, use review comments to chat about specific files and their changes, instead of using the PR comments.

CodeRabbit Commands (invoked as PR comments)

  • @coderabbitai pause to pause the reviews on a PR.
  • @coderabbitai resume to resume the paused reviews.
  • @coderabbitai review to trigger an incremental review. This is useful when automatic reviews are disabled for the repository.
  • @coderabbitai full review to do a full review from scratch and review all the files again.
  • @coderabbitai summary to regenerate the summary of the PR.
  • @coderabbitai resolve resolve all the CodeRabbit review comments.
  • @coderabbitai configuration to show the current CodeRabbit configuration for the repository.
  • @coderabbitai help to get help.

Additionally, you can add @coderabbitai ignore anywhere in the PR description to prevent this PR from being reviewed.

CodeRabbit Configration File (.coderabbit.yaml)

  • You can programmatically configure CodeRabbit by adding a .coderabbit.yaml file to the root of your repository.
  • Please see the configuration documentation for more information.
  • If your editor has YAML language server enabled, you can add the path at the top of this file to enable auto-completion and validation: # yaml-language-server: $schema=https://coderabbit.ai/integrations/schema.v2.json

Documentation and Community

  • Visit our Documentation for detailed information on how to use CodeRabbit.
  • Join our Discord Community to get help, request features, and share feedback.
  • Follow us on X/Twitter for updates and announcements.

Copy link

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

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

Actionable comments posted: 5

Outside diff range and nitpick comments (4)
app/src/main/java/com/canopas/yourspace/domain/utils/ContextExt.kt (1)

22-33: The update to use NetworkCapabilities is a good improvement for network connectivity checks, enhancing reliability and future-proofing the code.

Consider adding a comment explaining why NetworkCapabilities is used over NetworkInfo based on the Android version, which could help in future maintenance.

app/src/main/java/com/canopas/yourspace/ui/component/UserBatteryStatus.kt (1)

16-24: Updated the function to use ApiUser instead of ApiUserSession, aligning with the new user management strategy.

Consider adding a comment explaining the change from session to user to clarify the context for future developers.

data/src/main/java/com/canopas/yourspace/data/models/user/ApiUser.kt (1)

25-40: Added new fields state, battery_pct, and updated_at to the ApiUser class to enhance user state management.

Consider documenting these new fields in the class to explain their usage and impact, which could be beneficial for future developers and API consumers.

data/src/main/java/com/canopas/yourspace/data/service/auth/AuthService.kt (1)

124-125: Optimized the updateUserSessionState function to avoid unnecessary updates by checking if the current state matches the new state.

Consider adding a comment explaining why this check is important, as it helps in understanding the logic and avoiding redundant operations.

Copy link

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

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

Actionable comments posted: 3

Copy link

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

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

Actionable comments posted: 5

functions/index.js Show resolved Hide resolved
functions/index.js Show resolved Hide resolved
functions/index.js Show resolved Hide resolved
functions/index.js Show resolved Hide resolved
functions/index.js Show resolved Hide resolved
@cp-megh-l cp-megh-l merged commit 4c10b9e into main Jun 20, 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.

None yet

2 participants