about summary refs log tree commit diff
path: root/app/lib/command_tag/command/parent_status_tools.rb
blob: 2fdee2fb8688b02278cf73590732543f0f47bbfb (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
# frozen_string_literal: true
module CommandTag::Command::ParentStatusTools
  def handle_publish_once_at_end(_)
    is_blank = status_text_blank?
    return PublishStatusService.new.call(@status) if @parent.blank? || !is_blank
    return unless is_blank && author_of_parent? && !@parent.published?

    PublishStatusService.new.call(@parent)
  end

  alias handle_publish_post_once_at_end                   handle_publish_once_at_end
  alias handle_publish_roar_once_at_end                   handle_publish_once_at_end
  alias handle_publish_toot_once_at_end                   handle_publish_once_at_end

  def handle_edit_once_before_save(_)
    return unless author_of_parent?

    params = @parent.slice(*UpdateStatusService::ALLOWED_ATTRIBUTES).with_indifferent_access.compact
    params[:text] = @text
    UpdateStatusService.new.call(@parent, params)
    destroy_status!
  end

  alias handle_edit_post_once_before_save                 handle_edit_once_before_save
  alias handle_edit_roar_once_before_save                 handle_edit_once_before_save
  alias handle_edit_toot_once_before_save                 handle_edit_once_before_save
  alias handle_edit_parent_once_before_save               handle_edit_once_before_save

  def handle_mute_once_at_end(_)
    return if author_of_parent?

    MuteStatusService.new.call(@account, @parent)
  end

  alias handle_mute_post_once_at_end                      handle_mute_once_at_end
  alias handle_mute_roar_once_at_end                      handle_mute_once_at_end
  alias handle_mute_toot_once_at_end                      handle_mute_once_at_end
  alias handle_mute_parent_once_at_end                    handle_mute_once_at_end
  alias handle_hide_once_at_end                           handle_mute_once_at_end
  alias handle_hide_post_once_at_end                      handle_mute_once_at_end
  alias handle_hide_roar_once_at_end                      handle_mute_once_at_end
  alias handle_hide_toot_once_at_end                      handle_mute_once_at_end
  alias handle_hide_parent_once_at_end                    handle_mute_once_at_end

  def handle_unmute_once_at_end(_)
    return if author_of_parent?

    @account.unmute_status!(@parent)
  end

  alias handle_unmute_post_once_at_end                    handle_unmute_once_at_end
  alias handle_unmute_roar_once_at_end                    handle_unmute_once_at_end
  alias handle_unmute_toot_once_at_end                    handle_unmute_once_at_end
  alias handle_unmute_parent_once_at_end                  handle_unmute_once_at_end
  alias handle_unhide_once_at_end                         handle_unmute_once_at_end
  alias handle_unhide_post_once_at_end                    handle_unmute_once_at_end
  alias handle_unhide_roar_once_at_end                    handle_unmute_once_at_end
  alias handle_unhide_toot_once_at_end                    handle_unmute_once_at_end
  alias handle_unhide_parent_once_at_end                  handle_unmute_once_at_end

  def handle_mute_thread_once_at_end(_)
    return if author_of_parent?

    MuteConversationService.new.call(@account, @conversation)
  end

  alias handle_mute_conversation_once_at_end              handle_mute_thread_once_at_end
  alias handle_hide_thread_once_at_end                    handle_mute_thread_once_at_end
  alias handle_hide_conversation_once_at_end              handle_mute_thread_once_at_end

  def handle_unmute_thread_once_at_end(_)
    return if author_of_parent? || @conversation.blank?

    @account.unmute_conversation!(@conversation)
  end

  alias handle_unmute_conversation_once_at_end            handle_unmute_thread_once_at_end
  alias handle_unhide_thread_once_at_end                  handle_unmute_thread_once_at_end
  alias handle_unhide_conversation_once_at_end            handle_unmute_thread_once_at_end
end