Package io.meeds.pwa.service
Class PwaNotificationService
java.lang.Object
io.meeds.pwa.service.PwaNotificationService
-
Field Summary
FieldsModifier and TypeFieldDescriptionstatic final StringOptionaldatakey of a direct notification: the name of a DOM event the service worker asks the focused app page to dispatch on click — name it<addon>-<action>-from-push, since it is dispatched ondocumentwhere a platform event name would collide (detail = the notification data) instead of navigating it — the page keeps its state.static final StringOptionaldatakey of a direct notification carrying aDIRECT_CLIENT_ACTION_DATA: the url to follow when an app page is open but does not act in place (it never answered, or it did not own the action).static final Stringstatic final StringPush payload type whose content is the rendered notification itself (JSON), displayed by the service worker with no server fetch — usable by any domain that needs a push without a stored web notification.static final Stringstatic final Stringstatic final Stringstatic final Stringstatic final Stringstatic final Stringstatic final Stringstatic final Stringstatic final Stringstatic final Stringstatic final Stringstatic final Stringstatic final Stringstatic final Stringstatic final Stringstatic final Stringstatic final Stringstatic final Stringstatic final Stringstatic final Stringstatic final Stringstatic final Stringstatic final Stringstatic final Stringstatic final Stringstatic final Stringstatic final Stringstatic final Stringstatic final Stringstatic final Stringstatic final String -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionbooleancanReceiveDirectNotifications(String username, String notificationKind) Whether a direct notification of a kind scheduled for this user can reach at least one device right now — lets callers skip buffering content that could never fire (PWA disabled, no subscribed device, or the kind disabled on every device).create(long webNotificationId) Send a Push Notification to display to user device(s)Send a Push Notification to display to user device(s)voiddestroy()voidexcludePluginFromPush(String pluginId) Excludes a stored web-notification plugin from push delivery: its notifications keep their on-site and mail channels untouched, but never produce a push popup.voidfireDirectNotification(String username, String subscriptionId, String notificationKind, PwaDirectNotificationBuilder messageBuilder) Runs on the scheduler thread:ContainerTransactionalbinds the portal container so the subscription storage is readable there.org.exoplatform.services.resources.LocaleConfiggetLocaleConfig(String username) getNotification(long webNotificationId, String username) getNotificationFromPush(long webNotificationId, String authorizationHeader, String username) getPushDeliveryDelayStatus(String username, String subscriptionId) voidhandleDirectNotificationAction(String notificationKind, String action, Map<String, String> data, String authorizationHeader) Handles a quick action triggered on a direct notification from a device without a session: authenticates the device through its token and HMAC proof, then dispatches to the plugin of the notification kind.voidinit()booleanisPluginExcludedFromPush(String pluginId) voidreportPushDeliveryDelay(long webNotificationId, String authorizationHeader, String username, long sentAt, long receivedAt) voidresetPushDeliveryDelay(String username, String subscriptionId) voidscheduleDirectNotification(String username, String notificationKind, long defaultDelaySeconds, PwaDirectNotificationBuilder messageBuilder) Schedules, for each subscribed device of a user, a self-contained push whose content is produced at fire time by the given builder — once per device, with the device's subscription id, so the caller can keep per-device state (e.g.intsendCreateNotification(Long webNotificationId) voidsetDefaultNotificationMessageProperties(PwaNotificationMessage notificationMessage, String notificationId, org.exoplatform.services.resources.LocaleConfig localeConfig) voidupdateNotification(long webNotificationId, String action, String username) voidupdateNotificationFromPush(long webNotificationId, String action, String authorizationHeader, String username)
-
Field Details
-
PROOF_PARAM
- See Also:
-
TIMESTAMP_PARAM
- See Also:
-
SUBSCRIPTION_ID_PARAM
- See Also:
-
PUSH_TOKEN_PARAM
- See Also:
-
PWA_NOTIFICATION_CREATED
- See Also:
-
PWA_NOTIFICATION_RECEIVED
- See Also:
-
PWA_NOTIFICATION_OPEN_UI_ACTION
- See Also:
-
PWA_NOTIFICATION_MARK_READ_USER_ACTION
- See Also:
-
PWA_NOTIFICATION_MARK_READ_ACTION_LABEL
- See Also:
-
PWA_NOTIFICATION_PUSH_DELAY_TIME
- See Also:
-
PWA_NOTIFICATION_PUSH_EFFECTIVE_RECEIVED_TIME
- See Also:
-
PWA_NOTIFICATION_PUSH_RECEIVED_TIME
- See Also:
-
PWA_NOTIFICATION_PUSH_SENT_TIME
- See Also:
-
EVENT_NOTIFICATION_SENT
- See Also:
-
EVENT_NOTIFICATION_RESPONSE_ERROR
- See Also:
-
EVENT_NOTIFICATION_SENDING_ERROR
- See Also:
-
EVENT_OUTDATED_SUBSCRIPTION
- See Also:
-
EVENT_ERROR_PARAM_NAME
- See Also:
-
EVENT_SUBSCRIPTION_PARAM_NAME
- See Also:
-
EVENT_HTTP_RESPONSE_PARAM_NAME
- See Also:
-
EVENT_NOTIFICATION_ID_PARAM_NAME
- See Also:
-
EVENT_ACTION_PARAM_NAME
- See Also:
-
EVENT_NOTIFICATION_TYPE_PARAM_NAME
- See Also:
-
WEB_NOTIFICATION
- See Also:
-
DIRECT_NOTIFICATION
Push payload type whose content is the rendered notification itself (JSON), displayed by the service worker with no server fetch — usable by any domain that needs a push without a stored web notification.- See Also:
-
DIRECT_KIND_DATA
- See Also:
-
DIRECT_OBJECT_ID_DATA
- See Also:
-
DIRECT_TOKEN_DATA
- See Also:
-
DIRECT_SUBSCRIPTION_ID_DATA
- See Also:
-
DIRECT_CLIENT_ACTION_DATA
Optionaldatakey of a direct notification: the name of a DOM event the service worker asks the focused app page to dispatch on click — name it<addon>-<action>-from-push, since it is dispatched ondocumentwhere a platform event name would collide (detail = the notification data) instead of navigating it — the page keeps its state. A listener owning the action callspreventDefault(); unclaimed,DIRECT_CLIENT_ACTION_URL_DATAis followed when the payload carries one, else the notification url — as it is when no app page is open. That same url is handed to the page in the action message, for a listener that owns the action and then cannot carry it out.- See Also:
-
DIRECT_CLIENT_ACTION_URL_DATA
Optionaldatakey of a direct notification carrying aDIRECT_CLIENT_ACTION_DATA: the url to follow when an app page is open but does not act in place (it never answered, or it did not own the action). It stands for what the in-page action would have done, where the notification url only opens the app; with no app page open at all, the notification url is followed as usual. An absolute path of this origin, which the service worker prefixes with the origin as it does the notification url, and drops when it is shaped otherwise.- See Also:
-
EVENT_USERNAME_PARAM_NAME
- See Also:
-
EVENT_DURATION_PARAM_NAME
- See Also:
-
EVENT_NOTIFICATION_TOKEN_PARAM_NAME
- See Also:
-
EVENT_SUBSCRIPTION_ID_PARAM_NAME
- See Also:
-
-
Constructor Details
-
PwaNotificationService
public PwaNotificationService()
-
-
Method Details
-
init
@PostConstruct public void init() -
destroy
@PreDestroy public void destroy() -
getNotification
public PwaNotificationMessage getNotification(long webNotificationId, String username) throws org.exoplatform.commons.exception.ObjectNotFoundException, IllegalAccessException - Throws:
org.exoplatform.commons.exception.ObjectNotFoundExceptionIllegalAccessException
-
getNotificationFromPush
public PwaNotificationMessage getNotificationFromPush(long webNotificationId, String authorizationHeader, String username) throws org.exoplatform.commons.exception.ObjectNotFoundException, IllegalAccessException - Throws:
org.exoplatform.commons.exception.ObjectNotFoundExceptionIllegalAccessException
-
updateNotificationFromPush
public void updateNotificationFromPush(long webNotificationId, String action, String authorizationHeader, String username) throws org.exoplatform.commons.exception.ObjectNotFoundException, IllegalAccessException - Throws:
org.exoplatform.commons.exception.ObjectNotFoundExceptionIllegalAccessException
-
reportPushDeliveryDelay
public void reportPushDeliveryDelay(long webNotificationId, String authorizationHeader, String username, long sentAt, long receivedAt) throws IllegalAccessException, org.exoplatform.commons.exception.ObjectNotFoundException - Throws:
IllegalAccessExceptionorg.exoplatform.commons.exception.ObjectNotFoundException
-
getPushDeliveryDelayStatus
-
resetPushDeliveryDelay
-
getBadge
-
updateNotification
public void updateNotification(long webNotificationId, String action, String username) throws org.exoplatform.commons.exception.ObjectNotFoundException, IllegalAccessException - Throws:
org.exoplatform.commons.exception.ObjectNotFoundExceptionIllegalAccessException
-
create
Send a Push Notification to display to user device(s)- Parameters:
webNotificationId-
-
create
Send a Push Notification to display to user device(s)- Parameters:
params-
-
getVapidPublicKeyString
- Returns:
- VAPID Public Key encoded using Base64url
-
excludePluginFromPush
Excludes a stored web-notification plugin from push delivery: its notifications keep their on-site and mail channels untouched, but never produce a push popup. Any domain can register its plugin here.- Parameters:
pluginId- theNotificationInfoplugin id to exclude
-
isPluginExcludedFromPush
-
canReceiveDirectNotifications
Whether a direct notification of a kind scheduled for this user can reach at least one device right now — lets callers skip buffering content that could never fire (PWA disabled, no subscribed device, or the kind disabled on every device).- Parameters:
username- recipient platform usernamenotificationKind- the direct-notification kind (e.g. "chat")- Returns:
- true when PWA is enabled and at least one subscribed device has the kind enabled
-
scheduleDirectNotification
public void scheduleDirectNotification(String username, String notificationKind, long defaultDelaySeconds, PwaDirectNotificationBuilder messageBuilder) Schedules, for each subscribed device of a user, a self-contained push whose content is produced at fire time by the given builder — once per device, with the device's subscription id, so the caller can keep per-device state (e.g. a per-device "already popped" watermark). A device fires after its own delay (per-device setting when defined, elsedefaultDelaySeconds). Anullbuild cancels the send for that device — the caller's guard (e.g. "already read") decides at fire time, not at schedule time; a failed send reports back throughPwaDirectNotificationBuilder.onSendFailure(String, PwaNotificationMessage). The rendered notification travels inside the encrypted push payload: displaying it requires no session and no fetch.- Parameters:
username- recipient platform usernamenotificationKind- caller-chosen key of the per-device settings (e.g. "chat")defaultDelaySeconds- delay when the device defines nonemessageBuilder- produces the notification at fire time per device, or null to cancel that device's send. An actionable notification (withactions) must settagto the key of the object the actions target: the per-device action token is scoped tokind:tagand the action plugin receives that key as the only trusted target. ADIRECT_CLIENT_ACTION_DATAentry indatamakes a click act in the open page rather than navigate it.
-
fireDirectNotification
public void fireDirectNotification(String username, String subscriptionId, String notificationKind, PwaDirectNotificationBuilder messageBuilder) Runs on the scheduler thread:ContainerTransactionalbinds the portal container so the subscription storage is readable there. -
handleDirectNotificationAction
public void handleDirectNotificationAction(String notificationKind, String action, Map<String, String> data, String authorizationHeader) throws org.exoplatform.commons.exception.ObjectNotFoundException, IllegalAccessExceptionHandles a quick action triggered on a direct notification from a device without a session: authenticates the device through its token and HMAC proof, then dispatches to the plugin of the notification kind.- Parameters:
notificationKind- the direct-notification kind (e.g. "chat")action- the action id (e.g. "markRead")data- the notification data as delivered to the device (must carry the object id the token was scoped to)authorizationHeader- thePWA-Notificationheader- Throws:
org.exoplatform.commons.exception.ObjectNotFoundException- from the pluginIllegalAccessException- when the device cannot be authenticated or the plugin refuses the action
-
sendCreateNotification
-
setDefaultNotificationMessageProperties
public void setDefaultNotificationMessageProperties(PwaNotificationMessage notificationMessage, String notificationId, org.exoplatform.services.resources.LocaleConfig localeConfig) -
getLocaleConfig
-