Class WebNotificationApplicationBadgePlugin

java.lang.Object
io.meeds.appcenter.plugin.WebNotificationApplicationBadgePlugin
All Implemented Interfaces:
ApplicationBadgePlugin

@Component public class WebNotificationApplicationBadgePlugin extends Object implements ApplicationBadgePlugin
Reports the notification centre counter on its Application Center tile.

Reuses WebNotificationService.getNumberOnBadge(String) — the very value topbarNotification.jsp renders on the topbar bell — so the tile and the bell are two views of one number and can never disagree. Note this is deliberately not an unread count: it counts what the user has not yet seen, and is reset wholesale when they open the drawer, exactly as the bell behaves today.

Unlike the other contributors, this plugin lives in App Center rather than in the addon owning the data: notifications live in commons, which sits below App Center in the dependency tree, so it cannot depend back on the badge SPI.

  • Field Details

  • Constructor Details

    • WebNotificationApplicationBadgePlugin

      public WebNotificationApplicationBadgePlugin()
  • Method Details

    • init

      @PostConstruct public void init()
    • getName

      public String getName()
      Specified by:
      getName in interface ApplicationBadgePlugin
      Returns:
      the stable identifier of this badge, e.g. agendaPendingInvitations. It is what an administrator binds to a catalog entry, and what travels on the WebSocket frame — so it must never change once released.
    • getDrawerNames

      public List<String> getDrawerNames()
      Description copied from interface: ApplicationBadgePlugin
      A badge may legitimately belong to several catalog entries — an application and its timeline or dashboard variant report the same counter — so several urls may be declared.
      Specified by:
      getDrawerNames in interface ApplicationBadgePlugin
      Returns:
      the url of every catalog entry of type DRAWER this badge belongs to, so that the binding resolves with no administrator action, empty when none
    • isSelfCached

      public boolean isSelfCached()
      The notification domain already caches this counter — with single-flight, through CachedWebNotificationStorage's FutureExoCache — and invalidates it on every notification change. Caching it a second time in App Center would be two caches over one value with independent eviction, which is precisely the stale-badge pattern the design rejects.
      Specified by:
      isSelfCached in interface ApplicationBadgePlugin
      Returns:
      true to bypass the App Center badge cache
    • countBadge

      public long countBadge(String username)
      Description copied from interface: ApplicationBadgePlugin
      Counts the items this badge reports for one user. Called on the read path, so it must be cheap — or the plugin must declare itself ApplicationBadgePlugin.isSelfCached() and do its own caching.
      Specified by:
      countBadge in interface ApplicationBadgePlugin
      Parameters:
      username - the user the count is computed for
      Returns:
      the number of items to display, 0 to hide the badge