<commit_before># frozen_string_literal: true

class RemoveStatusService < BaseService
  include Redisable
  include Payloadable

  # Delete a status
  # @param   [Status] status
  # @param   [Hash] options
  # @option  [Boolean] :redraft
  # @option  [Boolean] :immediate
  # @option  [Boolean] :preserve
  # @option  [Boolean] :original_removed
  def call(status, **options)
    @payload  = Oj.dump(event: :delete, payload: status.id.to_s)
    @status   = status
    @account  = status.account
    @options  = options

    @status.discard

    RedisLock.acquire(lock_options) do |lock|
      if lock.acquired?
        remove_from_self if @account.local?
        remove_from_followers
        remove_from_lists

        # There is no reason to send out Undo activities when the
        # cause is that the original object has been removed, since
        # original object being removed implicitly removes reblogs
        # of it. The Delete activity of the original is forwarded
        # separately.
        remove_from_remote_reach if @account.local? && !@options[:original_removed]

        # Since reblogs don't mention anyone, don't get reblogged,
        # favourited and don't contain their own media attachments
        # or hashtags, this can be skipped
        unless @status.reblog?
          remove_from_mentions
          remove_reblogs
          remove_from_hashtags
          remove_from_public
          remove_from_media if @status.with_media?<commit_msg>Fix inconsistency in error handling when removing a status (#17974)<commit_after># frozen_string_literal: true

class RemoveStatusService < BaseService
  include Redisable
  include Payloadable

  # Delete a status
  # @param   [Status] status
  # @param   [Hash] options
  # @option  [Boolean] :redraft
  # @option  [Boolean] :immediate
  # @option  [Boolean] :preserve
  # @option  [Boolean] :original_removed
  def call(status, **options)
    @payload  = Oj.dump(event: :delete, payload: status.id.to_s)
    @status   = status
    @account  = status.account
    @options  = options

    RedisLock.acquire(lock_options) do |lock|
      if lock.acquired?
        @status.discard

        remove_from_self if @account.local?
        remove_from_followers
        remove_from_lists

        # There is no reason to send out Undo activities when the
        # cause is that the original object has been removed, since
        # original object being removed implicitly removes reblogs
        # of it. The Delete activity of the original is forwarded
        # separately.
        remove_from_remote_reach if @account.local? && !@options[:original_removed]

        # Since reblogs don't mention anyone, don't get reblogged,
        # favourited and don't contain their own media attachments
        # or hashtags, this can be skipped
        unless @status.reblog?
          remove_from_mentions
          remove_reblogs
          remove_from_hashtags
          remove_from_public
          remove_from_media if @status.with_media?
{'fraction_non_alphanumeric': 0.06962025316455696, 'fraction_numerical': 0.0016655562958027982, 'mean_word_length': 2.8206106870229006, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, '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': '4609761', 'n_tokens_mistral': 875, 'n_tokens_neox': 833, 'n_words': 268}