DEV: `lib/user-presence` improvements (PR #15046)

  • Remove JQuery
  • Remove legacy document.webkitHidden support. None of our currently supported browsers need this
  • Use passive event listeners. These allows the browser to process the events first, before passing control to us
  • Add a new unseenTime parameter. This allows consumers to request a delay before being notified about the browser going into the background
  • Add a method for removing a callback
  • Fire the callback when presence changes in either direction. Previously it would only fire when the user becomes present after a period of inactivity.
  • Ensure callbacks are only called once for each state change. Previously they would be called every 60s, regardless of the value
  • Listen to the visibilitychanged and focus events, treating them as equivalent to user action. This will make messagebus re-activate more quickly when switching back to a stale tab
  • Add test helpers
  • Delete the unused discourse/lib/page-visible module.
  • Call message-bus’s onVisibilityChange API directly, rather than dispatching a fake event on the document

(I intend to use these new APIs for some PresenceChannel improvements)


Should we need to clear this between tests? Usually it’s a good idea with module local variables like this.

Updated in latest commit

I’ve also done callbacks.length = 0 which works too.