about summary refs log tree commit diff
path: root/app/lib
diff options
context:
space:
mode:
authorFire Demon <firedemon@creature.cafe>2020-07-25 23:24:26 -0500
committerFire Demon <firedemon@creature.cafe>2020-08-30 05:45:15 -0500
commit173ec3d8c765239aa54c12d8a06e7dc404a1ac9d (patch)
treed4ecc46a566a8b13814173079cc77f1214c1e7b2 /app/lib
parentc4dd1074fcdeba84c812feec70d757bae0456fdd (diff)
[Feature, Privacy, Command Tags] Add text commands for per-domain post privacy
Diffstat (limited to 'app/lib')
-rw-r--r--app/lib/command_tag/commands/account_tools.rb37
-rw-r--r--app/lib/command_tag/commands/status_tools.rb28
2 files changed, 52 insertions, 13 deletions
diff --git a/app/lib/command_tag/commands/account_tools.rb b/app/lib/command_tag/commands/account_tools.rb
new file mode 100644
index 000000000..3d9fb6d4e
--- /dev/null
+++ b/app/lib/command_tag/commands/account_tools.rb
@@ -0,0 +1,37 @@
+# frozen_string_literal: true
+module CommandTag::Commands::AccountTools
+  def handle_account_at_start(args)
+    return if args[0].blank?
+
+    case args[0].downcase
+    when 'set'
+      handle_account_set(args[1..-1])
+    end
+  end
+
+  alias handle_acct_at_start handle_account_at_start
+
+  private
+
+  def handle_account_set(args)
+    return if args[0].blank?
+
+    case args[0].downcase
+    when 'v', 'visibility', 'privacy', 'default-visibility', 'default-privacy'
+      args[1] = read_visibility_from(args[1])
+      return if args[1].blank?
+
+      if args[2].blank?
+        @account.user.settings.default_privacy = args[1]
+      elsif args[1] == 'public'
+        domains = args[2..-1].map { |domain| normalize_domain(domain) }.uniq.compact
+        @account.domain_permissions.where(domain: domains).destroy_all if domains.present?
+      else
+        args[2..-1].flat_map(&:split).uniq.each do |domain|
+          domain = normalize_domain(domain)
+          @account.domain_permissions.create_or_update(domain: domain, visibility: args[1]) if domain.present?
+        end
+      end
+    end
+  end
+end
diff --git a/app/lib/command_tag/commands/status_tools.rb b/app/lib/command_tag/commands/status_tools.rb
index f8b8f8ae0..23bdcbfc3 100644
--- a/app/lib/command_tag/commands/status_tools.rb
+++ b/app/lib/command_tag/commands/status_tools.rb
@@ -1,28 +1,30 @@
 # frozen_string_literal: true
-
-# rubocop:disable Layout/ExtraSpacing
 module CommandTag::Commands::StatusTools
   def handle_title_before_save(args)
-    return unless author_of_status? && !@status.published?
+    return unless author_of_status?
 
     @status.title = args[0]
   end
 
   def handle_visibility_before_save(args)
-    return unless author_of_status? && !@status.published? && args[0].present?
-
-    args[0] = 'public' if %w(p pu all world).include?(args[0])
-    args[0] = 'unlisted' if %w(u ul).include?(args[0])
-    args[0] = 'private' if %w(f followers followers-only packmates packmates-only).include?(args[0])
-    args[0] = 'limited' if %w(l limit).include?(args[0])
-    args[0] = 'direct' if %w(d dm pm directmessage).include?(args[0])
+    return unless author_of_status? && args[0].present?
 
-    return unless %w(public unlisted private limited direct).include?(args[0])
+    args[0] = read_visibility_from(args[0])
+    return if args[0].blank?
 
-    @status.visibility = args[0].to_sym
+    if args[1].blank?
+      @status.visibility = args[0].to_sym
+    elsif args[0] == @status.visibility.to_s
+      domains = args[1..-1].map { |domain| normalize_domain(domain) }.uniq.compact
+      @status.domain_permissions.where(domain: domains).destroy_all if domains.present?
+    else
+      args[1..-1].flat_map(&:split).uniq.each do |domain|
+        domain = normalize_domain(domain)
+        @status.domain_permissions.create_or_update(domain: domain, visibility: args[0]) if domain.present?
+      end
+    end
   end
 
   alias handle_v_before_save                      handle_visibility_before_save
   alias handle_privacy_before_save                handle_visibility_before_save
 end
-# rubocop:enable Layout/ExtraSpacing