Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

DEV: lib/user-presence improvements #15046

Merged
merged 2 commits into from Nov 25, 2021
Merged

DEV: lib/user-presence improvements #15046

merged 2 commits into from Nov 25, 2021

Conversation

davidtaylorhq
Copy link
Member

@davidtaylorhq davidtaylorhq commented Nov 22, 2021

  • 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 browserUnseenTime 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)

- 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`
@@ -119,6 +119,10 @@ export function setTestPresence(value) {
testPresence = value;
}

export function clearPresenceCallbacks() {
callbacks.splice(0, callbacks.length);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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

@davidtaylorhq davidtaylorhq merged commit fd93d6f into main Nov 25, 2021
@davidtaylorhq davidtaylorhq deleted the user-presence-lib branch November 25, 2021 12:07
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
2 participants