Skip to content

Conversation

@WizCoderr
Copy link
Contributor

@WizCoderr WizCoderr commented Oct 28, 2025

Fixes - Jira-#Issue_Number

Didn't create a Jira ticket, click here to create new.

Please Add Screenshots If there are any UI changes.

Before After

Please make sure these boxes are checked before submitting your pull request - thanks!

  • Run the static analysis check ./gradlew check or ci-prepush.sh to make sure you didn't break anything

  • If you have multiple commits please combine them into one commit by squashing them.

Summary by CodeRabbit

  • New Features
    • Added a notification screen enabling users to view and manage their notifications.
    • Implemented dismiss functionality to remove individual notifications.
    • Added pull-to-refresh capability to manually update the notification list.
    • Integrated network availability detection for improved offline handling.
    • Notifications are automatically organized by read status and timestamp for better visibility.

@coderabbitai
Copy link

coderabbitai bot commented Oct 28, 2025

Walkthrough

A notification feature module was implemented comprising three main components: a composable-based UI screen with breakdown into content and item components, a ViewModel extending the base class with notification management flows (load, refresh, dismiss) and network monitoring, and navigation helpers to integrate the screen into the app's navigation graph.

Changes

Cohort / File(s) Summary
UI Components
feature/notification/src/commonMain/kotlin/org/mifos/mobile/feature/notification/NotificationScreen.kt
Added public entry-point composable with delegation to private overload. Introduced private composables: NotificationContent for pull-to-refresh and list rendering, and NotificationItem for individual notification rows with read/unread state and dismiss action.
ViewModel & State Management
feature/notification/src/commonMain/kotlin/org/mifos/mobile/feature/notification/NotificationViewModel.kt
Extended ViewModel base class. Added initialization side-effect for cleanup and loading. Implemented loadNotifications() and refreshNotifications() flows with state branching (Loading, Success, Error, Empty). Added dismissNotification() method with local and repository updates. Exposed isNetworkAvailable observable via NetworkMonitor.
Navigation
feature/notification/src/commonMain/kotlin/org/mifos/mobile/feature/notification/navigation/NotificationNavigation.kt
Added NavController.navigateToNotificationScreen() extension for programmatic navigation. Added NavGraphBuilder.notificationDestination() extension to register the screen in the navigation graph with push transition support.

Sequence Diagram(s)

sequenceDiagram
    participant UI as NotificationScreen
    participant VM as NotificationViewModel
    participant Repo as NotificationRepository
    participant Net as NetworkMonitor

    UI->>VM: observe isNetworkAvailable
    Net-->>VM: network status
    VM-->>UI: emit network state

    UI->>UI: onCompose
    VM->>VM: init{deleteOldNotifications()}
    VM->>VM: loadNotifications()
    VM->>Repo: loadNotifications()
    Repo-->>VM: DataState<List>
    VM->>VM: sortNotifications()
    VM-->>UI: emit Success(sorted list)

    UI->>VM: onRefresh()
    VM->>VM: refreshNotifications()
    VM-->>UI: emit isRefreshing=true
    VM->>Repo: loadNotifications()
    Repo-->>VM: DataState<List>
    VM-->>UI: emit isRefreshing=false

    UI->>VM: dismissNotification(notification)
    VM->>Repo: update read status
    Repo-->>VM: confirmation
    VM-->>UI: emit updated list
Loading

Estimated code review effort

🎯 3 (Moderate) | ⏱️ ~20 minutes

  • Areas requiring attention:
    • ViewModel initialization logic and flow ordering (deleteOldNotifications → loadNotifications chain)
    • NotificationUiState branching logic and error handling in loadNotifications flow
    • Notification sorting strategy and read/unread state management
    • Network availability integration with UI error/retry states
    • Navigation graph integration and composable transition setup

Poem

🐰 A hop through notifications bright,
Where screens and flows dance day and night,
Dismiss old troubles, refresh the feed,
Network status guides our deed,
Clean scaffolds stand with grace untold,
A feature feature, smooth and bold! ✨

