mirror of
https://github.com/discourse/discourse.git
synced 2025-06-04 04:14:38 +08:00
FIX: Update last_read_message_id
when moving chat messages (#22643)
This commit is contained in:
@ -66,6 +66,7 @@ module Chat
|
|||||||
update_references
|
update_references
|
||||||
delete_source_messages
|
delete_source_messages
|
||||||
update_reply_references
|
update_reply_references
|
||||||
|
update_tracking_state
|
||||||
update_thread_references
|
update_thread_references
|
||||||
end
|
end
|
||||||
|
|
||||||
@ -208,6 +209,10 @@ module Chat
|
|||||||
SQL
|
SQL
|
||||||
end
|
end
|
||||||
|
|
||||||
|
def update_tracking_state
|
||||||
|
::Chat::Action::ResetUserLastReadChannelMessage.call(@source_message_ids, @source_channel.id)
|
||||||
|
end
|
||||||
|
|
||||||
def update_thread_references
|
def update_thread_references
|
||||||
threads_to_update = []
|
threads_to_update = []
|
||||||
@source_messages
|
@source_messages
|
||||||
|
@ -183,6 +183,31 @@ describe Chat::MessageMover do
|
|||||||
expect(message3.reload.thread).to eq(thread)
|
expect(message3.reload.thread).to eq(thread)
|
||||||
end
|
end
|
||||||
|
|
||||||
|
it "updates the tracking to the last non-deleted channel message for users whose last_read_message_id was the moved message" do
|
||||||
|
membership_1 =
|
||||||
|
Fabricate(
|
||||||
|
:user_chat_channel_membership,
|
||||||
|
chat_channel: source_channel,
|
||||||
|
last_read_message: message1,
|
||||||
|
)
|
||||||
|
membership_2 =
|
||||||
|
Fabricate(
|
||||||
|
:user_chat_channel_membership,
|
||||||
|
chat_channel: source_channel,
|
||||||
|
last_read_message: message2,
|
||||||
|
)
|
||||||
|
membership_3 =
|
||||||
|
Fabricate(
|
||||||
|
:user_chat_channel_membership,
|
||||||
|
chat_channel: source_channel,
|
||||||
|
last_read_message: message3,
|
||||||
|
)
|
||||||
|
move!([message2.id])
|
||||||
|
expect(membership_1.reload.last_read_message_id).to eq(message1.id)
|
||||||
|
expect(membership_2.reload.last_read_message_id).to eq(message3.id)
|
||||||
|
expect(membership_3.reload.last_read_message_id).to eq(message3.id)
|
||||||
|
end
|
||||||
|
|
||||||
context "when a thread original message is moved" do
|
context "when a thread original message is moved" do
|
||||||
it "creates a new thread for the messages left behind in the old channel" do
|
it "creates a new thread for the messages left behind in the old channel" do
|
||||||
message4 =
|
message4 =
|
||||||
|
Reference in New Issue
Block a user