diff options
Diffstat (limited to 'app/lib/command_tag/command/status_tools.rb')
-rw-r--r-- | app/lib/command_tag/command/status_tools.rb | 42 |
1 files changed, 42 insertions, 0 deletions
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 |