FEATURE: Hook up chat bulk delete for threads (#21109)

Followup to bd5c5c4b5f,
this commit hooks up the bulk delete events for chat
messages inside the thread panel, by fanning out the
deleted message IDs based on whether they belong to
a thread or not.

Also adds a system spec to cover this case, as previously
the bulk delete event would have been broken with an incorrect
`typ` rather than `type` hash key.
This commit is contained in:
Martin Brennan
2023-04-18 08:28:20 +10:00
committed by GitHub
parent b869d35f94
commit 1e85de36e2
10 changed files with 222 additions and 24 deletions
+15
View File
@@ -34,6 +34,21 @@ module Chat
original_message.excerpt(max_length: EXCERPT_LENGTH)
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,
array_agg(chat_messages.id ORDER BY chat_messages.created_at, chat_messages.id) AS thread_message_ids,
chat_threads.original_message_id
FROM chat_messages
INNER JOIN chat_threads ON chat_threads.id = chat_messages.thread_id
WHERE thread_id IS NOT NULL
#{thread_ids ? "AND thread_id IN (:thread_ids)" : ""}
#{message_ids ? "AND chat_messages.id IN (:message_ids)" : ""}
#{include_original_message ? "" : "AND chat_messages.id != chat_threads.original_message_id"}
GROUP BY thread_id, chat_threads.original_message_id;
SQL
end
def self.ensure_consistency!
update_counts
end