DEV: Fix presence testing in legacy ember environment (#14596)

The legacy testing environment will remove the User.current() value before disposing of controllers/components. Presence often involves making HTTP calls during disposal of components, so this can cause issues.

Production, and the modern Ember-CLI environment, do not require this hack, so it is behind an `isTesting() && isLegacyEmber()` check.
This commit is contained in:
David Taylor 2021-10-13 17:24:19 +01:00 committed by GitHub
parent 74706bab10
commit bc68da24cd
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
1 changed files with 9 additions and 3 deletions

View File

@ -5,7 +5,7 @@ import { ajax } from "discourse/lib/ajax";
import { cancel, debounce, later, next, once, throttle } from "@ember/runloop";
import Session from "discourse/models/session";
import { Promise } from "rsvp";
import { isTesting } from "discourse-common/config/environment";
import { isLegacyEmber, isTesting } from "discourse-common/config/environment";
import User from "discourse/models/user";
const PRESENCE_INTERVAL_S = 30;
@ -464,8 +464,14 @@ export default class PresenceService extends Service {
}
});
} catch (e) {
// Updating server failed. Put the failed events
// back in the queue for next time
if (e.jqXHR?.status === 403 && isTesting() && isLegacyEmber()) {
// Legacy testing environment will remove the User.current() value before disposing of controllers/components.
// Presence often involves making HTTP calls during disposal of components, so this can cause issues.
// Modern Ember-CLI environment does not require this hack
return;
}
// Put the failed events back in the queue for next time
this._queuedEvents.unshift(...queue);
if (e.jqXHR?.status === 429) {
// Rate limited. No need to raise, we'll try again later