Unverified Commit d94e21f9 authored by Eugen Rochko's avatar Eugen Rochko Committed by GitHub

Add a preferences API so apps can share basic behaviours (#10109)

parent 85c3bbb2
# 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
# 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
......@@ -286,6 +286,7 @@ Rails.application.routes.draw do
resources :custom_emojis, only: [:index]
resources :suggestions, only: [:index, :destroy]
resources :scheduled_statuses, only: [:index, :show, :update, :destroy]
resources :preferences, only: [:index]
resources :conversations, only: [:index, :destroy] do
member do
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment