Class PNAction

All Implemented Interfaces:
EventListener, IGProp<GProp<?>[]>, IPropCnr, Cloneable

public class PNAction extends PropCnr
One push notification action, i.e. one entry of the actions array of the browser showNotification(title,options) call, modelled as properties rather than as JSON.

Every field of a web notification action is a string, so this container holds four optional StringProp children and nothing else:

  • ACTION - the identifier the service worker matches on (event.action === this). It is a string, never an integer.
  • TITLE - the button label.
  • ICON - an optional icon URL.
  • NAVIGATE - an optional URL to navigate to instead of firing notificationclick.

The number of actions a platform will display is small and platform-dependent (typically at most two; see Notification.maxActions), which is why the whole actions array is cheap to model as a couple of tiny containers instead of as JSON in a string.

JS-facing. This container streams to the JavaScript client, so its leaves are restricted to the closed set of property classes that have a JavaScript reconstructor. StringProp is in that set; a custom value property would not be, and must never appear here. The container itself needs no new JavaScript class - it is reconstructed by the generic PropCnr JavaScript, which is what the jsclient="PropCnr" registration in base-properties.xml selects.

Actions are a first-class use case, not decoration: a notification may carry buttons the client acts on, in-session directly or through the service worker on tap. They pass through intact and are never stripped.

Author:
Christopher Mindus
  • Field Details

  • Constructor Details

    • PNAction

      public PNAction()
      Creates a push notification action container without name and with a null value.
    • PNAction

      public PNAction(Atom propertyAtom)
      Creates a push notification action container with the specified name with a null value.
      Parameters:
      propertyAtom - The property atom.
  • Method Details

    • clone

      public PNAction clone()
      Creates a clone out of this property.
      Overrides:
      clone in class PropCnr
      Returns:
      The clone of the push notification action.
    • getAction

      public String getAction()
      Gets the service-worker action identifier, i.e. the string the service worker's notificationclick handler compares event.action against.
      Returns:
      The action identifier, or null when not set.
    • setAction

      public boolean setAction(String action)
      Sets the service-worker action identifier.
      Parameters:
      action - The action identifier.
      Returns:
      true when this property container has been changed, false otherwise.
    • getTitle

      public String getTitle()
      Gets the button label.
      Returns:
      The button label, or null when not set.
    • setTitle

      public boolean setTitle(String title)
      Sets the button label.
      Parameters:
      title - The button label.
      Returns:
      true when this property container has been changed, false otherwise.
    • getIcon

      public String getIcon()
      Gets the icon URL.
      Returns:
      The icon URL, or null when not set.
    • setIcon

      public boolean setIcon(String icon)
      Sets the icon URL.
      Parameters:
      icon - The icon URL.
      Returns:
      true when this property container has been changed, false otherwise.
    • getNavigate

      public String getNavigate()
      Gets the navigation URL used instead of firing notificationclick.
      Returns:
      The navigation URL, or null when not set.
    • setNavigate

      public boolean setNavigate(String navigate)
      Sets the navigation URL used instead of firing notificationclick.
      Parameters:
      navigate - The navigation URL.
      Returns:
      true when this property container has been changed, false otherwise.