Skip to content

Commit 9ef0b34

Browse files
committed
fix(notifications): simulate backend behavior in NoOp service
- Align the NoOp service's behavior with the backend architecture - Persist notification in the in-memory repository before emitting the push payload - This change ensures a more accurate simulation of the real push notification process
1 parent f838424 commit 9ef0b34

File tree

1 file changed

+18
-11
lines changed

1 file changed

+18
-11
lines changed

lib/notifications/services/no_op_push_notification_service.dart

Lines changed: 18 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -61,17 +61,24 @@ class NoOpPushNotificationService extends PushNotificationService {
6161
if (environment != AppEnvironment.demo) {
6262
return;
6363
}
64-
Future.delayed(const Duration(seconds: 10), () {
65-
if (_inAppNotificationsFixturesData.isEmpty) return;
66-
67-
// Use the first notification from the fixtures as the simulated push.
68-
final notificationToSimulate = _inAppNotificationsFixturesData.first;
69-
70-
// The AppBloc listens to the `onMessage` stream. When a payload is
71-
// emitted, the BLoC will create a new InAppNotification, save it,
72-
// and update the UI to show the unread indicator.
73-
_onMessageController.add(notificationToSimulate.payload);
74-
});
64+
unawaited(
65+
Future.delayed(const Duration(seconds: 10), () async {
66+
if (_inAppNotificationsFixturesData.isEmpty) return;
67+
68+
// Use the first notification from the fixtures as the simulated push.
69+
final notificationToSimulate = _inAppNotificationsFixturesData.first;
70+
71+
// To align with the backend architecture, this NoOp service
72+
// simulates the backend's behavior: it first persists the notification
73+
// to the in-memory repository, and *then* emits the push payload.
74+
await _inAppNotificationRepository.create(
75+
item: notificationToSimulate,
76+
userId: userId,
77+
);
78+
79+
_onMessageController.add(notificationToSimulate.payload);
80+
}),
81+
);
7582
}
7683

7784
@override

0 commit comments

Comments
 (0)