* DEV: Fix the function prototype observers deprecation
DEPRECATION: Function prototype extensions have been deprecated, please migrate from function(){}.observes('foo') to observer('foo', function() {}). [deprecation id: function-prototype-extensions.observes] See https://deprecations.emberjs.com/v3.x/#toc_function-prototype-extensions-observes for more details.
* DEV: Fix the function prototype event listeners deprecation
DEPRECATION: Function prototype extensions have been deprecated, please migrate from function(){}.on('foo') to on('foo', function() {}). [deprecation id: function-prototype-extensions.on] See https://deprecations.emberjs.com/v3.x/#toc_function-prototype-extensions-on for more details.
* DEV: Simplify `default as` imports
Co-authored-by: Joffrey JAFFEUX <j.jaffeux@gmail.com>
60 lines
1.4 KiB
JavaScript
60 lines
1.4 KiB
JavaScript
import { debounce } from "@ember/runloop";
|
|
import { cancel } from "@ember/runloop";
|
|
import Component from "@ember/component";
|
|
import computed, { on } from "ember-addons/ember-computed-decorators";
|
|
import {
|
|
keepAliveDuration,
|
|
bufferTime
|
|
} from "discourse/plugins/discourse-presence/discourse/components/composer-presence-display";
|
|
|
|
const MB_GET_LAST_MESSAGE = -2;
|
|
|
|
export default Component.extend({
|
|
topicId: null,
|
|
presenceUsers: null,
|
|
|
|
clear() {
|
|
if (!this.isDestroyed) this.set("presenceUsers", []);
|
|
},
|
|
|
|
@on("didInsertElement")
|
|
_inserted() {
|
|
this.clear();
|
|
|
|
this.messageBus.subscribe(
|
|
this.channel,
|
|
message => {
|
|
if (!this.isDestroyed) this.set("presenceUsers", message.users);
|
|
this._clearTimer = debounce(
|
|
this,
|
|
"clear",
|
|
keepAliveDuration + bufferTime
|
|
);
|
|
},
|
|
MB_GET_LAST_MESSAGE
|
|
);
|
|
},
|
|
|
|
@on("willDestroyElement")
|
|
_destroyed() {
|
|
cancel(this._clearTimer);
|
|
this.messageBus.unsubscribe(this.channel);
|
|
},
|
|
|
|
@computed("topicId")
|
|
channel(topicId) {
|
|
return `/presence/topic/${topicId}`;
|
|
},
|
|
|
|
@computed("presenceUsers", "currentUser.{id,ignored_users}")
|
|
users(users, currentUser) {
|
|
const ignoredUsers = currentUser.ignored_users || [];
|
|
return (users || []).filter(
|
|
user =>
|
|
user.id !== currentUser.id && !ignoredUsers.includes(user.username)
|
|
);
|
|
},
|
|
|
|
shouldDisplay: Ember.computed.gt("users.length", 0)
|
|
});
|