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:
Martin Brennan
2023-05-29 17:37:17 +02:00
committed by GitHub
parent 55ef2d0698
commit 72e46b98a9
4 changed files with 36 additions and 2 deletions

View File

@ -558,13 +558,30 @@ describe Chat::MessageCreator do
content: "this is a message",
in_reply_to_id: reply_message.id,
).chat_message
}.to change { Chat::UserChatThreadMembership.count }
}.to change { Chat::UserChatThreadMembership.count }.by(2)
expect(
Chat::UserChatThreadMembership.exists?(user: user1, thread: message.thread),
).to be_truthy
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
it "publishes the new thread" do
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
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 {
described_class.create(
chat_channel: public_chat_channel,