Skip to content

Commit

Permalink
Add visibility parameter in share page (mastodon#13023)
Browse files Browse the repository at this point in the history
* Add visibility parameter in share page

* Restrict to default privacy
  • Loading branch information
noellabo authored and Mage committed Jan 14, 2022
1 parent ca5c68f commit 974ba91
Show file tree
Hide file tree
Showing 3 changed files with 7 additions and 2 deletions.
5 changes: 5 additions & 0 deletions app/helpers/application_helper.rb
Original file line number Diff line number Diff line change
Expand Up @@ -142,6 +142,11 @@ def render_initial_state
text: [params[:title], params[:text], params[:url]].compact.join(' '),
}

permit_visibilities = %w(public unlisted private direct)
default_privacy = current_account&.user&.setting_default_privacy
permit_visibilities.shift(permit_visibilities.index(default_privacy) + 1) if default_privacy.present?
state_params[:visibility] = params[:visibility] if permit_visibilities.include? params[:visibility]

if user_signed_in?
state_params[:settings] = state_params[:settings].merge(Web::Setting.find_by(user: current_user)&.data || {})
state_params[:push_subscription] = current_account.user.web_push_subscription(current_session)
Expand Down
2 changes: 1 addition & 1 deletion app/presenters/initial_state_presenter.rb
Original file line number Diff line number Diff line change
Expand Up @@ -2,5 +2,5 @@

class InitialStatePresenter < ActiveModelSerializers::Model
attributes :settings, :push_subscription, :token,
:current_account, :admin, :text, :pawoo
:current_account, :admin, :text, :visibility, :pawoo
end
2 changes: 1 addition & 1 deletion app/serializers/initial_state_serializer.rb
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ def compose

if object.current_account
store[:me] = object.current_account.id.to_s
store[:default_privacy] = object.current_account.user.setting_default_privacy
store[:default_privacy] = object.visibility || object.current_account.user.setting_default_privacy
store[:default_sensitive] = object.current_account.user.setting_default_sensitive
end

Expand Down

0 comments on commit 974ba91

Please sign in to comment.