Skip to content

Commit e426ab5

Browse files
committed
feat(push_notification_client): add PushNotificationResult and update method return types
- Introduce PushNotificationResult class to encapsulate the result of bulk push notification send operations - Update sendNotification and sendBulkNotifications methods to return PushNotificationResult instead of void - These changes allow for better error handling and cleanup of invalid device tokens
1 parent 6709962 commit e426ab5

File tree

1 file changed

+30
-2
lines changed

1 file changed

+30
-2
lines changed

lib/src/services/push_notification_client.dart

Lines changed: 30 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,32 @@
11
import 'package:core/core.dart';
2+
import 'package:equatable/equatable.dart';
3+
import 'package:meta/meta.dart';
4+
5+
/// {@template push_notification_result}
6+
/// Encapsulates the result of a bulk push notification send operation.
7+
///
8+
/// This class provides structured feedback on which notifications were sent
9+
/// successfully and which ones failed, including the specific device tokens
10+
/// for each category. This is crucial for implementing self-healing mechanisms,
11+
/// such as cleaning up invalid or unregistered device tokens from the database.
12+
/// {@endtemplate}
13+
@immutable
14+
class PushNotificationResult extends Equatable {
15+
/// {@macro push_notification_result}
16+
const PushNotificationResult({
17+
this.sentTokens = const [],
18+
this.failedTokens = const [],
19+
});
20+
21+
/// A list of device tokens to which the notification was successfully sent.
22+
final List<String> sentTokens;
23+
24+
/// A list of device tokens to which the notification failed to be sent.
25+
final List<String> failedTokens;
26+
27+
@override
28+
List<Object> get props => [sentTokens, failedTokens];
29+
}
230

331
/// An abstract interface for push notification clients.
432
///
@@ -9,7 +37,7 @@ abstract class IPushNotificationClient {
937
///
1038
/// [deviceToken]: The unique token identifying the target device.
1139
/// [payload]: The data payload to be sent with the notification.
12-
Future<void> sendNotification({
40+
Future<PushNotificationResult> sendNotification({
1341
required String deviceToken,
1442
required PushNotificationPayload payload,
1543
});
@@ -21,7 +49,7 @@ abstract class IPushNotificationClient {
2149
///
2250
/// [deviceTokens]: A list of unique tokens identifying the target devices.
2351
/// [payload]: The data payload to be sent with the notification.
24-
Future<void> sendBulkNotifications({
52+
Future<PushNotificationResult> sendBulkNotifications({
2553
required List<String> deviceTokens,
2654
required PushNotificationPayload payload,
2755
});

0 commit comments

Comments
 (0)