about summary refs log tree commit diff
path: root/app/lib/command_tag/commands/status_tools.rb
blob: f8b8f8ae09f74cd18b9776692fbe15925f824a19 (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
# frozen_string_literal: true

# rubocop:disable Layout/ExtraSpacing
module CommandTag::Commands::StatusTools
  def handle_title_before_save(args)
    return unless author_of_status? && !@status.published?

    @status.title = args[0]
  end

  def handle_visibility_before_save(args)
    return unless author_of_status? && !@status.published? && args[0].present?

    args[0] = 'public' if %w(p pu all world).include?(args[0])
    args[0] = 'unlisted' if %w(u ul).include?(args[0])
    args[0] = 'private' if %w(f followers followers-only packmates packmates-only).include?(args[0])
    args[0] = 'limited' if %w(l limit).include?(args[0])
    args[0] = 'direct' if %w(d dm pm directmessage).include?(args[0])

    return unless %w(public unlisted private limited direct).include?(args[0])

    @status.visibility = args[0].to_sym
  end

  alias handle_v_before_save                      handle_visibility_before_save
  alias handle_privacy_before_save                handle_visibility_before_save
end
# rubocop:enable Layout/ExtraSpacing