FIX: Track thread in UI when user sends first message (#22462)

When a user sends their first message in a thread we
automatically track the thread in the backend, but we
don't reflect this in the UI until the user re-opens
the thread. This commit fixes that by showing the new
tracking level in the UI.
This commit is contained in:
Martin Brennan 2023-07-07 13:09:06 +10:00 committed by GitHub
parent d2d6d727de
commit 3ea8203719
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
4 changed files with 26 additions and 2 deletions

View File

@ -147,7 +147,7 @@ module Chat
)
Chat::Publisher.publish_user_tracking_state!(current_user, @chat_channel, message)
render json: success_json
render json: success_json.merge(message_id: message.id)
end
def edit_message

View File

@ -1,4 +1,6 @@
import Component from "@glimmer/component";
import { NotificationLevels } from "discourse/lib/notification-levels";
import UserChatThreadMembership from "discourse/plugins/chat/discourse/models/user-chat-thread-membership";
import { Promise } from "rsvp";
import { tracked } from "@glimmer/tracking";
import { action } from "@ember/object";
@ -272,6 +274,13 @@ export default class ChatThreadPanel extends Component {
thread_id: message.thread.staged ? null : message.thread.id,
staged_thread_id: message.thread.staged ? message.thread.id : null,
})
.then((response) => {
this.args.thread.currentUserMembership ??=
UserChatThreadMembership.create({
notification_level: NotificationLevels.TRACKING,
last_read_message_id: response.message_id,
});
})
.catch((error) => {
this.#onSendError(message.id, error);
})

View File

@ -157,6 +157,7 @@ Fabricator(:chat_thread, class_name: "Chat::Thread") do
thread.channel = original_message.chat_channel
end
transient :with_replies
transient :channel
transient :original_message_user
@ -168,9 +169,13 @@ Fabricator(:chat_thread, class_name: "Chat::Thread") do
)
end
after_create do |thread|
after_create do |thread, transients|
thread.original_message.update!(thread_id: thread.id)
thread.add(thread.original_message_user)
if transients[:with_replies]
Fabricate.times(transients[:with_replies], :chat_message, thread: thread)
end
end
end

View File

@ -127,6 +127,16 @@ describe "Single thread in side panel", type: :system do
expect(channel_page).not_to have_css(channel_page.message_by_id_selector(thread_message.id))
end
it "changes the tracking bell to be Tracking level in the thread panel" do
new_thread = Fabricate(:chat_thread, channel: channel, with_replies: 1)
chat_page.visit_channel(channel)
channel_page.message_thread_indicator(new_thread.original_message).click
expect(side_panel).to have_open_thread(new_thread)
expect(thread_page).to have_notification_level("normal")
thread_page.send_message("new thread message")
expect(thread_page).to have_notification_level("tracking")
end
it "handles updates from multiple users sending messages in the thread" do
using_session(:tab_1) do
sign_in(current_user)