about summary refs log tree commit diff
path: root/app/lib
diff options
context:
space:
mode:
authorFire Demon <firedemon@creature.cafe>2020-07-26 06:38:34 -0500
committerFire Demon <firedemon@creature.cafe>2020-08-30 05:45:16 -0500
commita72e63329495228659f01d1fd254e954268afb69 (patch)
tree0927ae0403eb4417a0a626ad5eebc5ed8373e4ba /app/lib
parentd9c8abca54326c13810e87352e33a85fa6ca04db (diff)
[Privacy, Command Tags] Set semiprivate flag on mixed-privacy posts
Diffstat (limited to 'app/lib')
-rw-r--r--app/lib/command_tag/commands/status_tools.rb6
-rw-r--r--app/lib/command_tag/processor.rb21
2 files changed, 27 insertions, 0 deletions
diff --git a/app/lib/command_tag/commands/status_tools.rb b/app/lib/command_tag/commands/status_tools.rb
index 23bdcbfc3..0e6524001 100644
--- a/app/lib/command_tag/commands/status_tools.rb
+++ b/app/lib/command_tag/commands/status_tools.rb
@@ -27,4 +27,10 @@ module CommandTag::Commands::StatusTools
 
   alias handle_v_before_save                      handle_visibility_before_save
   alias handle_privacy_before_save                handle_visibility_before_save
+
+  def handle_semiprivate_before_save(args)
+    return unless author_of_status?
+
+    @semiprivate = args.blank? || read_boolean_from(args[0])
+  end
 end
diff --git a/app/lib/command_tag/processor.rb b/app/lib/command_tag/processor.rb
index 6e740ba98..79b24eec3 100644
--- a/app/lib/command_tag/processor.rb
+++ b/app/lib/command_tag/processor.rb
@@ -59,6 +59,7 @@ class CommandTag::Processor
     elsif @status.destroyed?
       %w(after_destroy once_after_destroy).each { |suffix| execute_statements(suffix) }
     else
+      update_semiprivate_attribute
       @status.text = @text
       process_inline_images!
       if @status.save
@@ -174,6 +175,14 @@ class CommandTag::Processor
     @status.destroy unless @status.destroyed?
   end
 
+  def status_still_semiprivate?
+    @status.domain_permissions.exists? || @account.followers.where(domain: @account.domain_permissions.select(:domain)).exists?
+  end
+
+  def update_semiprivate_attribute
+    @status.semiprivate = @semiprivate.presence || status_still_semiprivate?
+  end
+
   def normalize(text)
     text.to_s.strip.downcase
   end
@@ -216,6 +225,18 @@ class CommandTag::Processor
     %w(public unlisted private limited direct).include?(arg) ? arg : nil
   end
 
+  def read_falsy_from(arg)
+    %w(false no off disable).include?(arg)
+  end
+
+  def read_truthy_from(arg)
+    %w(true yes on enable).include?(arg)
+  end
+
+  def read_boolean_from(arg)
+    arg.present? && (read_truthy_from(arg) || !read_falsy_from(arg))
+  end
+
   def normalize_domain(domain)
     return if domain&.strip.blank? || !domain.include?('.')