2022-11-02 09:41:30 -04:00
|
|
|
# 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
|
|
|
|
|
2022-11-28 11:32:57 -05:00
|
|
|
private
|
|
|
|
|
2022-11-02 09:41:30 -04:00
|
|
|
def delete_public_channel_messages
|
|
|
|
return unless valid_day_value?(:chat_channel_retention_days)
|
|
|
|
|
2022-11-28 11:32:57 -05:00
|
|
|
ChatMessageDestroyer.new.destroy_in_batches(
|
|
|
|
ChatMessage.in_public_channel.with_deleted.created_before(
|
|
|
|
SiteSetting.chat_channel_retention_days.days.ago,
|
2023-01-06 15:42:16 -05:00
|
|
|
),
|
2022-11-28 11:32:57 -05:00
|
|
|
)
|
2022-11-02 09:41:30 -04:00
|
|
|
end
|
|
|
|
|
|
|
|
def delete_dm_channel_messages
|
|
|
|
return unless valid_day_value?(:chat_dm_retention_days)
|
|
|
|
|
2022-11-28 11:32:57 -05:00
|
|
|
ChatMessageDestroyer.new.destroy_in_batches(
|
|
|
|
ChatMessage.in_dm_channel.with_deleted.created_before(
|
|
|
|
SiteSetting.chat_dm_retention_days.days.ago,
|
2023-01-06 15:42:16 -05:00
|
|
|
),
|
2022-11-28 11:32:57 -05:00
|
|
|
)
|
2022-11-02 09:41:30 -04:00
|
|
|
end
|
|
|
|
|
|
|
|
def valid_day_value?(setting_name)
|
|
|
|
(SiteSetting.public_send(setting_name) || 0).positive?
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|