Add backend support for local_only on status create
Based off ThibG implementation on glitch #502
This commit is contained in:
parent
4969ea4f2c
commit
f37ca30ea1
@ -52,7 +52,8 @@ class Api::V1::StatusesController < Api::BaseController
|
|||||||
spoiler_text: status_params[:spoiler_text],
|
spoiler_text: status_params[:spoiler_text],
|
||||||
visibility: status_params[:visibility],
|
visibility: status_params[:visibility],
|
||||||
application: doorkeeper_token.application,
|
application: doorkeeper_token.application,
|
||||||
idempotency: request.headers['Idempotency-Key'])
|
idempotency: request.headers['Idempotency-Key'],
|
||||||
|
local_only: status_params[:local_only])
|
||||||
|
|
||||||
render json: @status, serializer: REST::StatusSerializer
|
render json: @status, serializer: REST::StatusSerializer
|
||||||
end
|
end
|
||||||
@ -77,7 +78,7 @@ class Api::V1::StatusesController < Api::BaseController
|
|||||||
end
|
end
|
||||||
|
|
||||||
def status_params
|
def status_params
|
||||||
params.permit(:status, :in_reply_to_id, :sensitive, :spoiler_text, :visibility, media_ids: [])
|
params.permit(:status, :in_reply_to_id, :sensitive, :spoiler_text, :visibility, :local_only, media_ids: [])
|
||||||
end
|
end
|
||||||
|
|
||||||
def pagination_params(core_params)
|
def pagination_params(core_params)
|
||||||
|
@ -130,6 +130,10 @@ class Status < ApplicationRecord
|
|||||||
attributes['local'] || uri.nil?
|
attributes['local'] || uri.nil?
|
||||||
end
|
end
|
||||||
|
|
||||||
|
def local_only?
|
||||||
|
local_only
|
||||||
|
end
|
||||||
|
|
||||||
def reblog?
|
def reblog?
|
||||||
!reblog_of_id.nil?
|
!reblog_of_id.nil?
|
||||||
end
|
end
|
||||||
@ -222,6 +226,8 @@ class Status < ApplicationRecord
|
|||||||
|
|
||||||
around_create Mastodon::Snowflake::Callbacks
|
around_create Mastodon::Snowflake::Callbacks
|
||||||
|
|
||||||
|
before_create :set_locality
|
||||||
|
|
||||||
before_validation :prepare_contents, if: :local?
|
before_validation :prepare_contents, if: :local?
|
||||||
before_validation :set_reblog
|
before_validation :set_reblog
|
||||||
before_validation :set_visibility
|
before_validation :set_visibility
|
||||||
@ -445,6 +451,10 @@ class Status < ApplicationRecord
|
|||||||
self.local = account.local?
|
self.local = account.local?
|
||||||
end
|
end
|
||||||
|
|
||||||
|
def set_locality
|
||||||
|
self.local_only = reblog.local_only if reblog?
|
||||||
|
end
|
||||||
|
|
||||||
def update_statistics
|
def update_statistics
|
||||||
return unless public_visibility? || unlisted_visibility?
|
return unless public_visibility? || unlisted_visibility?
|
||||||
ActivityTracker.increment('activity:statuses:local')
|
ActivityTracker.increment('activity:statuses:local')
|
||||||
|
@ -4,7 +4,7 @@ class REST::StatusSerializer < ActiveModel::Serializer
|
|||||||
attributes :id, :created_at, :in_reply_to_id, :in_reply_to_account_id,
|
attributes :id, :created_at, :in_reply_to_id, :in_reply_to_account_id,
|
||||||
:sensitive, :spoiler_text, :visibility, :language,
|
:sensitive, :spoiler_text, :visibility, :language,
|
||||||
:uri, :content, :url, :replies_count, :reblogs_count,
|
:uri, :content, :url, :replies_count, :reblogs_count,
|
||||||
:favourites_count
|
:favourites_count, :local_only
|
||||||
|
|
||||||
attribute :favourited, if: :current_user?
|
attribute :favourited, if: :current_user?
|
||||||
attribute :reblogged, if: :current_user?
|
attribute :reblogged, if: :current_user?
|
||||||
|
@ -31,7 +31,8 @@ class PostStatusService < BaseService
|
|||||||
spoiler_text: options[:spoiler_text] || '',
|
spoiler_text: options[:spoiler_text] || '',
|
||||||
visibility: options[:visibility] || account.user&.setting_default_privacy,
|
visibility: options[:visibility] || account.user&.setting_default_privacy,
|
||||||
language: language_from_option(options[:language]) || account.user&.setting_default_language&.presence || LanguageDetector.instance.detect(text, account),
|
language: language_from_option(options[:language]) || account.user&.setting_default_language&.presence || LanguageDetector.instance.detect(text, account),
|
||||||
application: options[:application])
|
application: options[:application],
|
||||||
|
local_only: local_only_option(options[:local_only], in_reply_to))
|
||||||
end
|
end
|
||||||
|
|
||||||
process_hashtags_service.call(status)
|
process_hashtags_service.call(status)
|
||||||
@ -57,6 +58,11 @@ class PostStatusService < BaseService
|
|||||||
|
|
||||||
private
|
private
|
||||||
|
|
||||||
|
def local_only_option(local_only, in_reply_to)
|
||||||
|
return in_reply_to&.local_only? if local_only.nil? # XXX temporary, just until clients implement to avoid leaking local_only posts
|
||||||
|
local_only
|
||||||
|
end
|
||||||
|
|
||||||
def validate_media!(media_ids)
|
def validate_media!(media_ids)
|
||||||
return if media_ids.blank? || !media_ids.is_a?(Enumerable)
|
return if media_ids.blank? || !media_ids.is_a?(Enumerable)
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user