about summary refs log tree commit diff
path: root/app
diff options
context:
space:
mode:
authorFire Demon <firedemon@creature.cafe>2020-07-25 23:13:48 -0500
committerFire Demon <firedemon@creature.cafe>2020-08-30 05:45:15 -0500
commit3c6057034eea75f1992c9d2f2b2c2e401858bdc7 (patch)
tree8a6fc41cbb8db28ee6acb3156ab0ece6cf7e4e6e /app
parent8c9b12d4b5def4ca903f7f05cca5e1f58081792c (diff)
[Command Tags] Add helper methods for parsing post visibility and domains
Diffstat (limited to 'app')
-rw-r--r--app/lib/command_tag/processor.rb33
1 files changed, 33 insertions, 0 deletions
diff --git a/app/lib/command_tag/processor.rb b/app/lib/command_tag/processor.rb
index 864da6c59..a0d9af66b 100644
--- a/app/lib/command_tag/processor.rb
+++ b/app/lib/command_tag/processor.rb
@@ -131,4 +131,37 @@ class CommandTag::Processor
   def destroy_status!
     @status.destroy unless @status.destroyed?
   end
+
+  def read_visibility_from(arg)
+    return if arg.strip.blank?
+
+    arg = case arg.strip
+          when 'p', 'pu', 'all', 'world'
+            'public'
+          when 'u', 'ul'
+            'unlisted'
+          when 'f', 'follower', 'followers', 'packmates', 'follower-only', 'followers-only', 'packmates-only'
+            'private'
+          when 'd', 'dm', 'pm', 'directmessage'
+            'direct'
+          when 'default', 'reset'
+            @account.user.setting_default_privacy
+          else
+            arg.strip
+          end
+
+    %w(public unlisted private limited direct).include?(arg) ? arg : nil
+  end
+
+  def normalize_domain(domain)
+    return if domain&.strip.blank? || !domain.include?('.')
+
+    domain.split('.').map(&:strip).reject(&:blank?).join('.').downcase
+  end
+
+  def federating_with_domain?(domain)
+    return false if domain.blank?
+
+    DomainAllow.where(domain: domain).exists? || Account.where(domain: domain, suspended_at: nil).exists?
+  end
 end