mirror of
https://github.com/hanzoai/forum.git
synced 2026-09-30 21:51:19 +00:00
Applies the autofix, which caught a few places that were missed in the original find/replace See https://github.com/discourse/lint-configs/pull/91
49 lines
1.1 KiB
JavaScript
49 lines
1.1 KiB
JavaScript
import { cancel, debounce } from "@ember/runloop";
|
|
import Service, { service } from "@ember/service";
|
|
import { isTesting } from "discourse/lib/environment";
|
|
|
|
const KEEP_ALIVE = 10 * 1000; // 10 seconds
|
|
|
|
export default class ComposerPresenceManager extends Service {
|
|
@service currentUser;
|
|
@service presence;
|
|
@service siteSettings;
|
|
|
|
notifyState(name, replying = true, keepAlive = KEEP_ALIVE) {
|
|
if (!replying) {
|
|
this.leave();
|
|
return;
|
|
}
|
|
|
|
const canHideProfile = this.siteSettings.allow_users_to_hide_profile;
|
|
const isHidingPresence = this.currentUser.user_option.hide_presence;
|
|
|
|
if (canHideProfile && isHidingPresence) {
|
|
return;
|
|
}
|
|
|
|
if (this._name !== name) {
|
|
this.leave();
|
|
|
|
this._name = name;
|
|
this._channel = this.presence.getChannel(name);
|
|
this._channel.enter();
|
|
|
|
if (!isTesting()) {
|
|
this._autoLeaveTimer = debounce(this, this.leave, keepAlive);
|
|
}
|
|
}
|
|
}
|
|
|
|
leave() {
|
|
if (this._autoLeaveTimer) {
|
|
cancel(this._autoLeaveTimer);
|
|
this._autoLeaveTimer = null;
|
|
}
|
|
|
|
this._channel?.leave();
|
|
this._channel = null;
|
|
this._name = null;
|
|
}
|
|
}
|