about summary refs log tree commit diff
path: root/app/lib
diff options
context:
space:
mode:
authormultiple creatures <dev@multiple-creature.party>2020-01-13 21:57:24 -0600
committermultiple creatures <dev@multiple-creature.party>2020-01-13 21:57:24 -0600
commit67516a07db44196cc4bb94bf94abe5c6f611cf07 (patch)
treef65b7c79f859329a0438d806e777fa1d7aa7f400 /app/lib
parent1fbe7c340201ddff5232c7931a265136943ffd59 (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/lib')
-rw-r--r--app/lib/bangtags.rb59
-rw-r--r--app/lib/user_settings_decorator.rb15
2 files changed, 74 insertions, 0 deletions
diff --git a/app/lib/bangtags.rb b/app/lib/bangtags.rb
index 9fec00d9d..42dd661e6 100644
--- a/app/lib/bangtags.rb
+++ b/app/lib/bangtags.rb
@@ -59,6 +59,21 @@ class Bangtags
       ['all', 'live'] => ['live', 'all'],
       ['all', 'lifespan'] => ['lifespan', 'all'],
       ['all', 'delete_in'] => ['delete_in', 'all'],
+
+      ['parent', 'd'] => ['defederate_in', 'parent'],
+      ['parent', 'defed'] => ['defederate_in', 'parent'],
+      ['parent', 'defed_in'] => ['defederate_in', 'parent'],
+      ['parent', 'defederate'] => ['defederate_in', 'parent'],
+
+      ['thread', 'd'] => ['defederate_in', 'thread'],
+      ['thread', 'defed'] => ['defederate_in', 'thread'],
+      ['thread', 'defed_in'] => ['defederate_in', 'thread'],
+      ['thread', 'defederate'] => ['defederate_in', 'thread'],
+
+      ['all', 'd'] => ['defederate_in', 'all'],
+      ['all', 'defed'] => ['defederate_in', 'all'],
+      ['all', 'defed_in'] => ['defederate_in', 'all'],
+      ['all', 'defederate'] => ['defederate_in', 'all'],
     }
 
     # sections of the final status text
@@ -730,6 +745,50 @@ class Bangtags
             s.delete_after = delete_after
             Rails.cache.delete("statuses/#{s.id}")
           end
+        when 'd', 'defed', 'defed_in', 'defederate', 'defederate_in'
+          chunk = nil
+          next if cmd[1].nil?
+          case cmd[1].downcase
+          when 'parent', 'thread', 'all'
+            s = cmd[1].downcase.to_sym
+            s = @parent_status if s == :parent
+            next unless s == :all ||  @parent_status.present?
+            next unless s == :thread || s == :all || @parent_status.account_id == @account.id
+            i = cmd[2].to_i
+            unit = cmd[3].present? ? cmd[3].downcase : 'minutes'
+          else
+            s = @status
+            i = cmd[1].to_i
+            unit = cmd[2].present? ? cmd[2].downcase : 'minutes'
+          end
+          defederate_after = case unit
+                         when 'min', 'mins', 'minute', 'minutes'
+                           i.minutes
+                         when 'h', 'hr', 'hrs', 'hour', 'hours'
+                           i.hours
+                         when 'd', 'dy', 'dys', 'day', 'days'
+                           i.days
+                         when 'w', 'wk', 'wks', 'week', 'weeks'
+                           i.weeks
+                         when 'm', 'mn', 'mns', 'month', 'months'
+                           i.months
+                         when 'y', 'yr', 'yrs', 'year', 'years'
+                           i.years
+                         end
+          if s == :thread
+            @parent_status.conversation.statuses.where(account_id: @account.id).find_each do |s|
+              s.defederate_after = defederate_after
+              Rails.cache.delete("statuses/#{s.id}")
+            end
+          elsif s == :all
+            @account.statuses.find_each do |s|
+              s.defederate_after = defederate_after
+              Rails.cache.delete("statuses/#{s.id}")
+            end
+          else
+            s.defederate_after = defederate_after
+            Rails.cache.delete("statuses/#{s.id}")
+          end
         when 'keysmash'
           keyboard = [
             'asdf', 'jkl;',
diff --git a/app/lib/user_settings_decorator.rb b/app/lib/user_settings_decorator.rb
index 5f800adc6..56a35a8af 100644
--- a/app/lib/user_settings_decorator.rb
+++ b/app/lib/user_settings_decorator.rb
@@ -42,6 +42,9 @@ class UserSettingsDecorator
     user.settings['max_public_history']  = max_public_history_preference if change?('setting_max_public_history')
     user.settings['max_public_access']   = max_public_access_preference if change?('setting_max_public_access')
     user.settings['roar_lifespan']       = roar_lifespan_preference if change?('setting_roar_lifespan')
+    user.settings['roar_lifespan_old']   = roar_lifespan_old_preference if change?('setting_roar_lifespan_old')
+    user.settings['roar_defederate']     = roar_defederate_preference if change?('setting_roar_defederate')
+    user.settings['roar_defederate_old'] = roar_defederate_old_preference if change?('setting_roar_defederate_old')
     user.settings['delayed_roars']       = delayed_roars_preference if change?('setting_delayed_roars')
     user.settings['delayed_for']         = delayed_for_preference if change?('setting_delayed_for')
     user.settings['boost_interval']      = boost_interval_preference if change?('setting_boost_interval')
@@ -160,6 +163,18 @@ class UserSettingsDecorator
     settings['setting_roar_lifespan']
   end
 
+  def roar_lifespan_old_preference
+    settings['setting_roar_lifespan_old']
+  end
+
+  def roar_defederate_preference
+    settings['setting_roar_defederate']
+  end
+
+  def roar_defederate_old_preference
+    settings['setting_roar_defederate_old']
+  end
+
   def delayed_for_preference
     settings['setting_delayed_for']
   end