<commit_before># frozen_string_literal: true

class ProcessMentionsService < BaseService
  include StreamEntryRenderer

  # Scan status for mentions and fetch remote mentioned users, create
  # local mention pointers, send Salmon notifications to mentioned
  # remote users
  # @param [Status] status
  def call(status)
    return unless status.local?

    status.text.scan(Account::MENTION_RE).each do |match|
      begin
        mentioned_account = resolve_remote_account_service.call(match.first.to_s)
      rescue Goldfinger::Error, HTTP::Error
        mentioned_account = nil
      end

      next if mentioned_account.nil?

      mentioned_account.mentions.where(status: status).first_or_create(status: status)
    end

    status.mentions.includes(:account).each do |mention|
      create_notification(status, mention)
    end
  end

  private

  def create_notification(status, mention)
    mentioned_account = mention.account

    if mentioned_account.local?
      NotifyService.new.call(mentioned_account, mention)
    elsif mentioned_account.ostatus? && !status.stream_entry.hidden?
      NotificationWorker.perform_async(stream_entry_to_xml(status.stream_entry), status.account_id, mentioned_account.id)<commit_msg>Do not process undeliverable mentions (#5598)<commit_after># frozen_string_literal: true

class ProcessMentionsService < BaseService
  include StreamEntryRenderer

  # Scan status for mentions and fetch remote mentioned users, create
  # local mention pointers, send Salmon notifications to mentioned
  # remote users
  # @param [Status] status
  def call(status)
    return unless status.local?

    status.text.scan(Account::MENTION_RE).each do |match|
      begin
        mentioned_account = resolve_remote_account_service.call(match.first.to_s)
      rescue Goldfinger::Error, HTTP::Error
        mentioned_account = nil
      end

      next if mentioned_account.nil? || (mentioned_account.ostatus? && status.stream_entry.hidden?)

      mentioned_account.mentions.where(status: status).first_or_create(status: status)
    end

    status.mentions.includes(:account).each do |mention|
      create_notification(status, mention)
    end
  end

  private

  def create_notification(status, mention)
    mentioned_account = mention.account

    if mentioned_account.local?
      NotifyService.new.call(mentioned_account, mention)
    elsif mentioned_account.ostatus? && !status.stream_entry.hidden?
      NotificationWorker.perform_async(stream_entry_to_xml(status.stream_entry), status.account_id, mentioned_account.id)
{'fraction_non_alphanumeric': 0.07767752059631228, 'fraction_numerical': 0.001569242840329541, 'mean_word_length': 4.301455301455301, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 2}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '7575826', 'n_tokens_mistral': 729, 'n_tokens_neox': 691, 'n_words': 162}