FIX: Long poll if window becomes active (#13825)

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.
This commit is contained in:
Bianca Nenciu 2021-07-23 15:52:10 +03:00 committed by GitHub
parent 53082e011a
commit 2c10809244
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 4 additions and 8 deletions

View File

@ -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) {

View File

@ -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