Class PwaNotificationService

java.lang.Object
io.meeds.pwa.service.PwaNotificationService

@Service public class PwaNotificationService extends Object
  • Field Details

    • PROOF_PARAM

      public static final String PROOF_PARAM
      See Also:
    • TIMESTAMP_PARAM

      public static final String TIMESTAMP_PARAM
      See Also:
    • SUBSCRIPTION_ID_PARAM

      public static final String SUBSCRIPTION_ID_PARAM
      See Also:
    • PUSH_TOKEN_PARAM

      public static final String PUSH_TOKEN_PARAM
      See Also:
    • PWA_NOTIFICATION_CREATED

      public static final String PWA_NOTIFICATION_CREATED
      See Also:
    • PWA_NOTIFICATION_RECEIVED

      public static final String PWA_NOTIFICATION_RECEIVED
      See Also:
    • PWA_NOTIFICATION_OPEN_UI_ACTION

      public static final String PWA_NOTIFICATION_OPEN_UI_ACTION
      See Also:
    • PWA_NOTIFICATION_MARK_READ_USER_ACTION

      public static final String PWA_NOTIFICATION_MARK_READ_USER_ACTION
      See Also:
    • PWA_NOTIFICATION_MARK_READ_ACTION_LABEL

      public static final String PWA_NOTIFICATION_MARK_READ_ACTION_LABEL
      See Also:
    • PWA_NOTIFICATION_PUSH_DELAY_TIME

      public static final String PWA_NOTIFICATION_PUSH_DELAY_TIME
      See Also:
    • PWA_NOTIFICATION_PUSH_EFFECTIVE_RECEIVED_TIME

      public static final String PWA_NOTIFICATION_PUSH_EFFECTIVE_RECEIVED_TIME
      See Also:
    • PWA_NOTIFICATION_PUSH_RECEIVED_TIME

      public static final String PWA_NOTIFICATION_PUSH_RECEIVED_TIME
      See Also:
    • PWA_NOTIFICATION_PUSH_SENT_TIME

      public static final String PWA_NOTIFICATION_PUSH_SENT_TIME
      See Also:
    • EVENT_NOTIFICATION_SENT

      public static final String EVENT_NOTIFICATION_SENT
      See Also:
    • EVENT_NOTIFICATION_RESPONSE_ERROR

      public static final String EVENT_NOTIFICATION_RESPONSE_ERROR
      See Also:
    • EVENT_NOTIFICATION_SENDING_ERROR

      public static final String EVENT_NOTIFICATION_SENDING_ERROR
      See Also:
    • EVENT_OUTDATED_SUBSCRIPTION

      public static final String EVENT_OUTDATED_SUBSCRIPTION
      See Also:
    • EVENT_ERROR_PARAM_NAME

      public static final String EVENT_ERROR_PARAM_NAME
      See Also:
    • EVENT_SUBSCRIPTION_PARAM_NAME

      public static final String EVENT_SUBSCRIPTION_PARAM_NAME
      See Also:
    • EVENT_HTTP_RESPONSE_PARAM_NAME

      public static final String EVENT_HTTP_RESPONSE_PARAM_NAME
      See Also:
    • EVENT_NOTIFICATION_ID_PARAM_NAME

      public static final String EVENT_NOTIFICATION_ID_PARAM_NAME
      See Also:
    • EVENT_ACTION_PARAM_NAME

      public static final String EVENT_ACTION_PARAM_NAME
      See Also:
    • EVENT_NOTIFICATION_TYPE_PARAM_NAME

      public static final String EVENT_NOTIFICATION_TYPE_PARAM_NAME
      See Also:
    • WEB_NOTIFICATION

      public static final String WEB_NOTIFICATION
      See Also:
    • DIRECT_NOTIFICATION

      public static final String 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

      public static final String DIRECT_KIND_DATA
      See Also:
    • DIRECT_OBJECT_ID_DATA

      public static final String DIRECT_OBJECT_ID_DATA
      See Also:
    • DIRECT_TOKEN_DATA

      public static final String DIRECT_TOKEN_DATA
      See Also:
    • DIRECT_SUBSCRIPTION_ID_DATA

      public static final String DIRECT_SUBSCRIPTION_ID_DATA
      See Also:
    • DIRECT_CLIENT_ACTION_DATA

      public static final String DIRECT_CLIENT_ACTION_DATA
      Optional data key 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 on document where a platform event name would collide (detail = the notification data) instead of navigating it — the page keeps its state. A listener owning the action calls preventDefault(); unclaimed, DIRECT_CLIENT_ACTION_URL_DATA is 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

      public static final String DIRECT_CLIENT_ACTION_URL_DATA
      Optional data key of a direct notification carrying a DIRECT_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

      public static final String EVENT_USERNAME_PARAM_NAME
      See Also:
    • EVENT_DURATION_PARAM_NAME

      public static final String EVENT_DURATION_PARAM_NAME
      See Also:
    • EVENT_NOTIFICATION_TOKEN_PARAM_NAME

      public static final String EVENT_NOTIFICATION_TOKEN_PARAM_NAME
      See Also:
    • EVENT_SUBSCRIPTION_ID_PARAM_NAME

      public static final String 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.ObjectNotFoundException
      IllegalAccessException
    • getNotificationFromPush

      public PwaNotificationMessage getNotificationFromPush(long webNotificationId, String authorizationHeader, String username) throws org.exoplatform.commons.exception.ObjectNotFoundException, IllegalAccessException
      Throws:
      org.exoplatform.commons.exception.ObjectNotFoundException
      IllegalAccessException
    • updateNotificationFromPush

      public void updateNotificationFromPush(long webNotificationId, String action, String authorizationHeader, String username) throws org.exoplatform.commons.exception.ObjectNotFoundException, IllegalAccessException
      Throws:
      org.exoplatform.commons.exception.ObjectNotFoundException
      IllegalAccessException
    • reportPushDeliveryDelay

      public void reportPushDeliveryDelay(long webNotificationId, String authorizationHeader, String username, long sentAt, long receivedAt) throws IllegalAccessException, org.exoplatform.commons.exception.ObjectNotFoundException
      Throws:
      IllegalAccessException
      org.exoplatform.commons.exception.ObjectNotFoundException
    • getPushDeliveryDelayStatus

      public Map<String,Object> getPushDeliveryDelayStatus(String username, String subscriptionId)
    • resetPushDeliveryDelay

      public void resetPushDeliveryDelay(String username, String subscriptionId)
    • getBadge

      public Map<String,Object> getBadge(String username)
    • updateNotification

      public void updateNotification(long webNotificationId, String action, String username) throws org.exoplatform.commons.exception.ObjectNotFoundException, IllegalAccessException
      Throws:
      org.exoplatform.commons.exception.ObjectNotFoundException
      IllegalAccessException
    • create

      public ScheduledFuture<?> create(long webNotificationId)
      Send a Push Notification to display to user device(s)
      Parameters:
      webNotificationId -
    • create

      public ScheduledFuture<?> create(Map<String,Object> params)
      Send a Push Notification to display to user device(s)
      Parameters:
      params -
    • getVapidPublicKeyString

      public String getVapidPublicKeyString()
      Returns:
      VAPID Public Key encoded using Base64url
    • excludePluginFromPush

      public void excludePluginFromPush(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. Any domain can register its plugin here.
      Parameters:
      pluginId - the NotificationInfo plugin id to exclude
    • isPluginExcludedFromPush

      public boolean isPluginExcludedFromPush(String pluginId)
    • canReceiveDirectNotifications

      public boolean canReceiveDirectNotifications(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).
      Parameters:
      username - recipient platform username
      notificationKind - 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, else defaultDelaySeconds). A null build 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 through PwaDirectNotificationBuilder.onSendFailure(String, PwaNotificationMessage). The rendered notification travels inside the encrypted push payload: displaying it requires no session and no fetch.
      Parameters:
      username - recipient platform username
      notificationKind - caller-chosen key of the per-device settings (e.g. "chat")
      defaultDelaySeconds - delay when the device defines none
      messageBuilder - produces the notification at fire time per device, or null to cancel that device's send. An actionable notification (with actions) must set tag to the key of the object the actions target: the per-device action token is scoped to kind:tag and the action plugin receives that key as the only trusted target. A DIRECT_CLIENT_ACTION_DATA entry in data makes 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: ContainerTransactional binds 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, IllegalAccessException
      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.
      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 - the PWA-Notification header
      Throws:
      org.exoplatform.commons.exception.ObjectNotFoundException - from the plugin
      IllegalAccessException - when the device cannot be authenticated or the plugin refuses the action
    • sendCreateNotification

      public int sendCreateNotification(Long webNotificationId)
    • setDefaultNotificationMessageProperties

      public void setDefaultNotificationMessageProperties(PwaNotificationMessage notificationMessage, String notificationId, org.exoplatform.services.resources.LocaleConfig localeConfig)
    • getLocaleConfig

      public org.exoplatform.services.resources.LocaleConfig getLocaleConfig(String username)