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
This commit is contained in:
parent
b289351a3f
commit
fe00796027
|
@ -59,17 +59,17 @@ export default class ChatChannel {
|
|||
@tracked slug;
|
||||
@tracked description;
|
||||
@tracked status;
|
||||
@tracked activeThread = null;
|
||||
@tracked activeThread;
|
||||
@tracked meta;
|
||||
@tracked chatableId;
|
||||
@tracked chatableType;
|
||||
@tracked chatableUrl;
|
||||
@tracked autoJoinUsers = false;
|
||||
@tracked allowChannelWideMentions = true;
|
||||
@tracked membershipsCount = 0;
|
||||
@tracked autoJoinUsers;
|
||||
@tracked allowChannelWideMentions;
|
||||
@tracked membershipsCount;
|
||||
@tracked archive;
|
||||
@tracked tracking;
|
||||
@tracked threadingEnabled = false;
|
||||
@tracked threadingEnabled;
|
||||
@tracked draft;
|
||||
|
||||
threadsManager = new ChatThreadsManager(getOwnerWithFallback(this));
|
||||
|
@ -91,16 +91,16 @@ export default class ChatChannel {
|
|||
this.threadingEnabled = args.threading_enabled;
|
||||
this.autoJoinUsers = args.auto_join_users;
|
||||
this.allowChannelWideMentions = args.allow_channel_wide_mentions;
|
||||
this.chatable = this.#initChatable(args.chatable || []);
|
||||
this.currentUserMembership = args.current_user_membership;
|
||||
this.lastMessage = args.last_message;
|
||||
this.meta = args.meta;
|
||||
|
||||
this.chatable = this.#initChatable(args.chatable ?? []);
|
||||
this.tracking = new ChatTrackingState(getOwnerWithFallback(this));
|
||||
|
||||
if (args.archive_completed || args.archive_failed) {
|
||||
this.archive = ChatChannelArchive.create(args);
|
||||
}
|
||||
|
||||
this.tracking = new ChatTrackingState(getOwnerWithFallback(this));
|
||||
this.lastMessage = args.last_message;
|
||||
this.meta = args.meta;
|
||||
}
|
||||
|
||||
get unreadThreadsCountSinceLastViewed() {
|
||||
|
|
|
@ -7,8 +7,8 @@ export default class ChatDirectMessage {
|
|||
return new ChatDirectMessage(args);
|
||||
}
|
||||
|
||||
@tracked users = null;
|
||||
@tracked group = false;
|
||||
@tracked users;
|
||||
@tracked group;
|
||||
|
||||
type = CHATABLE_TYPES.directMessageChannel;
|
||||
|
||||
|
|
|
@ -9,16 +9,16 @@ export default class ChatMessageReaction {
|
|||
return new ChatMessageReaction(args);
|
||||
}
|
||||
|
||||
@tracked count = 0;
|
||||
@tracked reacted = false;
|
||||
@tracked users = [];
|
||||
@tracked count;
|
||||
@tracked reacted;
|
||||
@tracked users;
|
||||
@tracked emoji;
|
||||
|
||||
constructor(args = {}) {
|
||||
this.count = args.count;
|
||||
this.emoji = args.emoji;
|
||||
this.users = this.#initUsersModels(args.users);
|
||||
this.reacted = args.reacted;
|
||||
this.users = this.#initUsersModels(args.users);
|
||||
}
|
||||
|
||||
#initUsersModels(users = []) {
|
||||
|
|
|
@ -1,5 +1,5 @@
|
|||
import { cached, tracked } from "@glimmer/tracking";
|
||||
import { TrackedArray, TrackedObject } from "@ember-compat/tracked-built-ins";
|
||||
import { TrackedArray } from "@ember-compat/tracked-built-ins";
|
||||
import { generateCookFunction, parseMentions } from "discourse/lib/text";
|
||||
import Bookmark from "discourse/models/bookmark";
|
||||
import User from "discourse/models/user";
|
||||
|
@ -25,7 +25,7 @@ export default class ChatMessage {
|
|||
@tracked selected;
|
||||
@tracked channel;
|
||||
@tracked staged;
|
||||
@tracked processed = true;
|
||||
@tracked processed;
|
||||
@tracked draftSaved;
|
||||
@tracked draft;
|
||||
@tracked createdAt;
|
||||
|
@ -35,14 +35,14 @@ export default class ChatMessage {
|
|||
@tracked reviewableId;
|
||||
@tracked user;
|
||||
@tracked inReplyTo;
|
||||
@tracked expanded = true;
|
||||
@tracked expanded;
|
||||
@tracked bookmark;
|
||||
@tracked userFlagStatus;
|
||||
@tracked hidden;
|
||||
@tracked version = 0;
|
||||
@tracked edited;
|
||||
@tracked editing;
|
||||
@tracked chatWebhookEvent = new TrackedObject();
|
||||
@tracked chatWebhookEvent;
|
||||
@tracked mentionWarning;
|
||||
@tracked availableFlags;
|
||||
@tracked newest;
|
||||
|
@ -51,7 +51,7 @@ export default class ChatMessage {
|
|||
@tracked message;
|
||||
@tracked manager;
|
||||
@tracked deletedById;
|
||||
@tracked streaming = false;
|
||||
@tracked streaming;
|
||||
|
||||
@tracked _deletedAt;
|
||||
@tracked _cooked;
|
||||
|
@ -62,33 +62,33 @@ export default class ChatMessage {
|
|||
this.channel = channel;
|
||||
this.streaming = args.streaming;
|
||||
this.manager = args.manager;
|
||||
this.newest = args.newest || false;
|
||||
this.draftSaved = args.draftSaved || args.draft_saved || false;
|
||||
this.firstOfResults = args.firstOfResults || args.first_of_results || false;
|
||||
this.staged = args.staged || false;
|
||||
this.processed = args.processed || true;
|
||||
this.edited = args.edited || false;
|
||||
this.editing = args.editing || false;
|
||||
this.availableFlags = args.availableFlags || args.available_flags;
|
||||
this.hidden = args.hidden || false;
|
||||
this.chatWebhookEvent = args.chatWebhookEvent || args.chat_webhook_event;
|
||||
this.newest = args.newest ?? false;
|
||||
this.draftSaved = args.draftSaved ?? args.draft_saved ?? false;
|
||||
this.firstOfResults = args.firstOfResults ?? args.first_of_results ?? false;
|
||||
this.staged = args.staged ?? false;
|
||||
this.processed = args.processed ?? true;
|
||||
this.edited = args.edited ?? false;
|
||||
this.editing = args.editing ?? false;
|
||||
this.availableFlags = args.availableFlags ?? args.available_flags;
|
||||
this.hidden = args.hidden ?? false;
|
||||
this.chatWebhookEvent = args.chatWebhookEvent ?? args.chat_webhook_event;
|
||||
this.createdAt = args.created_at
|
||||
? new Date(args.created_at)
|
||||
: new Date(args.createdAt);
|
||||
this.deletedById = args.deletedById || args.deleted_by_id;
|
||||
this._deletedAt = args.deletedAt || args.deleted_at;
|
||||
this.expanded =
|
||||
this.hidden || this._deletedAt ? false : args.expanded || true;
|
||||
this.hidden || this._deletedAt ? false : args.expanded ?? true;
|
||||
this.excerpt = args.excerpt;
|
||||
this.reviewableId = args.reviewableId || args.reviewable_id;
|
||||
this.userFlagStatus = args.userFlagStatus || args.user_flag_status;
|
||||
this.reviewableId = args.reviewableId ?? args.reviewable_id;
|
||||
this.userFlagStatus = args.userFlagStatus ?? args.user_flag_status;
|
||||
this.draft = args.draft;
|
||||
this.message = args.message || "";
|
||||
this._cooked = args.cooked || "";
|
||||
this.message = args.message ?? "";
|
||||
this._cooked = args.cooked ?? "";
|
||||
this.inReplyTo =
|
||||
args.inReplyTo ||
|
||||
(args.in_reply_to || args.replyToMsg
|
||||
? ChatMessage.create(channel, args.in_reply_to || args.replyToMsg)
|
||||
args.inReplyTo ??
|
||||
(args.in_reply_to ?? args.replyToMsg
|
||||
? ChatMessage.create(channel, args.in_reply_to ?? args.replyToMsg)
|
||||
: null);
|
||||
this.reactions = this.#initChatMessageReactionModel(args.reactions);
|
||||
this.uploads = new TrackedArray(args.uploads || []);
|
||||
|
|
|
@ -13,12 +13,8 @@ export default class ChatThreadPreview {
|
|||
@tracked participantCount;
|
||||
@tracked participantUsers;
|
||||
|
||||
constructor(args = {}) {
|
||||
if (!args) {
|
||||
args = {};
|
||||
}
|
||||
|
||||
this.update(args);
|
||||
constructor(args) {
|
||||
this.update(args || {});
|
||||
}
|
||||
|
||||
get otherParticipantCount() {
|
||||
|
@ -26,24 +22,24 @@ export default class ChatThreadPreview {
|
|||
}
|
||||
|
||||
update(args = {}) {
|
||||
this.replyCount = args.reply_count || args.replyCount || 0;
|
||||
this.lastReplyId = args.last_reply_id || args.lastReplyId;
|
||||
this.replyCount = args.reply_count ?? args.replyCount ?? 0;
|
||||
this.lastReplyId = args.last_reply_id ?? args.lastReplyId;
|
||||
this.lastReplyCreatedAt = new Date(
|
||||
args.last_reply_created_at || args.lastReplyCreatedAt
|
||||
args.last_reply_created_at ?? args.lastReplyCreatedAt
|
||||
);
|
||||
this.lastReplyExcerpt = args.last_reply_excerpt || args.lastReplyExcerpt;
|
||||
this.lastReplyExcerpt = args.last_reply_excerpt ?? args.lastReplyExcerpt;
|
||||
this.participantCount =
|
||||
args.participant_count || args.participantCount || 0;
|
||||
args.participant_count ?? args.participantCount ?? 0;
|
||||
|
||||
// cheap trick to avoid avatars flickering
|
||||
const lastReplyUser = args.last_reply_user || args.lastReplyUser;
|
||||
const lastReplyUser = args.last_reply_user ?? args.lastReplyUser;
|
||||
if (lastReplyUser?.id !== this.lastReplyUser?.id) {
|
||||
this.lastReplyUser = lastReplyUser;
|
||||
}
|
||||
|
||||
// cheap trick to avoid avatars flickering
|
||||
const participantUsers =
|
||||
args.participant_users || args.participantUsers || [];
|
||||
args.participant_users ?? args.participantUsers ?? [];
|
||||
if (
|
||||
participantUsers?.map((u) => u.id).join(",") !==
|
||||
this.participantUsers?.map((u) => u.id).join(",")
|
||||
|
|
|
@ -5,13 +5,13 @@ import { service } from "@ember/service";
|
|||
export default class ChatTrackingState {
|
||||
@service chatTrackingStateManager;
|
||||
|
||||
@tracked _unreadCount = 0;
|
||||
@tracked _mentionCount = 0;
|
||||
@tracked _unreadCount;
|
||||
@tracked _mentionCount;
|
||||
|
||||
constructor(owner, params = {}) {
|
||||
setOwner(this, owner);
|
||||
this._unreadCount = params.unreadCount || 0;
|
||||
this._mentionCount = params.mentionCount || 0;
|
||||
this._unreadCount = params.unreadCount ?? 0;
|
||||
this._mentionCount = params.mentionCount ?? 0;
|
||||
}
|
||||
|
||||
reset() {
|
||||
|
|
|
@ -6,13 +6,13 @@ export default class UserChatChannelMembership {
|
|||
return new UserChatChannelMembership(args);
|
||||
}
|
||||
|
||||
@tracked following = false;
|
||||
@tracked muted = false;
|
||||
@tracked desktopNotificationLevel = null;
|
||||
@tracked mobileNotificationLevel = null;
|
||||
@tracked lastReadMessageId = null;
|
||||
@tracked lastViewedAt = null;
|
||||
@tracked user = null;
|
||||
@tracked following;
|
||||
@tracked muted;
|
||||
@tracked desktopNotificationLevel;
|
||||
@tracked mobileNotificationLevel;
|
||||
@tracked lastReadMessageId;
|
||||
@tracked lastViewedAt;
|
||||
@tracked user;
|
||||
|
||||
constructor(args = {}) {
|
||||
this.following = args.following;
|
||||
|
|
|
@ -6,9 +6,9 @@ export default class UserChatThreadMembership {
|
|||
return new UserChatThreadMembership(args);
|
||||
}
|
||||
|
||||
@tracked lastReadMessageId = null;
|
||||
@tracked notificationLevel = null;
|
||||
@tracked threadTitlePromptSeen = null;
|
||||
@tracked lastReadMessageId;
|
||||
@tracked notificationLevel;
|
||||
@tracked threadTitlePromptSeen;
|
||||
|
||||
constructor(args = {}) {
|
||||
this.lastReadMessageId = args.last_read_message_id;
|
||||
|
|
Loading…
Reference in New Issue