forked from mastodon/mastodon
-
Notifications
You must be signed in to change notification settings - Fork 4
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add a preferences API so apps can share basic behaviours (mastodon#10109
- Loading branch information
Showing
3 changed files
with
43 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
# frozen_string_literal: true | ||
|
||
class Api::V1::PreferencesController < Api::BaseController | ||
before_action -> { doorkeeper_authorize! :read, :'read:accounts' } | ||
before_action :require_user! | ||
|
||
respond_to :json | ||
|
||
def index | ||
render json: current_account, serializer: REST::PreferencesSerializer | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
# frozen_string_literal: true | ||
|
||
class REST::PreferencesSerializer < ActiveModel::Serializer | ||
attribute :posting_default_privacy, key: 'posting:default:visibility' | ||
attribute :posting_default_sensitive, key: 'posting:default:sensitive' | ||
attribute :posting_default_language, key: 'posting:default:language' | ||
|
||
attribute :reading_default_sensitive_media, key: 'reading:expand:media' | ||
attribute :reading_default_sensitive_text, key: 'reading:expand:spoilers' | ||
|
||
def posting_default_privacy | ||
object.user.setting_default_privacy | ||
end | ||
|
||
def posting_default_sensitive | ||
object.user.setting_default_sensitive | ||
end | ||
|
||
def posting_default_language | ||
object.user.setting_default_language.presence | ||
end | ||
|
||
def reading_default_sensitive_media | ||
object.user.setting_display_media | ||
end | ||
|
||
def reading_default_sensitive_text | ||
object.user.setting_expand_spoilers | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters