diff --git a/app/controllers/api/v1/statuses_controller.rb b/app/controllers/api/v1/statuses_controller.rb index 44ae3aae19c2e9..b3aaafe82cf930 100644 --- a/app/controllers/api/v1/statuses_controller.rb +++ b/app/controllers/api/v1/statuses_controller.rb @@ -49,7 +49,9 @@ def context loaded_descendants = cache_collection(descendants_results, Status) loaded_references = cache_collection(references_results, Status) - unless params[:with_reference] + if params[:with_reference] + loaded_references.reject! { |status| loaded_ancestors.any? { |ancestor| ancestor.id == status.id } } + else loaded_ancestors = (loaded_ancestors + loaded_references).uniq(&:id) loaded_references = [] end diff --git a/spec/controllers/api/v1/statuses_controller_spec.rb b/spec/controllers/api/v1/statuses_controller_spec.rb index 952a2e3b4045dd..28f1d9d58ea13b 100644 --- a/spec/controllers/api/v1/statuses_controller_spec.rb +++ b/spec/controllers/api/v1/statuses_controller_spec.rb @@ -97,15 +97,34 @@ describe 'GET #context' do let(:scopes) { 'read:statuses' } let(:status) { Fabricate(:status, account: user.account) } - - before do - Fabricate(:status, account: user.account, thread: status) - end + let!(:thread) { Fabricate(:status, account: user.account, thread: status) } it 'returns http success' do get :context, params: { id: status.id } expect(response).to have_http_status(200) end + + context 'when has also reference' do + before do + Fabricate(:status_reference, status: thread, target_status: status) + end + + it 'returns unique ancestors' do + get :context, params: { id: thread.id } + status_ids = body_as_json[:ancestors].map { |ref| ref[:id].to_i } + + expect(status_ids).to eq [status.id] + end + + it 'returns unique references' do + get :context, params: { id: thread.id, with_reference: true } + ancestor_status_ids = body_as_json[:ancestors].map { |ref| ref[:id].to_i } + reference_status_ids = body_as_json[:references].map { |ref| ref[:id].to_i } + + expect(ancestor_status_ids).to eq [status.id] + expect(reference_status_ids).to eq [] + end + end end context 'with reference' do