about summary refs log tree commit diff
path: root/app/services
diff options
context:
space:
mode:
authormultiple creatures <dev@multiple-creature.party>2019-08-07 01:08:07 -0500
committermultiple creatures <dev@multiple-creature.party>2019-08-07 01:08:34 -0500
commitef04f3879ac3bd7ec6dddd6cb843c8cdb79a1175 (patch)
tree719373d32c084e20d878e9de13a034946c5663b3 /app/services
parenta8475313b8e81f1e91ee446599a9b7b78716f30c (diff)
add option to automatically space out boosts over configurable random intervals
Diffstat (limited to 'app/services')
-rw-r--r--app/services/reblog_service.rb30
-rw-r--r--app/services/remove_status_service.rb6
2 files changed, 25 insertions, 11 deletions
diff --git a/app/services/reblog_service.rb b/app/services/reblog_service.rb
index 9ac38ac9d..7d72357f9 100644
--- a/app/services/reblog_service.rb
+++ b/app/services/reblog_service.rb
@@ -14,22 +14,30 @@ class ReblogService < BaseService
     authorize_with account, reblogged_status, :reblog?
 
     reblog = account.statuses.find_by(reblog: reblogged_status)
+    new_reblog = reblog.nil?
 
-    return reblog unless reblog.nil?
+    if new_reblog
+      visibility = options[:visibility] || account.user&.setting_default_privacy
+      visibility = reblogged_status.visibility if reblogged_status.hidden?
+      reblog = account.statuses.create!(reblog: reblogged_status, text: '', visibility: visibility)
+    end
 
-    visibility = options[:visibility] || account.user&.setting_default_privacy
-    visibility = reblogged_status.visibility if reblogged_status.hidden?
-    reblog = account.statuses.create!(reblog: reblogged_status, text: '', visibility: visibility)
+    if !options[:distribute] && account&.user&.boost_interval?
+      QueuedBoost.find_or_create_by!(account_id: account.id, status_id: reblogged_status.id) if account&.user&.boost_interval?
+    elsif !options[:nodistribute]
+      return reblog unless options[:distribute] || new_reblog
 
-    DistributionWorker.perform_async(reblog.id)
+      DistributionWorker.perform_async(reblog.id)
 
-    unless reblogged_status.local_only?
-      ActivityPub::DistributionWorker.perform_async(reblog.id)
-    end
+      unless reblogged_status.local_only?
+        ActivityPub::DistributionWorker.perform_async(reblog.id)
+      end
 
-    curate_status(reblogged_status)
-    create_notification(reblog) unless options[:skip_notify]
-    bump_potential_friendship(account, reblog)
+      curate_status(reblogged_status)
+
+      create_notification(reblog) unless options[:skip_notify]
+      bump_potential_friendship(account, reblog)
+    end
 
     reblog
   end
diff --git a/app/services/remove_status_service.rb b/app/services/remove_status_service.rb
index d55ecadef..f9f20aae5 100644
--- a/app/services/remove_status_service.rb
+++ b/app/services/remove_status_service.rb
@@ -17,6 +17,7 @@ class RemoveStatusService < BaseService
 
     RedisLock.acquire(lock_options) do |lock|
       if lock.acquired?
+        remove_from_queued
         remove_from_self if status.account.local?
         remove_from_followers
         remove_from_lists
@@ -46,6 +47,11 @@ class RemoveStatusService < BaseService
 
   private
 
+  def remove_from_queued
+    QueuedBoost.where(account_id: @account.id, status_id: @status.proper.id).destroy_all
+    QueuedBoost.where(status_id: @status.id).destroy_all
+  end
+
   def remove_from_self
     FeedManager.instance.unpush_from_home(@account, @status)
   end