mirror of
https://github.com/discourse/discourse.git
synced 2025-04-27 02:44:33 +08:00
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:
parent
d2d6d727de
commit
3ea8203719
@ -147,7 +147,7 @@ module Chat
|
|||||||
)
|
)
|
||||||
|
|
||||||
Chat::Publisher.publish_user_tracking_state!(current_user, @chat_channel, message)
|
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
|
end
|
||||||
|
|
||||||
def edit_message
|
def edit_message
|
||||||
|
@ -1,4 +1,6 @@
|
|||||||
import Component from "@glimmer/component";
|
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 { Promise } from "rsvp";
|
||||||
import { tracked } from "@glimmer/tracking";
|
import { tracked } from "@glimmer/tracking";
|
||||||
import { action } from "@ember/object";
|
import { action } from "@ember/object";
|
||||||
@ -272,6 +274,13 @@ export default class ChatThreadPanel extends Component {
|
|||||||
thread_id: message.thread.staged ? null : message.thread.id,
|
thread_id: message.thread.staged ? null : message.thread.id,
|
||||||
staged_thread_id: message.thread.staged ? message.thread.id : null,
|
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) => {
|
.catch((error) => {
|
||||||
this.#onSendError(message.id, error);
|
this.#onSendError(message.id, error);
|
||||||
})
|
})
|
||||||
|
@ -157,6 +157,7 @@ Fabricator(:chat_thread, class_name: "Chat::Thread") do
|
|||||||
thread.channel = original_message.chat_channel
|
thread.channel = original_message.chat_channel
|
||||||
end
|
end
|
||||||
|
|
||||||
|
transient :with_replies
|
||||||
transient :channel
|
transient :channel
|
||||||
transient :original_message_user
|
transient :original_message_user
|
||||||
|
|
||||||
@ -168,9 +169,13 @@ Fabricator(:chat_thread, class_name: "Chat::Thread") do
|
|||||||
)
|
)
|
||||||
end
|
end
|
||||||
|
|
||||||
after_create do |thread|
|
after_create do |thread, transients|
|
||||||
thread.original_message.update!(thread_id: thread.id)
|
thread.original_message.update!(thread_id: thread.id)
|
||||||
thread.add(thread.original_message_user)
|
thread.add(thread.original_message_user)
|
||||||
|
|
||||||
|
if transients[:with_replies]
|
||||||
|
Fabricate.times(transients[:with_replies], :chat_message, thread: thread)
|
||||||
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
@ -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))
|
expect(channel_page).not_to have_css(channel_page.message_by_id_selector(thread_message.id))
|
||||||
end
|
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
|
it "handles updates from multiple users sending messages in the thread" do
|
||||||
using_session(:tab_1) do
|
using_session(:tab_1) do
|
||||||
sign_in(current_user)
|
sign_in(current_user)
|
||||||
|
Loading…
x
Reference in New Issue
Block a user