A platform for community discussion. Free, open, simple.
FIX: live updates threads from my threads page (#25955)
Joffrey JAFFEUX0bb492c6b6b7
diff --git a/plugins/chat/assets/javascripts/discourse/components/user-threads/index.gjs b/plugins/chat/assets/javascripts/discourse/components/user-threads/index.gjsindex 945a876371c..bf9deae6a66 100644--- a/plugins/chat/assets/javascripts/discourse/components/user-threads/index.gjs+++ b/plugins/chat/assets/javascripts/discourse/components/user-threads/index.gjs@@ -7,12 +7,11 @@ import ChannelTitle from "discourse/plugins/chat/discourse/components/channel-tiimport List from "discourse/plugins/chat/discourse/components/chat/list";import ThreadIndicator from "discourse/plugins/chat/discourse/components/chat-message-thread-indicator";import ThreadTitle from "discourse/plugins/chat/discourse/components/thread-title";-import ChatChannel from "discourse/plugins/chat/discourse/models/chat-channel";-import ChatThread from "discourse/plugins/chat/discourse/models/chat-thread";export default class UserThreads extends Component {@service chat;@service chatApi;+ @service chatChannelsManager;@cachedget threadsCollection() {@@ -22,9 +21,10 @@ export default class UserThreads extends Component {@bindhandleLoadedThreads(result) {return result.threads.map((threadObject) => {- const channel = ChatChannel.create(threadObject.channel);- const thread = ChatThread.create(channel, threadObject);+ const channel = this.chatChannelsManager.store(threadObject.channel);+ const thread = channel.threadsManager.add(channel, threadObject);const tracking = result.tracking[thread.id];+if (tracking) {thread.tracking.mentionCount = tracking.mention_count;thread.tracking.unreadCount = tracking.unread_count;diff --git a/plugins/chat/assets/javascripts/discourse/models/chat-thread-preview.js b/plugins/chat/assets/javascripts/discourse/models/chat-thread-preview.jsindex 22547a071aa..37325681a54 100644--- a/plugins/chat/assets/javascripts/discourse/models/chat-thread-preview.js+++ b/plugins/chat/assets/javascripts/discourse/models/chat-thread-preview.js@@ -1,5 +1,6 @@import { tracked } from "@glimmer/tracking";import { TrackedArray } from "@ember-compat/tracked-built-ins";+import User from "discourse/models/user";export default class ChatThreadPreview {static create(args = {}) {@@ -36,4 +37,17 @@ export default class ChatThreadPreview {get otherParticipantCount() {return this.participantCount - this.participantUsers.length;}++ updateFromMessageObject(messageObject) {+ const user = User.create(messageObject.user);+ if (!this.participantUsers.find((u) => u.id === user.id)) {+ this.participantUsers.push(user);+ this.participantCount += 1;+ }+ this.replyCount += 1;+ this.lastReplyAt = messageObject.created_at;+ this.lastReplyId = messageObject.id;+ this.lastReplyExcerpt = messageObject.excerpt;+ this.lastReplyUser = user;+ }}diff --git a/plugins/chat/assets/javascripts/discourse/services/chat-subscriptions-manager.js b/plugins/chat/assets/javascripts/discourse/services/chat-subscriptions-manager.jsindex 1a6dde0cc52..1ebbc068415 100644--- a/plugins/chat/assets/javascripts/discourse/services/chat-subscriptions-manager.js+++ b/plugins/chat/assets/javascripts/discourse/services/chat-subscriptions-manager.js@@ -265,6 +265,7 @@ export default class ChatSubscriptionsManager extends Service {busData.thread_id,busData.message.created_at);+ thread.preview.updateFromMessageObject(busData.message);thread.tracking.unreadCount++;this._updateActiveLastViewedAt(channel);}diff --git a/plugins/chat/spec/system/page_objects/chat/chat.rb b/plugins/chat/spec/system/page_objects/chat/chat.rbindex f86e1d3660d..24060a02bf7 100644--- a/plugins/chat/spec/system/page_objects/chat/chat.rb+++ b/plugins/chat/spec/system/page_objects/chat/chat.rb@@ -59,6 +59,7 @@ module PageObjectsdef visit_user_threadsvisit("/chat/threads")+ has_css?(".spinner")has_no_css?(".spinner")enddiff --git a/plugins/chat/spec/system/page_objects/chat/components/thread_indicator.rb b/plugins/chat/spec/system/page_objects/chat/components/thread_indicator.rbindex 5f6a69c2308..bea1ff5ab8b 100644--- a/plugins/chat/spec/system/page_objects/chat/components/thread_indicator.rb+++ b/plugins/chat/spec/system/page_objects/chat/components/thread_indicator.rb@@ -41,6 +41,14 @@ module PageObjectsfind(@context).has_no_css?(".chat-thread-participants")end+ def has_excerpt?(text)+ find(@context).find("#{SELECTOR}__last-reply-excerpt", text: text)+ end++ def has_user?(user)+ find(@context).find("#{SELECTOR}__last-reply-username", text: user.username)+ end+def excerptfind(@context).find("#{SELECTOR}__last-reply-excerpt")enddiff --git a/plugins/chat/spec/system/reply_to_message/smoke_spec.rb b/plugins/chat/spec/system/reply_to_message/smoke_spec.rbindex 70b88b91168..0ae77982b9c 100644--- a/plugins/chat/spec/system/reply_to_message/smoke_spec.rb+++ b/plugins/chat/spec/system/reply_to_message/smoke_spec.rb@@ -54,7 +54,7 @@ RSpec.describe "Reply to message - smoke", type: :system dousing_session(:user_1) doexpect(thread_page.messages).to have_message(text: "user1reply")expect(thread_page.messages).to have_message(text: "user2reply")- expect(channel_page.message_thread_indicator(original_message)).to have_reply_count(2)+ expect(channel_page.message_thread_indicator(original_message)).to have_reply_count(3)endendenddiff --git a/plugins/chat/spec/system/user_threads_spec.rb b/plugins/chat/spec/system/user_threads_spec.rbindex 09f985dd436..6c68554a73d 100644--- a/plugins/chat/spec/system/user_threads_spec.rb+++ b/plugins/chat/spec/system/user_threads_spec.rb@@ -114,6 +114,24 @@ RSpec.describe "User threads", type: :system doexpect(user_threads_page).to have_threadsend++ it "updates the thread when another user replies" do+ chat_thread_chain_bootstrap(channel: channel_1, users: [current_user, Fabricate(:user)])+ thread = channel_1.threads.last+ message = thread.original_message+ last_user = Fabricate(:user)++ chat_page.visit_user_threads++ last_message = Fabricate(:chat_message, thread: thread, user: last_user, use_service: true)++ indicator = PageObjects::Components::Chat::ThreadIndicator.new(".c-user-thread")++ expect(indicator).to have_reply_count(4)+ expect(indicator).to have_participant(last_user)+ expect(indicator).to have_excerpt(last_message.excerpt)+ expect(indicator).to have_user(last_user)+ endendcontext "when in drawer" do