FIX: Chat threads N1 (#22322)

Followup to 1526d1f97d

This commit fixes an N1 for mentions/user status
when querying chat threads. This only happened if
any of the thread OMs had mentions.
This commit is contained in:
Martin Brennan 2023-06-28 15:41:51 +10:00 committed by GitHub
parent 0d1d707213
commit 41ebbab4ff
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 35 additions and 1 deletions

View File

@ -132,8 +132,10 @@ module Chat
original_message_user: :user_status,
original_message: [
:chat_webhook_event,
:chat_mentions,
:chat_channel,
chat_mentions: {
user: :user_status,
},
user: :user_status,
],
)

View File

@ -124,6 +124,38 @@ RSpec.describe Chat::Api::ChannelThreadsController do
)
end
it "has preloaded chat mentions and users for the thread original message" do
thread_1.original_message.update!(
message: "@#{current_user.username} hello and @#{thread_2.original_message_user.username}!",
)
thread_1.original_message.rebake!
thread_1.original_message.create_mentions
get "/chat/api/channels/#{public_channel.id}/threads"
expect(response.status).to eq(200)
expect(
response.parsed_body["threads"]
.find { |thread| thread["id"] == thread_1.id }
.dig("original_message", "mentioned_users"),
).to eq(
[
{
"avatar_template" => User.system_avatar_template(current_user.username),
"id" => current_user.id,
"name" => current_user.name,
"username" => current_user.username,
},
{
"avatar_template" =>
User.system_avatar_template(thread_2.original_message_user.username),
"id" => thread_2.original_message_user.id,
"name" => thread_2.original_message_user.name,
"username" => thread_2.original_message_user.username,
},
],
)
end
context "when the channel is not accessible to the useer" do
before do
public_channel.update!(chatable: Fabricate(:private_category, group: Fabricate(:group)))