Skip to content

Commit 9b6f046

Browse files
committed
feat(app): check for unread notifications on app start
- Add logic to count unread notifications when the app starts - Update state to reflect unread notifications status - Implement error handling for notification count retrieval
1 parent 14e4224 commit 9b6f046

File tree

1 file changed

+18
-0
lines changed

1 file changed

+18
-0
lines changed

lib/app/bloc/app_bloc.dart

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -138,6 +138,24 @@ class AppBloc extends Bloc<AppEvent, AppState> {
138138
// If a user is already logged in when the app starts, register their
139139
// device for push notifications.
140140
if (state.user != null) {
141+
// Check for existing unread notifications on startup.
142+
// This ensures the notification dot is shown correctly if the user
143+
// has unread notifications from a previous session.
144+
try {
145+
final unreadCount = await _inAppNotificationRepository.count(
146+
userId: state.user!.id,
147+
filter: {'readAt': null},
148+
);
149+
if (unreadCount > 0) {
150+
emit(state.copyWith(hasUnreadInAppNotifications: true));
151+
}
152+
} catch (e, s) {
153+
_logger.severe(
154+
'Failed to check for unread notifications on app start.',
155+
e,
156+
s,
157+
);
158+
}
141159
await _registerDeviceForPushNotifications(state.user!.id);
142160
}
143161
}

0 commit comments

Comments
 (0)