Rework FEP-7888 implementation (#36064)
Some checks failed
Check i18n / check-i18n (push) Waiting to run
Chromatic / Run Chromatic (push) Waiting to run
CodeQL / Analyze (javascript) (push) Waiting to run
CodeQL / Analyze (ruby) (push) Waiting to run
Check formatting / lint (push) Waiting to run
CSS Linting / lint (push) Waiting to run
JavaScript Linting / lint (push) Waiting to run
Ruby Linting / lint (push) Waiting to run
JavaScript Testing / test (push) Waiting to run
Historical data migration test / test (14-alpine) (push) Waiting to run
Historical data migration test / test (15-alpine) (push) Waiting to run
Historical data migration test / test (16-alpine) (push) Waiting to run
Historical data migration test / test (17-alpine) (push) Waiting to run
Ruby Testing / build (production) (push) Waiting to run
Ruby Testing / build (test) (push) Waiting to run
Ruby Testing / test (.ruby-version) (push) Blocked by required conditions
Ruby Testing / test (3.2) (push) Blocked by required conditions
Ruby Testing / test (3.3) (push) Blocked by required conditions
Ruby Testing / ImageMagick tests (.ruby-version) (push) Blocked by required conditions
Ruby Testing / ImageMagick tests (3.2) (push) Blocked by required conditions
Ruby Testing / ImageMagick tests (3.3) (push) Blocked by required conditions
Ruby Testing / End to End testing (.ruby-version) (push) Blocked by required conditions
Ruby Testing / End to End testing (3.2) (push) Blocked by required conditions
Ruby Testing / End to End testing (3.3) (push) Blocked by required conditions
Ruby Testing / Elastic Search integration testing (.ruby-version, docker.elastic.co/elasticsearch/elasticsearch:7.17.13) (push) Blocked by required conditions
Ruby Testing / Elastic Search integration testing (.ruby-version, docker.elastic.co/elasticsearch/elasticsearch:8.10.2) (push) Blocked by required conditions
Ruby Testing / Elastic Search integration testing (.ruby-version, opensearchproject/opensearch:2) (push) Blocked by required conditions
Ruby Testing / Elastic Search integration testing (3.2, docker.elastic.co/elasticsearch/elasticsearch:7.17.13) (push) Blocked by required conditions
Ruby Testing / Elastic Search integration testing (3.3, docker.elastic.co/elasticsearch/elasticsearch:7.17.13) (push) Blocked by required conditions
Crowdin / Upload translations / upload-translations (push) Has been cancelled

This commit is contained in:
Claire 2025-09-09 20:27:30 +02:00 committed by GitHub
parent 377e870348
commit e1dc960219
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
9 changed files with 61 additions and 25 deletions

View File

@ -26,7 +26,8 @@ class ActivityPub::ContextsController < ActivityPub::BaseController
end end
def set_conversation def set_conversation
@conversation = Conversation.local.find(params[:id]) account_id, status_id = params[:id].split('-')
@conversation = Conversation.local.find_by(parent_account_id: account_id, parent_status_id: status_id)
end end
def set_items def set_items

View File

@ -41,7 +41,7 @@ class ActivityPub::TagManager
when :person when :person
target.instance_actor? ? instance_actor_url : account_url(target) target.instance_actor? ? instance_actor_url : account_url(target)
when :conversation when :conversation
context_url(target) context_url(target) unless target.parent_account_id.nil? || target.parent_status_id.nil?
when :note, :comment, :activity when :note, :comment, :activity
return activity_account_status_url(target.account, target) if target.reblog? return activity_account_status_url(target.account, target) if target.reblog?

View File

@ -24,6 +24,10 @@ class Conversation < ApplicationRecord
before_validation :set_parent_account, on: :create before_validation :set_parent_account, on: :create
def to_param
"#{parent_account_id}-#{parent_status_id}" unless parent_account_id.nil? || parent_status_id.nil?
end
def local? def local?
uri.nil? uri.nil?
end end

View File

@ -7,7 +7,7 @@ class ActivityPub::ContextPresenter < ActiveModelSerializers::Model
def from_conversation(conversation) def from_conversation(conversation)
new.tap do |presenter| new.tap do |presenter|
presenter.id = ActivityPub::TagManager.instance.uri_for(conversation) presenter.id = ActivityPub::TagManager.instance.uri_for(conversation)
presenter.attributed_to = ActivityPub::TagManager.instance.uri_for(conversation.parent_account) presenter.attributed_to = ActivityPub::TagManager.instance.uri_for(conversation.parent_account) if conversation.parent_account.present?
end end
end end
end end

View File

@ -2,6 +2,7 @@
class ActivityPub::NoteSerializer < ActivityPub::Serializer class ActivityPub::NoteSerializer < ActivityPub::Serializer
include FormattingHelper include FormattingHelper
include JsonLdHelper
context_extensions :atom_uri, :conversation, :sensitive, :voters_count, :quotes, :interaction_policies context_extensions :atom_uri, :conversation, :sensitive, :voters_count, :quotes, :interaction_policies
@ -159,14 +160,16 @@ class ActivityPub::NoteSerializer < ActivityPub::Serializer
if object.conversation.uri? if object.conversation.uri?
object.conversation.uri object.conversation.uri
else else
OStatus::TagManager.instance.unique_tag(object.conversation.created_at, object.conversation.id, 'Conversation') # This means `parent_status_id` and `parent_account_id` must *not* get backfilled
ActivityPub::TagManager.instance.uri_for(object.conversation) || OStatus::TagManager.instance.unique_tag(object.conversation.created_at, object.conversation.id, 'Conversation')
end end
end end
def context def context
return if object.conversation.nil? return if object.conversation.nil?
ActivityPub::TagManager.instance.uri_for(object.conversation) uri = ActivityPub::TagManager.instance.uri_for(object.conversation)
uri unless unsupported_uri_scheme?(uri)
end end
def local? def local?

View File

@ -120,7 +120,7 @@ Rails.application.routes.draw do
end end
resource :inbox, only: [:create], module: :activitypub resource :inbox, only: [:create], module: :activitypub
resources :contexts, only: [:show], module: :activitypub do resources :contexts, only: [:show], module: :activitypub, constraints: { id: /[0-9]+-[0-9]+/ } do
member do member do
get :items get :items
end end

View File

@ -0,0 +1,9 @@
# frozen_string_literal: true
class AddIndexOnParentStatusIdToConversations < ActiveRecord::Migration[8.0]
disable_ddl_transaction!
def change
add_index :conversations, :parent_status_id, algorithm: :concurrently, unique: true, where: 'parent_status_id IS NOT NULL'
end
end

View File

@ -10,7 +10,7 @@
# #
# It's strongly recommended that you check this file into your version control system. # It's strongly recommended that you check this file into your version control system.
ActiveRecord::Schema[8.0].define(version: 2025_09_02_221600) do ActiveRecord::Schema[8.0].define(version: 2025_09_09_100506) do
# These are extensions that must be enabled in order to support this database # These are extensions that must be enabled in order to support this database
enable_extension "pg_catalog.plpgsql" enable_extension "pg_catalog.plpgsql"
@ -361,6 +361,7 @@ ActiveRecord::Schema[8.0].define(version: 2025_09_02_221600) do
t.datetime "updated_at", precision: nil, null: false t.datetime "updated_at", precision: nil, null: false
t.bigint "parent_status_id" t.bigint "parent_status_id"
t.bigint "parent_account_id" t.bigint "parent_account_id"
t.index ["parent_status_id"], name: "index_conversations_on_parent_status_id", unique: true, where: "(parent_status_id IS NOT NULL)"
t.index ["uri"], name: "index_conversations_on_uri", unique: true, opclass: :text_pattern_ops, where: "(uri IS NOT NULL)" t.index ["uri"], name: "index_conversations_on_uri", unique: true, opclass: :text_pattern_ops, where: "(uri IS NOT NULL)"
end end

View File

@ -3,10 +3,10 @@
require 'rails_helper' require 'rails_helper'
RSpec.describe 'ActivityPub Contexts' do RSpec.describe 'ActivityPub Contexts' do
let(:conversation) { Fabricate(:conversation) } let(:conversation) { Fabricate(:status).owned_conversation }
describe 'GET #show' do describe 'GET #show' do
subject { get context_path(id: conversation.id), headers: nil } subject { get context_path(conversation), headers: nil }
let!(:status) { Fabricate(:status, conversation: conversation) } let!(:status) { Fabricate(:status, conversation: conversation) }
let!(:unrelated_status) { Fabricate(:status) } let!(:unrelated_status) { Fabricate(:status) }
@ -26,17 +26,39 @@ RSpec.describe 'ActivityPub Contexts' do
expect(response.parsed_body[:first][:items]) expect(response.parsed_body[:first][:items])
.to be_an(Array) .to be_an(Array)
.and have_attributes(size: 1) .and have_attributes(size: 2)
.and include(ActivityPub::TagManager.instance.uri_for(status)) .and include(ActivityPub::TagManager.instance.uri_for(status))
.and not_include(ActivityPub::TagManager.instance.uri_for(unrelated_status)) .and not_include(ActivityPub::TagManager.instance.uri_for(unrelated_status))
end end
context 'when the initial account is deleted' do
before { conversation.parent_account.delete }
it 'returns http success and correct media type and correct items' do
subject
expect(response)
.to have_http_status(200)
.and have_cacheable_headers
expect(response.media_type)
.to eq 'application/activity+json'
expect(response.parsed_body[:type])
.to eq 'Collection'
expect(response.parsed_body[:first][:items])
.to be_an(Array)
.and have_attributes(size: 1)
.and include(ActivityPub::TagManager.instance.uri_for(status))
.and not_include(ActivityPub::TagManager.instance.uri_for(unrelated_status))
end
end
context 'with pagination' do context 'with pagination' do
context 'with few statuses' do context 'with few statuses' do
before do before do
3.times do Fabricate.times(3, :status, conversation: conversation)
Fabricate(:status, conversation: conversation)
end
end end
it 'does not include a next page link' do it 'does not include a next page link' do
@ -48,7 +70,7 @@ RSpec.describe 'ActivityPub Contexts' do
context 'with many statuses' do context 'with many statuses' do
before do before do
(ActivityPub::ContextsController::DESCENDANTS_LIMIT + 1).times do ActivityPub::ContextsController::DESCENDANTS_LIMIT.times do
Fabricate(:status, conversation: conversation) Fabricate(:status, conversation: conversation)
end end
end end
@ -63,13 +85,11 @@ RSpec.describe 'ActivityPub Contexts' do
end end
describe 'GET #items' do describe 'GET #items' do
subject { get items_context_path(id: conversation.id, page: 0, min_id: nil), headers: nil } subject { get items_context_path(conversation, page: 0, min_id: nil), headers: nil }
context 'with few statuses' do context 'with few statuses' do
before do before do
3.times do Fabricate.times(2, :status, conversation: conversation)
Fabricate(:status, conversation: conversation)
end
end end
it 'returns http success and correct media type and correct items' do it 'returns http success and correct media type and correct items' do
@ -94,9 +114,8 @@ RSpec.describe 'ActivityPub Contexts' do
context 'with many statuses' do context 'with many statuses' do
before do before do
(ActivityPub::ContextsController::DESCENDANTS_LIMIT + 1).times do stub_const 'ActivityPub::ContextsController::DESCENDANTS_LIMIT', 2
Fabricate(:status, conversation: conversation) Fabricate.times(ActivityPub::ContextsController::DESCENDANTS_LIMIT, :status, conversation: conversation)
end
end end
it 'includes a next page link' do it 'includes a next page link' do
@ -108,13 +127,12 @@ RSpec.describe 'ActivityPub Contexts' do
context 'with page requested' do context 'with page requested' do
before do before do
(ActivityPub::ContextsController::DESCENDANTS_LIMIT + 1).times do |_i| stub_const 'ActivityPub::ContextsController::DESCENDANTS_LIMIT', 2
Fabricate(:status, conversation: conversation) Fabricate.times(ActivityPub::ContextsController::DESCENDANTS_LIMIT, :status, conversation: conversation)
end
end end
it 'returns the correct items' do it 'returns the correct items' do
get items_context_path(id: conversation.id, page: 0, min_id: nil), headers: nil get items_context_path(conversation, page: 0, min_id: nil), headers: nil
next_page = response.parsed_body['first']['next'] next_page = response.parsed_body['first']['next']
get next_page, headers: nil get next_page, headers: nil