Files
Jarek RadoszandGitHub 88a7c980cf DEV: Minor refactor of chat models (#27467)
* remove default prop values where they're being set in constructor
* replace some `||` operators in constructors with `??` so the fallback boolean values are actually used
2024-06-13 17:07:31 +02:00

36 lines
797 B
JavaScript

import { tracked } from "@glimmer/tracking";
import { TrackedArray } from "@ember-compat/tracked-built-ins";
import User from "discourse/models/user";
export const REACTIONS = { add: "add", remove: "remove" };
export default class ChatMessageReaction {
static create(args = {}) {
return new ChatMessageReaction(args);
}
@tracked count;
@tracked reacted;
@tracked users;
@tracked emoji;
constructor(args = {}) {
this.count = args.count;
this.emoji = args.emoji;
this.reacted = args.reacted;
this.users = this.#initUsersModels(args.users);
}
#initUsersModels(users = []) {
return new TrackedArray(
users.map((user) => {
if (user instanceof User) {
return user;
}
return User.create(user);
})
);
}
}