diff --git a/plugins/chat/assets/javascripts/discourse/models/chat-channel.js b/plugins/chat/assets/javascripts/discourse/models/chat-channel.js index a04f8dcd7ad..e398e067457 100644 --- a/plugins/chat/assets/javascripts/discourse/models/chat-channel.js +++ b/plugins/chat/assets/javascripts/discourse/models/chat-channel.js @@ -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() { diff --git a/plugins/chat/assets/javascripts/discourse/models/chat-direct-message.js b/plugins/chat/assets/javascripts/discourse/models/chat-direct-message.js index df0ee97e60f..3d4f08cb676 100644 --- a/plugins/chat/assets/javascripts/discourse/models/chat-direct-message.js +++ b/plugins/chat/assets/javascripts/discourse/models/chat-direct-message.js @@ -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; diff --git a/plugins/chat/assets/javascripts/discourse/models/chat-message-reaction.js b/plugins/chat/assets/javascripts/discourse/models/chat-message-reaction.js index 867883df350..1914fb09b06 100644 --- a/plugins/chat/assets/javascripts/discourse/models/chat-message-reaction.js +++ b/plugins/chat/assets/javascripts/discourse/models/chat-message-reaction.js @@ -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 = []) { diff --git a/plugins/chat/assets/javascripts/discourse/models/chat-message.js b/plugins/chat/assets/javascripts/discourse/models/chat-message.js index eb744947991..649afefa97b 100644 --- a/plugins/chat/assets/javascripts/discourse/models/chat-message.js +++ b/plugins/chat/assets/javascripts/discourse/models/chat-message.js @@ -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 || []); diff --git a/plugins/chat/assets/javascripts/discourse/models/chat-thread-preview.js b/plugins/chat/assets/javascripts/discourse/models/chat-thread-preview.js index 941b654b099..cfbe82afda7 100644 --- a/plugins/chat/assets/javascripts/discourse/models/chat-thread-preview.js +++ b/plugins/chat/assets/javascripts/discourse/models/chat-thread-preview.js @@ -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(",") diff --git a/plugins/chat/assets/javascripts/discourse/models/chat-tracking-state.js b/plugins/chat/assets/javascripts/discourse/models/chat-tracking-state.js index 30f1116f5af..525d3eec5d8 100644 --- a/plugins/chat/assets/javascripts/discourse/models/chat-tracking-state.js +++ b/plugins/chat/assets/javascripts/discourse/models/chat-tracking-state.js @@ -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() { diff --git a/plugins/chat/assets/javascripts/discourse/models/user-chat-channel-membership.js b/plugins/chat/assets/javascripts/discourse/models/user-chat-channel-membership.js index 7a87d280d8d..0e5b6fe11d3 100644 --- a/plugins/chat/assets/javascripts/discourse/models/user-chat-channel-membership.js +++ b/plugins/chat/assets/javascripts/discourse/models/user-chat-channel-membership.js @@ -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; diff --git a/plugins/chat/assets/javascripts/discourse/models/user-chat-thread-membership.js b/plugins/chat/assets/javascripts/discourse/models/user-chat-thread-membership.js index 1987e09bfeb..d5ac1f8ecaa 100644 --- a/plugins/chat/assets/javascripts/discourse/models/user-chat-thread-membership.js +++ b/plugins/chat/assets/javascripts/discourse/models/user-chat-thread-membership.js @@ -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;