diff --git a/api/openapi.yaml b/api/openapi.yaml index 7bb44f7..fe97f13 100644 --- a/api/openapi.yaml +++ b/api/openapi.yaml @@ -3685,9 +3685,12 @@ components: errors: "" properties: id: - description: Notification identifier when the request created a notification. - An empty string means no notification was created; read `errors` for details - (HTTP may still be 200). + description: "Notification identifier when the request created a notification.\ + \ An empty string means no notification was created; read `errors` for\ + \ details (HTTP may still be 200). All OneSignal server SDKs expose message-sent\ + \ / message-not-sent narrowing helpers (named idiomatically per language\ + \ — e.g. `isMessageSent`, `is_message_sent`, `message_sent?`); prefer\ + \ them over comparing `id` directly." type: string external_id: description: Optional correlation / idempotency-related value from the API diff --git a/docs/CreateNotificationSuccessResponse.md b/docs/CreateNotificationSuccessResponse.md index ff1e64e..1e59d72 100644 --- a/docs/CreateNotificationSuccessResponse.md +++ b/docs/CreateNotificationSuccessResponse.md @@ -7,7 +7,7 @@ | Name | Type | Description | Notes | |------------ | ------------- | ------------- | -------------| -|**id** | **String** | Notification identifier when the request created a notification. An empty string means no notification was created; read `errors` for details (HTTP may still be 200). | [optional] | +|**id** | **String** | Notification identifier when the request created a notification. An empty string means no notification was created; read `errors` for details (HTTP may still be 200). All OneSignal server SDKs expose message-sent / message-not-sent narrowing helpers (named idiomatically per language — e.g. `isMessageSent`, `is_message_sent`, `message_sent?`); prefer them over comparing `id` directly. | [optional] | |**externalId** | **String** | Optional correlation / idempotency-related value from the API response. This is not the end-user External ID used for targeting recipients (that lives under `include_aliases.external_id`). | [optional] | |**errors** | **Object** | Polymorphic field: may be an array of human-readable strings and/or an object (for example with `invalid_aliases`, `invalid_external_user_ids`, or `invalid_player_ids`) depending on the API response; HTTP may still be 200 with partial success. Typed SDKs model this loosely so both shapes deserialize. | [optional] | diff --git a/src/main/java/com/onesignal/client/NotificationHelpers.java b/src/main/java/com/onesignal/client/NotificationHelpers.java index a7b9e8a..1087228 100644 --- a/src/main/java/com/onesignal/client/NotificationHelpers.java +++ b/src/main/java/com/onesignal/client/NotificationHelpers.java @@ -103,6 +103,34 @@ public static CreateNotificationWithRetryResult createNotificationWithRetry(Defa } } + /** + * Whether a POST /notifications 200 response is the "message sent" branch. + * + *
POST /notifications returns 200 in two cases that share the
+ * {@link CreateNotificationSuccessResponse} shape: a notification was
+ * created (non-empty {@code id}), or none was (empty {@code id}, with
+ * {@code errors} carrying the reason). Prefer this guard over inspecting
+ * {@code id} directly.
+ *
+ * @param response a create-notification success response
+ * @return {@code true} when a notification was created
+ */
+ public static boolean isMessageSent(CreateNotificationSuccessResponse response) {
+ return response != null && response.getId() != null && !response.getId().isEmpty();
+ }
+
+ /**
+ * Whether a POST /notifications 200 response is the "message not sent"
+ * branch -- no notification was created ({@code id} absent or empty);
+ * inspect {@code errors} for why.
+ *
+ * @param response a create-notification success response
+ * @return {@code true} when no notification was created
+ */
+ public static boolean isMessageNotSent(CreateNotificationSuccessResponse response) {
+ return !isMessageSent(response);
+ }
+
private static String headerValue(Map