Skip to content

Commit

Permalink
Limit maximum visibility of local silenced users to unlisted (mastodo…
Browse files Browse the repository at this point in the history
  • Loading branch information
ClearlyClaire authored and hiyuki2578 committed Oct 2, 2019
1 parent 3cff963 commit 631bdd0
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 1 deletion.
5 changes: 4 additions & 1 deletion app/services/post_status_service.rb
Original file line number Diff line number Diff line change
Expand Up @@ -23,13 +23,16 @@ def call(account, text, in_reply_to = nil, **options)
status = nil
text = options.delete(:spoiler_text) if text.blank? && options[:spoiler_text].present?

visibility = options[:visibility] || account.user&.setting_default_privacy
visibility = :unlisted if visibility == :public && account.silenced

ApplicationRecord.transaction do
status = account.statuses.create!(text: text,
media_attachments: media || [],
thread: in_reply_to,
sensitive: (options[:sensitive].nil? ? account.user&.setting_default_sensitive : options[:sensitive]) || options[:spoiler_text].present?,
spoiler_text: options[:spoiler_text] || '',
visibility: options[:visibility] || account.user&.setting_default_privacy,
visibility: visibility,
language: language_from_option(options[:language]) || account.user&.setting_default_language&.presence || LanguageDetector.instance.detect(text, account),
application: options[:application])
end
Expand Down
7 changes: 7 additions & 0 deletions spec/services/post_status_service_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,13 @@
expect(status.visibility).to eq "private"
end

it 'creates a status with limited visibility for silenced users' do
status = subject.call(Fabricate(:account, silenced: true), 'test', nil, visibility: :public)

expect(status).to be_persisted
expect(status.visibility).to eq "unlisted"
end

it 'creates a status for the given application' do
application = Fabricate(:application)

Expand Down

0 comments on commit 631bdd0

Please sign in to comment.