Compare commits
5 commits
main
...
local-only
Author | SHA1 | Date | |
---|---|---|---|
920d25f8c9 | |||
578438b360 | |||
358fd2121a | |||
cb11b0ee5a | |||
bdaaddeff9 |
|
@ -42,6 +42,7 @@ class Api::V1::StatusesController < Api::BaseController
|
||||||
@status = PostStatusService.new.call(current_user.account,
|
@status = PostStatusService.new.call(current_user.account,
|
||||||
status_params[:status],
|
status_params[:status],
|
||||||
status_params[:in_reply_to_id].blank? ? nil : Status.find(status_params[:in_reply_to_id]),
|
status_params[:in_reply_to_id].blank? ? nil : Status.find(status_params[:in_reply_to_id]),
|
||||||
|
local_only: status_params[:local_only],
|
||||||
media_ids: status_params[:media_ids],
|
media_ids: status_params[:media_ids],
|
||||||
sensitive: status_params[:sensitive],
|
sensitive: status_params[:sensitive],
|
||||||
spoiler_text: status_params[:spoiler_text],
|
spoiler_text: status_params[:spoiler_text],
|
||||||
|
@ -72,7 +73,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, :local_only, :sensitive, :spoiler_text, :visibility, media_ids: [])
|
||||||
end
|
end
|
||||||
|
|
||||||
def pagination_params(core_params)
|
def pagination_params(core_params)
|
||||||
|
|
|
@ -3,7 +3,8 @@
|
||||||
class REST::StatusSerializer < ActiveModel::Serializer
|
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, :reblogs_count, :favourites_count
|
:uri, :content, :url, :reblogs_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?
|
||||||
|
|
|
@ -6,6 +6,7 @@ class PostStatusService < BaseService
|
||||||
# @param [String] text Message
|
# @param [String] text Message
|
||||||
# @param [Status] in_reply_to Optional status to reply to
|
# @param [Status] in_reply_to Optional status to reply to
|
||||||
# @param [Hash] options
|
# @param [Hash] options
|
||||||
|
# @option [Boolean] :local_only
|
||||||
# @option [Boolean] :sensitive
|
# @option [Boolean] :sensitive
|
||||||
# @option [String] :visibility
|
# @option [String] :visibility
|
||||||
# @option [String] :spoiler_text
|
# @option [String] :spoiler_text
|
||||||
|
@ -25,6 +26,7 @@ class PostStatusService < BaseService
|
||||||
ApplicationRecord.transaction do
|
ApplicationRecord.transaction do
|
||||||
status = account.statuses.create!(text: text,
|
status = account.statuses.create!(text: text,
|
||||||
thread: in_reply_to,
|
thread: in_reply_to,
|
||||||
|
local_only: options[:local_only],
|
||||||
sensitive: options[:sensitive],
|
sensitive: options[:sensitive],
|
||||||
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,
|
||||||
|
|
|
@ -35,13 +35,71 @@ RSpec.describe Api::V1::StatusesController, type: :controller do
|
||||||
end
|
end
|
||||||
|
|
||||||
describe 'POST #create' do
|
describe 'POST #create' do
|
||||||
|
context 'with local_only unspecified and no eyeball' do
|
||||||
before do
|
before do
|
||||||
post :create, params: { status: 'Hello world' }
|
post :create, params: { status: 'Hello world' }
|
||||||
end
|
end
|
||||||
|
|
||||||
|
let(:status_response) { JSON.parse(response.body) }
|
||||||
|
|
||||||
it 'returns http success' do
|
it 'returns http success' do
|
||||||
expect(response).to have_http_status(:success)
|
expect(response).to have_http_status(:success)
|
||||||
end
|
end
|
||||||
|
|
||||||
|
it 'creates a non-local-only status' do
|
||||||
|
expect(status_response["local_only"]).to be false
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
context 'with local_only unspecified and an eyeball' do
|
||||||
|
before do
|
||||||
|
post :create, params: { status: "Hello world #{Status.new.local_only_emoji}" }
|
||||||
|
end
|
||||||
|
|
||||||
|
let(:status_response) { JSON.parse(response.body) }
|
||||||
|
|
||||||
|
it 'returns http success' do
|
||||||
|
expect(response).to have_http_status(:success)
|
||||||
|
end
|
||||||
|
|
||||||
|
it 'creates a local-only status' do
|
||||||
|
expect(status_response["local_only"]).to be true
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
|
||||||
|
context 'with local_only set to true' do
|
||||||
|
before do
|
||||||
|
post :create, params: { status: 'Hello world', local_only: true }
|
||||||
|
end
|
||||||
|
|
||||||
|
let(:status_response) { JSON.parse(response.body) }
|
||||||
|
|
||||||
|
it 'returns http success' do
|
||||||
|
expect(response).to have_http_status(:success)
|
||||||
|
end
|
||||||
|
|
||||||
|
it 'creates a local-only status' do
|
||||||
|
expect(status_response["local_only"]).to be true
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
context 'with local_only set to false' do
|
||||||
|
before do
|
||||||
|
post :create, params: { status: 'Hello world', local_only: false }
|
||||||
|
end
|
||||||
|
|
||||||
|
let(:status_response) { JSON.parse(response.body) }
|
||||||
|
|
||||||
|
it 'returns http success' do
|
||||||
|
expect(response).to have_http_status(:success)
|
||||||
|
end
|
||||||
|
|
||||||
|
it 'creates a non-local-only status' do
|
||||||
|
expect(status_response["local_only"]).to be false
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
end
|
end
|
||||||
|
|
||||||
describe 'DELETE #destroy' do
|
describe 'DELETE #destroy' do
|
||||||
|
@ -59,6 +117,36 @@ RSpec.describe Api::V1::StatusesController, type: :controller do
|
||||||
expect(Status.find_by(id: status.id)).to be nil
|
expect(Status.find_by(id: status.id)).to be nil
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
describe 'the "local_only" property' do
|
||||||
|
context 'for a local-only status' do
|
||||||
|
let(:status) { Fabricate(:status, account: user.account, local_only: true) }
|
||||||
|
|
||||||
|
before do
|
||||||
|
get :show, params: { id: status.id }
|
||||||
|
end
|
||||||
|
|
||||||
|
let(:status_response) { JSON.parse(response.body) }
|
||||||
|
|
||||||
|
it 'is true' do
|
||||||
|
expect(status_response["local_only"]).to be true
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
context 'for a non-local-only status' do
|
||||||
|
let(:status) { Fabricate(:status, account: user.account, local_only: false) }
|
||||||
|
|
||||||
|
before do
|
||||||
|
get :show, params: { id: status.id }
|
||||||
|
end
|
||||||
|
|
||||||
|
let(:status_response) { JSON.parse(response.body) }
|
||||||
|
|
||||||
|
it 'is false' do
|
||||||
|
expect(status_response["local_only"]).to be false
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
context 'without an oauth token' do
|
context 'without an oauth token' do
|
||||||
|
@ -123,5 +211,34 @@ RSpec.describe Api::V1::StatusesController, type: :controller do
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
context 'with a local-only status' do
|
||||||
|
let(:status) { Fabricate(:status, account: user.account, visibility: :public, local_only: true) }
|
||||||
|
|
||||||
|
describe 'GET #show' do
|
||||||
|
it 'returns http unautharized' do
|
||||||
|
get :show, params: { id: status.id }
|
||||||
|
expect(response).to have_http_status(:missing)
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
describe 'GET #context' do
|
||||||
|
before do
|
||||||
|
Fabricate(:status, account: user.account, thread: status)
|
||||||
|
end
|
||||||
|
|
||||||
|
it 'returns http unautharized' do
|
||||||
|
get :context, params: { id: status.id }
|
||||||
|
expect(response).to have_http_status(:missing)
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
describe 'GET #card' do
|
||||||
|
it 'returns http unautharized' do
|
||||||
|
get :card, params: { id: status.id }
|
||||||
|
expect(response).to have_http_status(:missing)
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
Reference in a new issue