mirror of
https://github.com/discourse/discourse.git
synced 2025-02-12 22:34:57 +00:00
This commit introduce a new API for registering callbacks, which we'll execute when a user gets destroyed, and the `delete_posts` opt is true. The chat plugin registers one callback and queues a job to destroy every message from that user in batches.
41 lines
983 B
Ruby
41 lines
983 B
Ruby
# frozen_string_literal: true
|
|
|
|
module Jobs
|
|
class DeleteOldChatMessages < ::Jobs::Scheduled
|
|
daily at: 0.hours
|
|
|
|
def execute(args = {})
|
|
delete_public_channel_messages
|
|
delete_dm_channel_messages
|
|
end
|
|
|
|
private
|
|
|
|
def delete_public_channel_messages
|
|
return unless valid_day_value?(:chat_channel_retention_days)
|
|
|
|
ChatMessageDestroyer.new.destroy_in_batches(
|
|
ChatMessage
|
|
.in_public_channel
|
|
.with_deleted
|
|
.created_before(SiteSetting.chat_channel_retention_days.days.ago)
|
|
)
|
|
end
|
|
|
|
def delete_dm_channel_messages
|
|
return unless valid_day_value?(:chat_dm_retention_days)
|
|
|
|
ChatMessageDestroyer.new.destroy_in_batches(
|
|
ChatMessage
|
|
.in_dm_channel
|
|
.with_deleted
|
|
.created_before(SiteSetting.chat_dm_retention_days.days.ago)
|
|
)
|
|
end
|
|
|
|
def valid_day_value?(setting_name)
|
|
(SiteSetting.public_send(setting_name) || 0).positive?
|
|
end
|
|
end
|
|
end
|