mirror of
https://github.com/discourse/discourse.git
synced 2025-05-28 13:51:18 +08:00
DEV: Add last_message_id to channel and thread (#22488)
Initial migration and changes to models as well as changing the following services to update last_message_id: * Chat::MessageCreator * Chat::RestoreMessage * Chat::TrashMessage The data migration will set the `last_message_id` for all existing threads and channels in the database. When we query the thread list as well as the channel, we look at the last message ID for the following: * Channel - Sorting DM channels, and channel metadata for the list of channels * Thread - Last reply details for thread indicators and thread list
This commit is contained in:
@ -120,16 +120,14 @@ describe Chat::MessageCreator do
|
||||
}.to change { Chat::Message.count }.by(1)
|
||||
end
|
||||
|
||||
it "updates the channel’s last message date" do
|
||||
previous_last_message_sent_at = public_chat_channel.last_message_sent_at
|
||||
|
||||
described_class.create(
|
||||
chat_channel: public_chat_channel,
|
||||
user: user1,
|
||||
content: "this is a message",
|
||||
)
|
||||
|
||||
expect(previous_last_message_sent_at).to be < public_chat_channel.reload.last_message_sent_at
|
||||
it "updates the last_message for the channel" do
|
||||
message =
|
||||
described_class.create(
|
||||
chat_channel: public_chat_channel,
|
||||
user: user1,
|
||||
content: "this is a message",
|
||||
).chat_message
|
||||
expect(public_chat_channel.reload.last_message).to eq(message)
|
||||
end
|
||||
|
||||
it "sets the last_editor_id to the user who created the message" do
|
||||
@ -640,6 +638,18 @@ describe Chat::MessageCreator do
|
||||
expect(message.in_reply_to.thread).to eq(message.thread)
|
||||
expect(message.thread.original_message).to eq(reply_message)
|
||||
expect(message.thread.original_message_user).to eq(reply_message.user)
|
||||
expect(message.thread.last_message).to eq(message)
|
||||
end
|
||||
|
||||
it "does not change the last_message of the channel for a thread reply" do
|
||||
original_last_message = public_chat_channel.last_message
|
||||
described_class.create(
|
||||
chat_channel: public_chat_channel,
|
||||
user: user1,
|
||||
content: "this is a message",
|
||||
in_reply_to_id: reply_message.id,
|
||||
)
|
||||
expect(public_chat_channel.reload.last_message).to eq(original_last_message)
|
||||
end
|
||||
|
||||
it "creates a user thread membership" do
|
||||
@ -756,6 +766,7 @@ describe Chat::MessageCreator do
|
||||
}.not_to change { Chat::Thread.count }
|
||||
|
||||
expect(message.reload.thread).to eq(existing_thread)
|
||||
expect(existing_thread.reload.last_message).to eq(message)
|
||||
end
|
||||
|
||||
it "creates a user thread membership if one does not exist" do
|
||||
|
Reference in New Issue
Block a user