Pre-merge checks and finishing touches

❌ Failed checks (1 warning)
Check name Status Explanation Resolution
Title Check ⚠️ Warning The pull request title states "chore(docs): Code Documentation for feature/notification module," which suggests this is a documentation-focused change. However, the actual changeset contains substantial functional code implementation, including new composable functions in NotificationScreen.kt (NotificationContent, NotificationItem), public methods in NotificationViewModel.kt (loadNotifications, refreshNotifications, dismissNotification, isNetworkAvailable), and navigation helper extensions in NotificationNavigation.kt. These are feature implementation changes, not documentation updates, making the title misleading regarding the true nature of the changeset. Update the PR title to accurately reflect the functional changes, such as "feat(notification): Implement NotificationScreen composables and ViewModel logic" or "feat(notification): Add notification UI and state management implementation." This would better represent the actual implementation of notification features rather than documentation updates, allowing reviewers to understand the true scope of the changes.
✅ Passed checks (2 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Docstring Coverage ✅ Passed Docstring coverage is 80.00% which is sufficient. The required threshold is 80.00%.
✨ Finishing touches
  • 📝 Generate docstrings
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Post copyable unit tests in a comment

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

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: 1

Caution

Some comments are outside the diff and can’t be posted inline due to platform limitations.

⚠️ Outside diff range comments (2)
feature/notification/src/commonMain/kotlin/org/mifos/mobile/feature/notification/NotificationScreen.kt (2)

203-203: Fix: rememberSaveable needs a key to prevent state misassignment.

The rememberSaveable call doesn't provide a key, so saved state is keyed by composition position (the item's index in the LazyColumn). When notifications are reordered (e.g., after sorting unread first) or the list changes, the saved isRead state can be restored for the wrong notification, showing incorrect read/unread status.

Option 1 (Quick fix): Add a key parameter:

-    val isRead = rememberSaveable { mutableStateOf(notification.isRead()) }
+    val isRead = rememberSaveable(key = notification.id.toString()) { 
+        mutableStateOf(notification.isRead()) 
+    }

Option 2 (Recommended): Remove local state entirely and derive it directly from the notification object, since the ViewModel already tracks read status:

-    val isRead = rememberSaveable { mutableStateOf(notification.isRead()) }
+    val isRead = remember(notification) { notification.isRead() }

Then update the dismiss logic:

