Previous commit 479c0a3051 was done with the assumption that this info was defined on user serializer but it was actually defined on post serializer in core. This commit extends the user serializer for messages to add this data to the user.
Also correctly adds serializer test to ensure we actually have this data.
76 lines
1.6 KiB
JavaScript
76 lines
1.6 KiB
JavaScript
import Component from "@glimmer/component";
|
|
import { prioritizeNameInUx } from "discourse/lib/settings";
|
|
import { inject as service } from "@ember/service";
|
|
import { bind } from "discourse-common/utils/decorators";
|
|
|
|
export default class ChatMessageInfo extends Component {
|
|
@service siteSettings;
|
|
|
|
@bind
|
|
trackStatus() {
|
|
this.#user?.trackStatus?.();
|
|
}
|
|
|
|
@bind
|
|
stopTrackingStatus() {
|
|
this.#user?.stopTrackingStatus?.();
|
|
}
|
|
|
|
get usernameClasses() {
|
|
const user = this.#user;
|
|
|
|
const classes = this.prioritizeName ? ["is-full-name"] : ["is-username"];
|
|
if (!user) {
|
|
return classes;
|
|
}
|
|
if (user.staff) {
|
|
classes.push("is-staff");
|
|
}
|
|
if (user.admin) {
|
|
classes.push("is-admin");
|
|
}
|
|
if (user.moderator) {
|
|
classes.push("is-moderator");
|
|
}
|
|
if (user.new_user) {
|
|
classes.push("is-new-user");
|
|
}
|
|
if (user.primary_group_name) {
|
|
classes.push("group--" + user.primary_group_name);
|
|
}
|
|
return classes.join(" ");
|
|
}
|
|
|
|
get name() {
|
|
return this.prioritizeName
|
|
? this.#user?.get("name")
|
|
: this.#user?.get("username");
|
|
}
|
|
|
|
get isFlagged() {
|
|
return (
|
|
this.#message?.get("reviewable_id") ||
|
|
this.#message?.get("user_flag_status") === 0
|
|
);
|
|
}
|
|
|
|
get prioritizeName() {
|
|
return (
|
|
this.siteSettings.display_name_on_posts &&
|
|
prioritizeNameInUx(this.#user?.get("name"))
|
|
);
|
|
}
|
|
|
|
get showStatus() {
|
|
return !!this.#user?.get("status");
|
|
}
|
|
|
|
get #user() {
|
|
return this.#message?.get("user");
|
|
}
|
|
|
|
get #message() {
|
|
return this.args.message;
|
|
}
|
|
}
|