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

30 lines
686 B
JavaScript

import { tracked } from "@glimmer/tracking";
import User from "discourse/models/user";
import { CHATABLE_TYPES } from "discourse/plugins/chat/discourse/models/chat-channel";
export default class ChatDirectMessage {
static create(args = {}) {
return new ChatDirectMessage(args);
}
@tracked users;
@tracked group;
type = CHATABLE_TYPES.directMessageChannel;
constructor(args = {}) {
this.group = args.group ?? false;
this.users = this.#initUsers(args.users || []);
}
#initUsers(users) {
return users.map((user) => {
if (!user || user instanceof User) {
return user;
} else {
return User.create(user);
}
});
}
}