-            if (!isRead.value) {
+            if (!isRead) {
                 MifosTextButton(
                     content = {
                         Text(stringResource(Res.string.dialog_action_ok))
                     },
                     onClick = {
-                        isRead.value = true
                         dismissNotification(notification)
                     },
                 )
             }

Note: With Option 2, the button won't immediately hide when clicked (it will wait for the state to update via the ViewModel). If immediate UI feedback is desired, keep the mutable state but add the key parameter (Option 1).


237-240: I need to investigate further. The key finding is that updateReadStatus is completely commented out. Let me gather more context:

I need to locate the dismissNotification function and understand the full context. Let me run a final verification script:

Fix non-functional repository implementation and add error handling for dismiss action.

The dismissNotification call on line 239 has two critical issues:

  1. Non-functional implementation: The updateReadStatus method in NotificationRepositoryImp is completely commented out, so dismissing a notification never persists to the database.

  2. Missing error handling: Suspend functions should use try-catch blocks to handle exceptions. The optimistic UI update (line 238) occurs before the async call with no error handling. If the repository operation fails, the notification appears dismissed locally but remains in the database, creating a stale state.

Required actions:

  • Uncomment or complete the updateReadStatus implementation in core/data/src/commonMain/kotlin/org/mifos/mobile/core/data/repositoryImpl/NotificationRepositoryImp.kt
  • Wrap the dismiss operation in try-catch to store previous state and rollback the UI update if the operation fails
🧹 Nitpick comments (1)
feature/notification/src/commonMain/kotlin/org/mifos/mobile/feature/notification/NotificationViewModel.kt (1)

80-82: Optional: Remove no-op DataState.Loading branch.

Line 81 evaluates to Loading but doesn't update _notificationUiState. Since the state was already set to Loading on line 67, this branch is a no-op and could be removed for clarity.

                         is DataState.Error -> {
                             _notificationUiState.value =
                                 NotificationUiState.Error(notifications.message)
                         }
-                        DataState.Loading -> {
-                            Loading
-                        }
                         is DataState.Success -> {
                             _isRefreshing.emit(false)
📜 Review details

Configuration used: CodeRabbit UI

Review profile: CHILL

Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 70c39c6 and 575549d.

📒 Files selected for processing (3)
  • feature/notification/src/commonMain/kotlin/org/mifos/mobile/feature/notification/NotificationScreen.kt (4 hunks)
  • feature/notification/src/commonMain/kotlin/org/mifos/mobile/feature/notification/NotificationViewModel.kt (4 hunks)
  • feature/notification/src/commonMain/kotlin/org/mifos/mobile/feature/notification/navigation/NotificationNavigation.kt (1 hunks)
🔇 Additional comments (8)
feature/notification/src/commonMain/kotlin/org/mifos/mobile/feature/notification/NotificationScreen.kt (3)

54-82: Documentation and implementation look good!

The entry point composable is well-documented and correctly delegates to the private overload after collecting state from the ViewModel.


84-147: Well-structured state handling!

The documentation clearly explains the UI states, and the implementation correctly handles all variants of NotificationUiState with appropriate components.


149-188: Pull-to-refresh implementation is correct!

The documentation accurately describes the refresh functionality, and the implementation properly uses PullToRefreshBox with LazyColumn.

feature/notification/src/commonMain/kotlin/org/mifos/mobile/feature/notification/navigation/NotificationNavigation.kt (1)

21-49: Excellent navigation documentation!

All navigation components are well-documented and follow standard patterns. The route definition, navigation function, and destination builder are all correctly implemented.

feature/notification/src/commonMain/kotlin/org/mifos/mobile/feature/notification/NotificationViewModel.kt (4)

26-60: Well-documented ViewModel initialization!

The class documentation is comprehensive, and the initialization logic correctly deletes old notifications before loading current ones. The network monitoring setup with stateIn is also appropriate.


96-102: Clean refresh implementation!

The refresh function is well-documented and correctly implemented with the refreshing state management.


115-126: Perfect sorting implementation!

The documentation clearly describes the sorting logic (unread first, then most recent), and the implementation correctly uses compareByDescending with thenByDescending.


129-154: Comprehensive UI state documentation!

All UI state variants are well-documented with clear descriptions of when each state is used and what data they contain.

@niyajali niyajali changed the title Documentation done for feature/notification chore(docs): Code Documentation for feature/notification module Oct 28, 2025
Copy link
Collaborator

@niyajali niyajali left a comment

Choose a reason for hiding this comment

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

@WizCoderr Please adhere to conventional commit guidelines (https://www.conventionalcommits.org/en/v1.0.0/) for your commits and PR title, and craft KDoc documentation in a professional, human-like style using AI.

@WizCoderr
Copy link
Contributor Author

it is done

@WizCoderr WizCoderr changed the title chore(docs): Code Documentation for feature/notification module Code Documentation for feature/notification module Oct 28, 2025
@WizCoderr WizCoderr requested a review from niyajali October 28, 2025 16:49
@niyajali
Copy link
Collaborator

@WizCoderr Why you've changed the PR title?

@niyajali niyajali changed the title Code Documentation for feature/notification module chore(docs): Code Documentation for feature/notification module Oct 28, 2025
@niyajali
Copy link
Collaborator

niyajali commented Oct 28, 2025

And rewrite all the KDoc comment in human and professional manner, tell the AI to write like this

@WizCoderr WizCoderr closed this Oct 30, 2025
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