mirror of
https://github.com/discourse/discourse.git
synced 2025-03-29 06:46:39 +08:00
FIX: Create original message user thread membership (#21808)
When a thread is created / a new message is created in the thread, we want to make sure that the original message user has a membership for that thread, otherwise they will not receive unread indicators for messages in the thread.
This commit is contained in:
parent
55ef2d0698
commit
72e46b98a9
plugins/chat
assets/javascripts/discourse/components
lib/chat
spec
@ -1,5 +1,9 @@
|
|||||||
<div
|
<div
|
||||||
class={{concat-class "chat-thread" (if this.loading "loading")}}
|
class={{concat-class
|
||||||
|
"chat-thread"
|
||||||
|
(if this.loading "loading")
|
||||||
|
(if this.thread.staged "staged")
|
||||||
|
}}
|
||||||
data-id={{this.thread.id}}
|
data-id={{this.thread.id}}
|
||||||
{{did-insert this.setUploadDropZone}}
|
{{did-insert this.setUploadDropZone}}
|
||||||
{{did-insert this.subscribeToUpdates}}
|
{{did-insert this.subscribeToUpdates}}
|
||||||
|
@ -233,6 +233,13 @@ module Chat
|
|||||||
return if resolved_thread.blank?
|
return if resolved_thread.blank?
|
||||||
resolved_thread.increment_replies_count_cache
|
resolved_thread.increment_replies_count_cache
|
||||||
Chat::UserChatThreadMembership.find_or_create_by!(user: @user, thread: resolved_thread)
|
Chat::UserChatThreadMembership.find_or_create_by!(user: @user, thread: resolved_thread)
|
||||||
|
|
||||||
|
if resolved_thread.original_message_user != @user
|
||||||
|
Chat::UserChatThreadMembership.find_or_create_by!(
|
||||||
|
user: resolved_thread.original_message_user,
|
||||||
|
thread: resolved_thread,
|
||||||
|
)
|
||||||
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
@ -558,13 +558,30 @@ describe Chat::MessageCreator do
|
|||||||
content: "this is a message",
|
content: "this is a message",
|
||||||
in_reply_to_id: reply_message.id,
|
in_reply_to_id: reply_message.id,
|
||||||
).chat_message
|
).chat_message
|
||||||
}.to change { Chat::UserChatThreadMembership.count }
|
}.to change { Chat::UserChatThreadMembership.count }.by(2)
|
||||||
|
|
||||||
expect(
|
expect(
|
||||||
Chat::UserChatThreadMembership.exists?(user: user1, thread: message.thread),
|
Chat::UserChatThreadMembership.exists?(user: user1, thread: message.thread),
|
||||||
).to be_truthy
|
).to be_truthy
|
||||||
end
|
end
|
||||||
|
|
||||||
|
it "creates a thread membership for the original message user" do
|
||||||
|
message = nil
|
||||||
|
expect {
|
||||||
|
message =
|
||||||
|
described_class.create(
|
||||||
|
chat_channel: public_chat_channel,
|
||||||
|
user: user1,
|
||||||
|
content: "this is a message",
|
||||||
|
in_reply_to_id: reply_message.id,
|
||||||
|
).chat_message
|
||||||
|
}.to change { Chat::UserChatThreadMembership.count }.by(2)
|
||||||
|
|
||||||
|
expect(
|
||||||
|
Chat::UserChatThreadMembership.exists?(user: reply_message.user, thread: message.thread),
|
||||||
|
).to be_truthy
|
||||||
|
end
|
||||||
|
|
||||||
context "when threading is enabled" do
|
context "when threading is enabled" do
|
||||||
it "publishes the new thread" do
|
it "publishes the new thread" do
|
||||||
public_chat_channel.update!(threading_enabled: true)
|
public_chat_channel.update!(threading_enabled: true)
|
||||||
@ -664,6 +681,11 @@ describe Chat::MessageCreator do
|
|||||||
|
|
||||||
it "does not create a thread membership if one exists" do
|
it "does not create a thread membership if one exists" do
|
||||||
Fabricate(:user_chat_thread_membership, user: user1, thread: existing_thread)
|
Fabricate(:user_chat_thread_membership, user: user1, thread: existing_thread)
|
||||||
|
Fabricate(
|
||||||
|
:user_chat_thread_membership,
|
||||||
|
user: existing_thread.original_message_user,
|
||||||
|
thread: existing_thread,
|
||||||
|
)
|
||||||
expect {
|
expect {
|
||||||
described_class.create(
|
described_class.create(
|
||||||
chat_channel: public_chat_channel,
|
chat_channel: public_chat_channel,
|
||||||
|
@ -42,6 +42,7 @@ RSpec.describe "Reply to message - channel - full page", type: :system, js: true
|
|||||||
thread_page.click_send_message
|
thread_page.click_send_message
|
||||||
|
|
||||||
expect(thread_page).to have_message(text: "reply to message")
|
expect(thread_page).to have_message(text: "reply to message")
|
||||||
|
expect(channel_page).to have_thread_indicator(original_message)
|
||||||
|
|
||||||
refresh
|
refresh
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user