Skip to content

Commit

Permalink
FIX: Long poll if window becomes active (#13825)
Browse files Browse the repository at this point in the history
This commit fixes two bugs. The first one is that onPresenceChange was
called with invalid arguments and it did not register a callback. The
second bug is that it triggered the wrong visibilitychange event. The
function it tried to call does not exist in all versions of MessageBus.
It is safer to trigger an event instead because that exists in all
versions.
  • Loading branch information
nbianca committed Jul 23, 2021
1 parent 53082e0 commit 2c10809
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 8 deletions.
Expand Up @@ -56,11 +56,7 @@ export default {
// When 20 minutes pass we stop long polling due to "shouldLongPollCallback".
onPresenceChange({
unseenTime: LONG_POLL_AFTER_UNSEEN_TIME,
callback: () => {
if (messageBus.onVisibilityChange) {
messageBus.onVisibilityChange();
}
},
callback: () => document.dispatchEvent(new Event("visibilitychange")),
});

if (siteSettings.login_required && !user) {
Expand Down
6 changes: 3 additions & 3 deletions app/assets/javascripts/discourse/app/lib/user-presence.js
Expand Up @@ -44,11 +44,11 @@ export function seenUser() {
}

// register a callback for cases where presence changed
export function onPresenceChange(maxUnseenTime, callback) {
if (maxUnseenTime < MIN_DELTA) {
export function onPresenceChange({ unseenTime, callback }) {
if (unseenTime < MIN_DELTA) {
throw "unseenTime is too short";
}
callbacks.push({ unseenTime: maxUnseenTime, callback: callback });
callbacks.push({ unseenTime, callback });
}

// We could piggieback on the Scroll mixin, but it is not applied
Expand Down

0 comments on commit 2c10809

Please sign in to comment.