FIX: Update client lastReadMessageId on trashed message (#21697)

Followup ae3231e1406d4ccf1d048ef8a8d8f744f840896b, when a
message is trashed we already update the lastReadMessageId of
all users in the channel to the latest non-deleted message on
the server side. However we didn't propagate this to the client,
so in some cases when we did the following:

1. Delete the last message in the channel
2. Switch to another channel
3. Switch back to the original

We would get a 404 error from the target message ID being looked
up still being the old lastReadMessageId (now deleted) for the
user's channel membership.

All we need to do is send the last not-deleted message ID for
the channel (or thread) to all the member users.
This commit is contained in:
Martin Brennan
2023-05-23 18:32:19 +02:00
committed by GitHub
parent bce56d843c
commit c908eeacc9
9 changed files with 102 additions and 1 deletions

View File

@ -127,6 +127,16 @@ module Chat
SQL
end
def latest_not_deleted_message_id
DB.query_single(<<~SQL, channel_id: self.id).first
SELECT id FROM chat_messages
WHERE chat_channel_id = :channel_id
AND deleted_at IS NULL
ORDER BY created_at DESC, id DESC
LIMIT 1
SQL
end
private
def change_status(acting_user, target_status)

View File

@ -52,6 +52,17 @@ module Chat
original_message.rich_excerpt(max_length: EXCERPT_LENGTH)
end
def latest_not_deleted_message_id
DB.query_single(<<~SQL, channel_id: self.channel_id, thread_id: self.id).first
SELECT id FROM chat_messages
WHERE chat_channel_id = :channel_id
AND thread_id = :thread_id
AND deleted_at IS NULL
ORDER BY created_at DESC, id DESC
LIMIT 1
SQL
end
def self.grouped_messages(thread_ids: nil, message_ids: nil, include_original_message: true)
DB.query(<<~SQL, message_ids: message_ids, thread_ids: thread_ids)
SELECT thread_id,