diff options
author | multiple creatures <dev@multiple-creature.party> | 2020-01-13 21:57:24 -0600 |
---|---|---|
committer | multiple creatures <dev@multiple-creature.party> | 2020-01-13 21:57:24 -0600 |
commit | 67516a07db44196cc4bb94bf94abe5c6f611cf07 (patch) | |
tree | f65b7c79f859329a0438d806e777fa1d7aa7f400 /app/workers | |
parent | 1fbe7c340201ddff5232c7931a265136943ffd59 (diff) |
add new privacy option to auto-defederate after a given timespan + add options to defederate and/or delete past posts + add `defed_in`/`parent:defed_in`/`thread:defed_in` bangtags + ui indicator for posts marked for auto-defederation
Diffstat (limited to 'app/workers')
-rw-r--r-- | app/workers/defederate_status_worker.rb | 17 | ||||
-rw-r--r-- | app/workers/mark_expired_statuses_worker.rb | 44 | ||||
-rw-r--r-- | app/workers/scheduler/defederating_statuses_scheduler.rb | 19 |
3 files changed, 80 insertions, 0 deletions
diff --git a/app/workers/defederate_status_worker.rb b/app/workers/defederate_status_worker.rb new file mode 100644 index 000000000..bae4be9b8 --- /dev/null +++ b/app/workers/defederate_status_worker.rb @@ -0,0 +1,17 @@ +# frozen_string_literal: true + +class DefederateStatusWorker + include Sidekiq::Worker + + sidekiq_options unique: :until_executed + + def perform(defederating_status_id) + defederating_status = DefederatingStatus.find(defederating_status_id) + defederating_status.destroy! + + RemoveStatusService.new.call(defederating_status.status, defederate_only: true) + true + rescue ActiveRecord::RecordNotFound, ActiveRecord::RecordInvalid + true + end +end diff --git a/app/workers/mark_expired_statuses_worker.rb b/app/workers/mark_expired_statuses_worker.rb new file mode 100644 index 000000000..9eac58357 --- /dev/null +++ b/app/workers/mark_expired_statuses_worker.rb @@ -0,0 +1,44 @@ +# frozen_string_literal: true + +class MarkExpiredStatusesWorker + include Sidekiq::Worker + + sidekiq_options queue: 'bulk' + + def perform(account_id, defederate = false, lifespan = false) + @account = Account.find(account_id) + return if @account&.user.nil? + @user = @account.user + + @roar_defederate = @user.roar_defederate.to_i + @roar_lifespan = @user.roar_lifespan.to_i + + defederate = false if @roar_defederate == 0 + lifespan = false if @roar_lifespan == 0 + + return unless defederate || lifespan + + offset = 30.minutes + + @account.statuses.find_each do |status| + modified = false + + if defederate && !status.local_only? && status.updated_at < @roar_defederate.days.ago + status.defederate_after = offset + modified = true + end + + if lifespan && status.updated_at < @roar_lifespan.days.ago + status.delete_after = offset + 30.minutes + modified = true + end + + if modified + Rails.cache.delete("statuses/#{status.id}") + offset += 1.second + end + end + rescue ActiveRecord::RecordNotFound + true + end +end diff --git a/app/workers/scheduler/defederating_statuses_scheduler.rb b/app/workers/scheduler/defederating_statuses_scheduler.rb new file mode 100644 index 000000000..91a644e02 --- /dev/null +++ b/app/workers/scheduler/defederating_statuses_scheduler.rb @@ -0,0 +1,19 @@ +# frozen_string_literal: true + +class Scheduler::DefederatingStatusesScheduler + include Sidekiq::Worker + + sidekiq_options unique: :until_executed, retry: 0 + + def perform + due_statuses.find_each do |defederating_status| + DefederateStatusWorker.perform_async(defederating_status.id) + end + end + + private + + def due_statuses + DefederatingStatus.where('defederate_after <= ?', Time.now.utc) + end +end |