FIX: Update `last_read_message_id` when moving chat messages (#22643)

This commit is contained in:
Jan Cernik 2023-07-18 12:46:54 -03:00 committed by GitHub
parent 3d554aa10e
commit d258bda2fe
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 30 additions and 0 deletions

View File

@ -66,6 +66,7 @@ module Chat
update_references
delete_source_messages
update_reply_references
update_tracking_state
update_thread_references
end
@ -208,6 +209,10 @@ module Chat
SQL
end
def update_tracking_state
::Chat::Action::ResetUserLastReadChannelMessage.call(@source_message_ids, @source_channel.id)
end
def update_thread_references
threads_to_update = []
@source_messages

View File

@ -183,6 +183,31 @@ describe Chat::MessageMover do
expect(message3.reload.thread).to eq(thread)
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
it "creates a new thread for the messages left behind in the old channel" do
message4 =