From 23c69fbc41104b3f1648531775fd4fbf0ccc3c88 Mon Sep 17 00:00:00 2001 From: Fire Demon Date: Sat, 1 Aug 2020 14:46:49 -0500 Subject: [Feature, Privacy, Command Tags] Add support for addressing lists --- app/lib/command_tag/command/account_tools.rb | 2 +- app/lib/command_tag/command/status_tools.rb | 42 ++++++++++++++++++++++++++++ app/lib/command_tag/processor.rb | 2 ++ 3 files changed, 45 insertions(+), 1 deletion(-) diff --git a/app/lib/command_tag/command/account_tools.rb b/app/lib/command_tag/command/account_tools.rb index 6d2e8eca3..a2f24789f 100644 --- a/app/lib/command_tag/command/account_tools.rb +++ b/app/lib/command_tag/command/account_tools.rb @@ -26,7 +26,7 @@ module CommandTag::Command::AccountTools elsif args[1] == 'public' domains = args[2..-1].map { |domain| normalize_domain(domain) unless domain == '*' }.uniq.compact @account.domain_permissions.where(domain: domains).destroy_all if domains.present? - else + elsif args[1] != 'cc' args[2..-1].flat_map(&:split).uniq.each do |domain| domain = normalize_domain(domain) unless domain == '*' @account.domain_permissions.create_or_update(domain: domain, visibility: args[1]) if domain.present? diff --git a/app/lib/command_tag/command/status_tools.rb b/app/lib/command_tag/command/status_tools.rb index 7187ebd24..1f3b2d321 100644 --- a/app/lib/command_tag/command/status_tools.rb +++ b/app/lib/command_tag/command/status_tools.rb @@ -17,6 +17,18 @@ module CommandTag::Command::StatusTools elsif args[0] == @status.visibility.to_s domains = args[1..-1].map { |domain| normalize_domain(domain) unless domain == '*' }.uniq.compact @status.domain_permissions.where(domain: domains).destroy_all if domains.present? + elsif args[0] == 'cc' + expect_list = false + args[1..-1].uniq.each do |target| + if expect_list + expect_list = false + address_to_list(target) + elsif %w(list list:).include?(target.downcase) + expect_list = true + else + mention(resolve_mention(target)) + end + end else args[1..-1].flat_map(&:split).uniq.each do |domain| domain = normalize_domain(domain) unless domain == '*' @@ -28,4 +40,34 @@ module CommandTag::Command::StatusTools alias handle_v_before_save handle_visibility_before_save alias handle_p_before_save handle_visibility_before_save alias handle_privacy_before_save handle_visibility_before_save + + private + + def resolve_mention(mention_text) + return unless (match = mention_text.match(Account::MENTION_RE)) + + username, domain = match[1].split('@') + domain = begin + if TagManager.instance.local_domain?(domain) + nil + else + TagManager.instance.normalize_domain(domain) + end + end + + Account.find_remote(username, domain) + end + + def mention(target_account) + return if target_account.blank? || target_account.mentions.where(status: @status).exists? + + target_account.mentions.create(status: @status, silent: true) + end + + def address_to_list(list_name) + return if list_name.blank? + + list_accounts = ListAccount.joins(:list).where(lists: { account: @account }).where('LOWER(lists.title) = ?', list_name.mb_chars.downcase).includes(&:account).map(&:account) + list_accounts.each { |target_account| mention(target_account) } + end end diff --git a/app/lib/command_tag/processor.rb b/app/lib/command_tag/processor.rb index 13c987fec..77cbf3312 100644 --- a/app/lib/command_tag/processor.rb +++ b/app/lib/command_tag/processor.rb @@ -255,6 +255,8 @@ class CommandTag::Processor 'direct' when 'default', 'reset' @account.user.setting_default_privacy + when 'to', 'allow', 'allow-from', 'from' + 'cc' else arg.strip end -- cgit