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
+23 -3
View File
@@ -167,11 +167,31 @@ module Chat
end
def self.publish_bulk_delete!(chat_channel, deleted_message_ids)
# TODO (martin) Handle sending this through for all the threads that
# may contain the deleted messages as well.
Chat::Thread
.grouped_messages(message_ids: deleted_message_ids)
.each do |group|
MessageBus.publish(
thread_message_bus_channel(chat_channel.id, group.thread_id),
{
type: "bulk_delete",
deleted_ids: group.thread_message_ids,
deleted_at: Time.zone.now,
},
permissions(chat_channel),
)
# Don't need to publish to the main channel if the messages deleted
# were a part of the thread (except the original message ID, since
# that shows in the main channel).
deleted_message_ids =
deleted_message_ids - (group.thread_message_ids - [group.original_message_id])
end
return if deleted_message_ids.empty?
MessageBus.publish(
root_message_bus_channel(chat_channel.id),
{ typ: "bulk_delete", deleted_ids: deleted_message_ids, deleted_at: Time.zone.now },
{ type: "bulk_delete", deleted_ids: deleted_message_ids, deleted_at: Time.zone.now },
permissions(chat_channel),
)
end