From c63368f64c5e6df185ad0829bda1f9690d3f9575 Mon Sep 17 00:00:00 2001 From: Matt Jankowski Date: Wed, 30 Oct 2024 15:27:16 -0400 Subject: [PATCH 1/6] Replace `Oj` with plain `JSON` across spec/ --- .../lib/activitypub/activity/announce_spec.rb | 4 +-- spec/lib/activitypub/activity/create_spec.rb | 2 +- spec/lib/activitypub/dereferencer_spec.rb | 2 +- spec/lib/feed_manager_spec.rb | 2 +- spec/lib/mastodon/cli/domains_spec.rb | 2 +- spec/lib/webfinger_spec.rb | 6 ++--- spec/lib/webhooks/payload_renderer_spec.rb | 2 +- spec/models/user_spec.rb | 2 +- spec/requests/api/v2/filters_spec.rb | 2 +- .../fetch_featured_collection_service_spec.rb | 18 ++++++------- ...h_featured_tags_collection_service_spec.rb | 8 +++--- .../fetch_remote_account_service_spec.rb | 26 +++++++++---------- .../fetch_remote_actor_service_spec.rb | 26 +++++++++---------- .../fetch_remote_key_service_spec.rb | 10 +++---- .../fetch_remote_status_service_spec.rb | 8 +++--- .../activitypub/fetch_replies_service_spec.rb | 6 ++--- .../process_collection_service_spec.rb | 2 +- .../process_status_update_service_spec.rb | 2 +- .../synchronize_followers_service_spec.rb | 6 ++--- spec/services/backup_service_spec.rb | 4 +-- .../fetch_remote_status_service_spec.rb | 2 +- spec/services/remove_status_service_spec.rb | 2 +- spec/services/resolve_account_service_spec.rb | 10 +++---- .../software_update_check_service_spec.rb | 2 +- .../activitypub/fetch_replies_worker_spec.rb | 2 +- 25 files changed, 79 insertions(+), 79 deletions(-) diff --git a/spec/lib/activitypub/activity/announce_spec.rb b/spec/lib/activitypub/activity/announce_spec.rb index b556bfd6c2..582dd4d63f 100644 --- a/spec/lib/activitypub/activity/announce_spec.rb +++ b/spec/lib/activitypub/activity/announce_spec.rb @@ -35,7 +35,7 @@ RSpec.describe ActivityPub::Activity::Announce do context 'when sender is followed by a local account' do before do Fabricate(:account).follow!(sender) - stub_request(:get, 'https://example.com/actor/hello-world').to_return(body: Oj.dump(unknown_object_json), headers: { 'Content-Type': 'application/activity+json' }) + stub_request(:get, 'https://example.com/actor/hello-world').to_return(body: JSON.dump(unknown_object_json), headers: { 'Content-Type': 'application/activity+json' }) subject.perform end @@ -120,7 +120,7 @@ RSpec.describe ActivityPub::Activity::Announce do let(:object_json) { 'https://example.com/actor/hello-world' } before do - stub_request(:get, 'https://example.com/actor/hello-world').to_return(body: Oj.dump(unknown_object_json), headers: { 'Content-Type': 'application/activity+json' }) + stub_request(:get, 'https://example.com/actor/hello-world').to_return(body: JSON.dump(unknown_object_json), headers: { 'Content-Type': 'application/activity+json' }) end context 'when the relay is enabled' do diff --git a/spec/lib/activitypub/activity/create_spec.rb b/spec/lib/activitypub/activity/create_spec.rb index 8be6766dad..721b30e0fa 100644 --- a/spec/lib/activitypub/activity/create_spec.rb +++ b/spec/lib/activitypub/activity/create_spec.rb @@ -1071,7 +1071,7 @@ RSpec.describe ActivityPub::Activity::Create do before do stub_request(:get, object_json[:id]) .with(headers: { Authorization: "Bearer #{token}" }) - .to_return(body: Oj.dump(object_json), headers: { 'Content-Type': 'application/activity+json' }) + .to_return(body: JSON.dump(object_json), headers: { 'Content-Type': 'application/activity+json' }) subject.perform end diff --git a/spec/lib/activitypub/dereferencer_spec.rb b/spec/lib/activitypub/dereferencer_spec.rb index 11078de866..de9195612c 100644 --- a/spec/lib/activitypub/dereferencer_spec.rb +++ b/spec/lib/activitypub/dereferencer_spec.rb @@ -12,7 +12,7 @@ RSpec.describe ActivityPub::Dereferencer do let(:uri) { nil } before do - stub_request(:get, 'https://example.com/foo').to_return(body: Oj.dump(object), headers: { 'Content-Type' => 'application/activity+json' }) + stub_request(:get, 'https://example.com/foo').to_return(body: JSON.dump(object), headers: { 'Content-Type' => 'application/activity+json' }) end context 'with a URI' do diff --git a/spec/lib/feed_manager_spec.rb b/spec/lib/feed_manager_spec.rb index 1d3123d343..7a7fd371b1 100644 --- a/spec/lib/feed_manager_spec.rb +++ b/spec/lib/feed_manager_spec.rb @@ -524,7 +524,7 @@ RSpec.describe FeedManager do allow(redis).to receive_messages(publish: nil) subject.unpush_from_home(receiver, status) - deletion = Oj.dump(event: :delete, payload: status.id.to_s) + deletion = JSON.dump(event: :delete, payload: status.id.to_s) expect(redis).to have_received(:publish).with("timeline:#{receiver.id}", deletion) end end diff --git a/spec/lib/mastodon/cli/domains_spec.rb b/spec/lib/mastodon/cli/domains_spec.rb index d1c26546f0..6034921ef8 100644 --- a/spec/lib/mastodon/cli/domains_spec.rb +++ b/spec/lib/mastodon/cli/domains_spec.rb @@ -87,7 +87,7 @@ RSpec.describe Mastodon::CLI::Domains do end def json_summary - Oj.dump('host.example': { activity: {} }) + JSON.dump('host.example': { activity: {} }) end end end diff --git a/spec/lib/webfinger_spec.rb b/spec/lib/webfinger_spec.rb index 5015deac7f..9b4e9b5d67 100644 --- a/spec/lib/webfinger_spec.rb +++ b/spec/lib/webfinger_spec.rb @@ -8,7 +8,7 @@ RSpec.describe Webfinger do let!(:webfinger) { { subject: 'acct:alice@example.com', links: [{ rel: 'self', href: 'https://example.com/alice', type: 'application/activity+json' }] } } it 'correctly parses the response' do - stub_request(:get, 'https://example.com/.well-known/webfinger?resource=acct:alice@example.com').to_return(body: Oj.dump(webfinger), headers: { 'Content-Type': 'application/jrd+json' }) + stub_request(:get, 'https://example.com/.well-known/webfinger?resource=acct:alice@example.com').to_return(body: JSON.dump(webfinger), headers: { 'Content-Type': 'application/jrd+json' }) response = described_class.new('acct:alice@example.com').perform @@ -20,7 +20,7 @@ RSpec.describe Webfinger do let!(:webfinger) { { subject: 'acct:alice@example.com', links: [{ rel: 'self', href: 'https://example.com/alice', type: 'application/ld+json; profile="https://www.w3.org/ns/activitystreams"' }] } } it 'correctly parses the response' do - stub_request(:get, 'https://example.com/.well-known/webfinger?resource=acct:alice@example.com').to_return(body: Oj.dump(webfinger), headers: { 'Content-Type': 'application/jrd+json' }) + stub_request(:get, 'https://example.com/.well-known/webfinger?resource=acct:alice@example.com').to_return(body: JSON.dump(webfinger), headers: { 'Content-Type': 'application/jrd+json' }) response = described_class.new('acct:alice@example.com').perform @@ -32,7 +32,7 @@ RSpec.describe Webfinger do let!(:webfinger) { { subject: 'acct:alice@example.com', links: [{ rel: 'self', href: 'https://example.com/alice', type: 'application/json"' }] } } it 'raises an error' do - stub_request(:get, 'https://example.com/.well-known/webfinger?resource=acct:alice@example.com').to_return(body: Oj.dump(webfinger), headers: { 'Content-Type': 'application/jrd+json' }) + stub_request(:get, 'https://example.com/.well-known/webfinger?resource=acct:alice@example.com').to_return(body: JSON.dump(webfinger), headers: { 'Content-Type': 'application/jrd+json' }) expect { described_class.new('acct:alice@example.com').perform }.to raise_error(Webfinger::Error) end diff --git a/spec/lib/webhooks/payload_renderer_spec.rb b/spec/lib/webhooks/payload_renderer_spec.rb index 0623edd254..71171dfd74 100644 --- a/spec/lib/webhooks/payload_renderer_spec.rb +++ b/spec/lib/webhooks/payload_renderer_spec.rb @@ -7,7 +7,7 @@ RSpec.describe Webhooks::PayloadRenderer do let(:event) { Webhooks::EventPresenter.new(type, object) } let(:payload) { ActiveModelSerializers::SerializableResource.new(event, serializer: REST::Admin::WebhookEventSerializer, scope: nil, scope_name: :current_user).as_json } - let(:json) { Oj.dump(payload) } + let(:json) { JSON.dump(payload) } describe '#render' do context 'when event is account.approved' do diff --git a/spec/models/user_spec.rb b/spec/models/user_spec.rb index 08d410bb16..ebb8194bbe 100644 --- a/spec/models/user_spec.rb +++ b/spec/models/user_spec.rb @@ -506,7 +506,7 @@ RSpec.describe User do expect { web_push_subscription.reload } .to raise_error(ActiveRecord::RecordNotFound) expect(redis_pipeline_stub) - .to have_received(:publish).with("timeline:access_token:#{access_token.id}", Oj.dump(event: :kill)).once + .to have_received(:publish).with("timeline:access_token:#{access_token.id}", JSON.dump(event: :kill)).once end def remove_activated_sessions diff --git a/spec/requests/api/v2/filters_spec.rb b/spec/requests/api/v2/filters_spec.rb index 3b5c44cefa..9657ca5997 100644 --- a/spec/requests/api/v2/filters_spec.rb +++ b/spec/requests/api/v2/filters_spec.rb @@ -210,7 +210,7 @@ RSpec.describe 'Filters' do expect(keyword.reload.keyword).to eq 'updated' - expect(redis).to have_received(:publish).with("timeline:#{user.account.id}", Oj.dump(event: :filters_changed)).once + expect(redis).to have_received(:publish).with("timeline:#{user.account.id}", JSON.dump(event: :filters_changed)).once end end diff --git a/spec/services/activitypub/fetch_featured_collection_service_spec.rb b/spec/services/activitypub/fetch_featured_collection_service_spec.rb index 7ea87922ac..3472b67f5d 100644 --- a/spec/services/activitypub/fetch_featured_collection_service_spec.rb +++ b/spec/services/activitypub/fetch_featured_collection_service_spec.rb @@ -72,11 +72,11 @@ RSpec.describe ActivityPub::FetchFeaturedCollectionService do shared_examples 'sets pinned posts' do before do - stub_request(:get, 'https://example.com/account/pinned/known').to_return(status: 200, body: Oj.dump(status_json_pinned_known), headers: { 'Content-Type': 'application/activity+json' }) - stub_request(:get, 'https://example.com/account/pinned/unknown-inlined').to_return(status: 200, body: Oj.dump(status_json_pinned_unknown_inlined), headers: { 'Content-Type': 'application/activity+json' }) + stub_request(:get, 'https://example.com/account/pinned/known').to_return(status: 200, body: JSON.dump(status_json_pinned_known), headers: { 'Content-Type': 'application/activity+json' }) + stub_request(:get, 'https://example.com/account/pinned/unknown-inlined').to_return(status: 200, body: JSON.dump(status_json_pinned_unknown_inlined), headers: { 'Content-Type': 'application/activity+json' }) stub_request(:get, 'https://example.com/account/pinned/unknown-unreachable').to_return(status: 404) - stub_request(:get, 'https://example.com/account/pinned/unknown-reachable').to_return(status: 200, body: Oj.dump(status_json_pinned_unknown_reachable), headers: { 'Content-Type': 'application/activity+json' }) - stub_request(:get, 'https://example.com/account/collections/featured').to_return(status: 200, body: Oj.dump(featured_with_null), headers: { 'Content-Type': 'application/activity+json' }) + stub_request(:get, 'https://example.com/account/pinned/unknown-reachable').to_return(status: 200, body: JSON.dump(status_json_pinned_unknown_reachable), headers: { 'Content-Type': 'application/activity+json' }) + stub_request(:get, 'https://example.com/account/collections/featured').to_return(status: 200, body: JSON.dump(featured_with_null), headers: { 'Content-Type': 'application/activity+json' }) subject.call(actor, note: true, hashtag: false) end @@ -94,7 +94,7 @@ RSpec.describe ActivityPub::FetchFeaturedCollectionService do describe '#call' do context 'when the endpoint is a Collection' do before do - stub_request(:get, actor.featured_collection_url).to_return(status: 200, body: Oj.dump(payload), headers: { 'Content-Type': 'application/activity+json' }) + stub_request(:get, actor.featured_collection_url).to_return(status: 200, body: JSON.dump(payload), headers: { 'Content-Type': 'application/activity+json' }) end it_behaves_like 'sets pinned posts' @@ -111,7 +111,7 @@ RSpec.describe ActivityPub::FetchFeaturedCollectionService do end before do - stub_request(:get, actor.featured_collection_url).to_return(status: 200, body: Oj.dump(payload), headers: { 'Content-Type': 'application/activity+json' }) + stub_request(:get, actor.featured_collection_url).to_return(status: 200, body: JSON.dump(payload), headers: { 'Content-Type': 'application/activity+json' }) end it_behaves_like 'sets pinned posts' @@ -120,7 +120,7 @@ RSpec.describe ActivityPub::FetchFeaturedCollectionService do let(:items) { 'https://example.com/account/pinned/unknown-reachable' } before do - stub_request(:get, 'https://example.com/account/pinned/unknown-reachable').to_return(status: 200, body: Oj.dump(status_json_pinned_unknown_reachable), headers: { 'Content-Type': 'application/activity+json' }) + stub_request(:get, 'https://example.com/account/pinned/unknown-reachable').to_return(status: 200, body: JSON.dump(status_json_pinned_unknown_reachable), headers: { 'Content-Type': 'application/activity+json' }) subject.call(actor, note: true, hashtag: false) end @@ -147,7 +147,7 @@ RSpec.describe ActivityPub::FetchFeaturedCollectionService do end before do - stub_request(:get, actor.featured_collection_url).to_return(status: 200, body: Oj.dump(payload), headers: { 'Content-Type': 'application/activity+json' }) + stub_request(:get, actor.featured_collection_url).to_return(status: 200, body: JSON.dump(payload), headers: { 'Content-Type': 'application/activity+json' }) end it_behaves_like 'sets pinned posts' @@ -156,7 +156,7 @@ RSpec.describe ActivityPub::FetchFeaturedCollectionService do let(:items) { 'https://example.com/account/pinned/unknown-reachable' } before do - stub_request(:get, 'https://example.com/account/pinned/unknown-reachable').to_return(status: 200, body: Oj.dump(status_json_pinned_unknown_reachable), headers: { 'Content-Type': 'application/activity+json' }) + stub_request(:get, 'https://example.com/account/pinned/unknown-reachable').to_return(status: 200, body: JSON.dump(status_json_pinned_unknown_reachable), headers: { 'Content-Type': 'application/activity+json' }) subject.call(actor, note: true, hashtag: false) end diff --git a/spec/services/activitypub/fetch_featured_tags_collection_service_spec.rb b/spec/services/activitypub/fetch_featured_tags_collection_service_spec.rb index 59367b1e32..0bd70953ac 100644 --- a/spec/services/activitypub/fetch_featured_tags_collection_service_spec.rb +++ b/spec/services/activitypub/fetch_featured_tags_collection_service_spec.rb @@ -38,7 +38,7 @@ RSpec.describe ActivityPub::FetchFeaturedTagsCollectionService do describe '#call' do context 'when the endpoint is a Collection' do before do - stub_request(:get, collection_url).to_return(status: 200, body: Oj.dump(payload), headers: { 'Content-Type': 'application/activity+json' }) + stub_request(:get, collection_url).to_return(status: 200, body: JSON.dump(payload), headers: { 'Content-Type': 'application/activity+json' }) end it_behaves_like 'sets featured tags' @@ -46,7 +46,7 @@ RSpec.describe ActivityPub::FetchFeaturedTagsCollectionService do context 'when the account already has featured tags' do before do - stub_request(:get, collection_url).to_return(status: 200, body: Oj.dump(payload), headers: { 'Content-Type': 'application/activity+json' }) + stub_request(:get, collection_url).to_return(status: 200, body: JSON.dump(payload), headers: { 'Content-Type': 'application/activity+json' }) actor.featured_tags.create!(name: 'FoO') actor.featured_tags.create!(name: 'baz') @@ -67,7 +67,7 @@ RSpec.describe ActivityPub::FetchFeaturedTagsCollectionService do end before do - stub_request(:get, collection_url).to_return(status: 200, body: Oj.dump(payload), headers: { 'Content-Type': 'application/activity+json' }) + stub_request(:get, collection_url).to_return(status: 200, body: JSON.dump(payload), headers: { 'Content-Type': 'application/activity+json' }) end it_behaves_like 'sets featured tags' @@ -88,7 +88,7 @@ RSpec.describe ActivityPub::FetchFeaturedTagsCollectionService do end before do - stub_request(:get, collection_url).to_return(status: 200, body: Oj.dump(payload), headers: { 'Content-Type': 'application/activity+json' }) + stub_request(:get, collection_url).to_return(status: 200, body: JSON.dump(payload), headers: { 'Content-Type': 'application/activity+json' }) end it_behaves_like 'sets featured tags' diff --git a/spec/services/activitypub/fetch_remote_account_service_spec.rb b/spec/services/activitypub/fetch_remote_account_service_spec.rb index 175ac9cb61..d19181448f 100644 --- a/spec/services/activitypub/fetch_remote_account_service_spec.rb +++ b/spec/services/activitypub/fetch_remote_account_service_spec.rb @@ -38,8 +38,8 @@ RSpec.describe ActivityPub::FetchRemoteAccountService do before do actor[:inbox] = nil - stub_request(:get, 'https://example.com/alice').to_return(body: Oj.dump(actor), headers: { 'Content-Type': 'application/activity+json' }) - stub_request(:get, 'https://example.com/.well-known/webfinger?resource=acct:alice@example.com').to_return(body: Oj.dump(webfinger), headers: { 'Content-Type': 'application/jrd+json' }) + stub_request(:get, 'https://example.com/alice').to_return(body: JSON.dump(actor), headers: { 'Content-Type': 'application/activity+json' }) + stub_request(:get, 'https://example.com/.well-known/webfinger?resource=acct:alice@example.com').to_return(body: JSON.dump(webfinger), headers: { 'Content-Type': 'application/jrd+json' }) end it 'fetches resource and looks up webfinger and returns nil' do @@ -54,8 +54,8 @@ RSpec.describe ActivityPub::FetchRemoteAccountService do let!(:webfinger) { { subject: 'acct:alice@example.com', links: [{ rel: 'self', href: 'https://example.com/alice', type: 'application/activity+json' }] } } before do - stub_request(:get, 'https://example.com/alice').to_return(body: Oj.dump(actor), headers: { 'Content-Type': 'application/activity+json' }) - stub_request(:get, 'https://example.com/.well-known/webfinger?resource=acct:alice@example.com').to_return(body: Oj.dump(webfinger), headers: { 'Content-Type': 'application/jrd+json' }) + stub_request(:get, 'https://example.com/alice').to_return(body: JSON.dump(actor), headers: { 'Content-Type': 'application/activity+json' }) + stub_request(:get, 'https://example.com/.well-known/webfinger?resource=acct:alice@example.com').to_return(body: JSON.dump(webfinger), headers: { 'Content-Type': 'application/jrd+json' }) end it 'fetches resource and looks up webfinger and sets attributes' do @@ -75,9 +75,9 @@ RSpec.describe ActivityPub::FetchRemoteAccountService do let!(:webfinger) { { subject: 'acct:alice@iscool.af', links: [{ rel: 'self', href: 'https://example.com/alice', type: 'application/activity+json' }] } } before do - stub_request(:get, 'https://example.com/alice').to_return(body: Oj.dump(actor), headers: { 'Content-Type': 'application/activity+json' }) - stub_request(:get, 'https://example.com/.well-known/webfinger?resource=acct:alice@example.com').to_return(body: Oj.dump(webfinger), headers: { 'Content-Type': 'application/jrd+json' }) - stub_request(:get, 'https://iscool.af/.well-known/webfinger?resource=acct:alice@iscool.af').to_return(body: Oj.dump(webfinger), headers: { 'Content-Type': 'application/jrd+json' }) + stub_request(:get, 'https://example.com/alice').to_return(body: JSON.dump(actor), headers: { 'Content-Type': 'application/activity+json' }) + stub_request(:get, 'https://example.com/.well-known/webfinger?resource=acct:alice@example.com').to_return(body: JSON.dump(webfinger), headers: { 'Content-Type': 'application/jrd+json' }) + stub_request(:get, 'https://iscool.af/.well-known/webfinger?resource=acct:alice@iscool.af').to_return(body: JSON.dump(webfinger), headers: { 'Content-Type': 'application/jrd+json' }) end it 'fetches resource and looks up webfinger and follows redirection and sets attributes' do @@ -98,8 +98,8 @@ RSpec.describe ActivityPub::FetchRemoteAccountService do let!(:webfinger) { { subject: 'acct:alice@example.com', links: [{ rel: 'self', href: 'https://example.com/bob', type: 'application/activity+json' }] } } before do - stub_request(:get, 'https://example.com/alice').to_return(body: Oj.dump(actor), headers: { 'Content-Type': 'application/activity+json' }) - stub_request(:get, 'https://example.com/.well-known/webfinger?resource=acct:alice@example.com').to_return(body: Oj.dump(webfinger), headers: { 'Content-Type': 'application/jrd+json' }) + stub_request(:get, 'https://example.com/alice').to_return(body: JSON.dump(actor), headers: { 'Content-Type': 'application/activity+json' }) + stub_request(:get, 'https://example.com/.well-known/webfinger?resource=acct:alice@example.com').to_return(body: JSON.dump(webfinger), headers: { 'Content-Type': 'application/jrd+json' }) end it 'fetches resource and looks up webfinger and does not create account' do @@ -114,9 +114,9 @@ RSpec.describe ActivityPub::FetchRemoteAccountService do let!(:webfinger) { { subject: 'acct:alice@iscool.af', links: [{ rel: 'self', href: 'https://example.com/bob', type: 'application/activity+json' }] } } before do - stub_request(:get, 'https://example.com/alice').to_return(body: Oj.dump(actor), headers: { 'Content-Type': 'application/activity+json' }) - stub_request(:get, 'https://example.com/.well-known/webfinger?resource=acct:alice@example.com').to_return(body: Oj.dump(webfinger), headers: { 'Content-Type': 'application/jrd+json' }) - stub_request(:get, 'https://iscool.af/.well-known/webfinger?resource=acct:alice@iscool.af').to_return(body: Oj.dump(webfinger), headers: { 'Content-Type': 'application/jrd+json' }) + stub_request(:get, 'https://example.com/alice').to_return(body: JSON.dump(actor), headers: { 'Content-Type': 'application/activity+json' }) + stub_request(:get, 'https://example.com/.well-known/webfinger?resource=acct:alice@example.com').to_return(body: JSON.dump(webfinger), headers: { 'Content-Type': 'application/jrd+json' }) + stub_request(:get, 'https://iscool.af/.well-known/webfinger?resource=acct:alice@iscool.af').to_return(body: JSON.dump(webfinger), headers: { 'Content-Type': 'application/jrd+json' }) end it 'fetches resource and looks up webfinger and follows redirect and does not create account' do @@ -130,7 +130,7 @@ RSpec.describe ActivityPub::FetchRemoteAccountService do context 'with wrong id' do it 'does not create account' do - expect(subject.call('https://fake.address/@foo', prefetched_body: Oj.dump(actor))).to be_nil + expect(subject.call('https://fake.address/@foo', prefetched_body: JSON.dump(actor))).to be_nil end end end diff --git a/spec/services/activitypub/fetch_remote_actor_service_spec.rb b/spec/services/activitypub/fetch_remote_actor_service_spec.rb index 9d031cb89b..09a1383b07 100644 --- a/spec/services/activitypub/fetch_remote_actor_service_spec.rb +++ b/spec/services/activitypub/fetch_remote_actor_service_spec.rb @@ -38,8 +38,8 @@ RSpec.describe ActivityPub::FetchRemoteActorService do before do actor[:inbox] = nil - stub_request(:get, 'https://example.com/alice').to_return(body: Oj.dump(actor), headers: { 'Content-Type': 'application/activity+json' }) - stub_request(:get, 'https://example.com/.well-known/webfinger?resource=acct:alice@example.com').to_return(body: Oj.dump(webfinger), headers: { 'Content-Type': 'application/jrd+json' }) + stub_request(:get, 'https://example.com/alice').to_return(body: JSON.dump(actor), headers: { 'Content-Type': 'application/activity+json' }) + stub_request(:get, 'https://example.com/.well-known/webfinger?resource=acct:alice@example.com').to_return(body: JSON.dump(webfinger), headers: { 'Content-Type': 'application/jrd+json' }) end it 'fetches resource and looks up webfinger and returns nil' do @@ -54,8 +54,8 @@ RSpec.describe ActivityPub::FetchRemoteActorService do let!(:webfinger) { { subject: 'acct:alice@example.com', links: [{ rel: 'self', href: 'https://example.com/alice', type: 'application/activity+json' }] } } before do - stub_request(:get, 'https://example.com/alice').to_return(body: Oj.dump(actor), headers: { 'Content-Type': 'application/activity+json' }) - stub_request(:get, 'https://example.com/.well-known/webfinger?resource=acct:alice@example.com').to_return(body: Oj.dump(webfinger), headers: { 'Content-Type': 'application/jrd+json' }) + stub_request(:get, 'https://example.com/alice').to_return(body: JSON.dump(actor), headers: { 'Content-Type': 'application/activity+json' }) + stub_request(:get, 'https://example.com/.well-known/webfinger?resource=acct:alice@example.com').to_return(body: JSON.dump(webfinger), headers: { 'Content-Type': 'application/jrd+json' }) end it 'fetches resource and looks up webfinger and sets values' do @@ -75,9 +75,9 @@ RSpec.describe ActivityPub::FetchRemoteActorService do let!(:webfinger) { { subject: 'acct:alice@iscool.af', links: [{ rel: 'self', href: 'https://example.com/alice', type: 'application/activity+json' }] } } before do - stub_request(:get, 'https://example.com/alice').to_return(body: Oj.dump(actor), headers: { 'Content-Type': 'application/activity+json' }) - stub_request(:get, 'https://example.com/.well-known/webfinger?resource=acct:alice@example.com').to_return(body: Oj.dump(webfinger), headers: { 'Content-Type': 'application/jrd+json' }) - stub_request(:get, 'https://iscool.af/.well-known/webfinger?resource=acct:alice@iscool.af').to_return(body: Oj.dump(webfinger), headers: { 'Content-Type': 'application/jrd+json' }) + stub_request(:get, 'https://example.com/alice').to_return(body: JSON.dump(actor), headers: { 'Content-Type': 'application/activity+json' }) + stub_request(:get, 'https://example.com/.well-known/webfinger?resource=acct:alice@example.com').to_return(body: JSON.dump(webfinger), headers: { 'Content-Type': 'application/jrd+json' }) + stub_request(:get, 'https://iscool.af/.well-known/webfinger?resource=acct:alice@iscool.af').to_return(body: JSON.dump(webfinger), headers: { 'Content-Type': 'application/jrd+json' }) end it 'fetches resource and looks up webfinger and follows redirect and sets values' do @@ -98,8 +98,8 @@ RSpec.describe ActivityPub::FetchRemoteActorService do let!(:webfinger) { { subject: 'acct:alice@example.com', links: [{ rel: 'self', href: 'https://example.com/bob', type: 'application/activity+json' }] } } before do - stub_request(:get, 'https://example.com/alice').to_return(body: Oj.dump(actor), headers: { 'Content-Type': 'application/activity+json' }) - stub_request(:get, 'https://example.com/.well-known/webfinger?resource=acct:alice@example.com').to_return(body: Oj.dump(webfinger), headers: { 'Content-Type': 'application/jrd+json' }) + stub_request(:get, 'https://example.com/alice').to_return(body: JSON.dump(actor), headers: { 'Content-Type': 'application/activity+json' }) + stub_request(:get, 'https://example.com/.well-known/webfinger?resource=acct:alice@example.com').to_return(body: JSON.dump(webfinger), headers: { 'Content-Type': 'application/jrd+json' }) end it 'fetches resource and looks up webfinger and does not create account' do @@ -114,9 +114,9 @@ RSpec.describe ActivityPub::FetchRemoteActorService do let!(:webfinger) { { subject: 'acct:alice@iscool.af', links: [{ rel: 'self', href: 'https://example.com/bob', type: 'application/activity+json' }] } } before do - stub_request(:get, 'https://example.com/alice').to_return(body: Oj.dump(actor), headers: { 'Content-Type': 'application/activity+json' }) - stub_request(:get, 'https://example.com/.well-known/webfinger?resource=acct:alice@example.com').to_return(body: Oj.dump(webfinger), headers: { 'Content-Type': 'application/jrd+json' }) - stub_request(:get, 'https://iscool.af/.well-known/webfinger?resource=acct:alice@iscool.af').to_return(body: Oj.dump(webfinger), headers: { 'Content-Type': 'application/jrd+json' }) + stub_request(:get, 'https://example.com/alice').to_return(body: JSON.dump(actor), headers: { 'Content-Type': 'application/activity+json' }) + stub_request(:get, 'https://example.com/.well-known/webfinger?resource=acct:alice@example.com').to_return(body: JSON.dump(webfinger), headers: { 'Content-Type': 'application/jrd+json' }) + stub_request(:get, 'https://iscool.af/.well-known/webfinger?resource=acct:alice@iscool.af').to_return(body: JSON.dump(webfinger), headers: { 'Content-Type': 'application/jrd+json' }) end it 'fetches resource and looks up webfinger and follows redirect and does not create account' do @@ -130,7 +130,7 @@ RSpec.describe ActivityPub::FetchRemoteActorService do context 'with wrong id' do it 'does not create account' do - expect(subject.call('https://fake.address/@foo', prefetched_body: Oj.dump(actor))).to be_nil + expect(subject.call('https://fake.address/@foo', prefetched_body: JSON.dump(actor))).to be_nil end end end diff --git a/spec/services/activitypub/fetch_remote_key_service_spec.rb b/spec/services/activitypub/fetch_remote_key_service_spec.rb index 847a154108..98d01c5a00 100644 --- a/spec/services/activitypub/fetch_remote_key_service_spec.rb +++ b/spec/services/activitypub/fetch_remote_key_service_spec.rb @@ -50,8 +50,8 @@ RSpec.describe ActivityPub::FetchRemoteKeyService do end before do - stub_request(:get, 'https://example.com/alice').to_return(body: Oj.dump(actor), headers: { 'Content-Type': 'application/activity+json' }) - stub_request(:get, 'https://example.com/.well-known/webfinger?resource=acct:alice@example.com').to_return(body: Oj.dump(webfinger), headers: { 'Content-Type': 'application/jrd+json' }) + stub_request(:get, 'https://example.com/alice').to_return(body: JSON.dump(actor), headers: { 'Content-Type': 'application/activity+json' }) + stub_request(:get, 'https://example.com/.well-known/webfinger?resource=acct:alice@example.com').to_return(body: JSON.dump(webfinger), headers: { 'Content-Type': 'application/jrd+json' }) end describe '#call' do @@ -59,7 +59,7 @@ RSpec.describe ActivityPub::FetchRemoteKeyService do context 'when the key is a sub-object from the actor' do before do - stub_request(:get, public_key_id).to_return(body: Oj.dump(actor), headers: { 'Content-Type': 'application/activity+json' }) + stub_request(:get, public_key_id).to_return(body: JSON.dump(actor), headers: { 'Content-Type': 'application/activity+json' }) end it 'returns the expected account' do @@ -71,7 +71,7 @@ RSpec.describe ActivityPub::FetchRemoteKeyService do let(:public_key_id) { 'https://example.com/alice-public-key.json' } before do - stub_request(:get, public_key_id).to_return(body: Oj.dump(key_json.merge({ '@context': ['https://www.w3.org/ns/activitystreams', 'https://w3id.org/security/v1'] })), headers: { 'Content-Type': 'application/activity+json' }) + stub_request(:get, public_key_id).to_return(body: JSON.dump(key_json.merge({ '@context': ['https://www.w3.org/ns/activitystreams', 'https://w3id.org/security/v1'] })), headers: { 'Content-Type': 'application/activity+json' }) end it 'returns the expected account' do @@ -84,7 +84,7 @@ RSpec.describe ActivityPub::FetchRemoteKeyService do let(:actor_public_key) { 'https://example.com/alice-public-key.json' } before do - stub_request(:get, public_key_id).to_return(body: Oj.dump(key_json.merge({ '@context': ['https://www.w3.org/ns/activitystreams', 'https://w3id.org/security/v1'] })), headers: { 'Content-Type': 'application/activity+json' }) + stub_request(:get, public_key_id).to_return(body: JSON.dump(key_json.merge({ '@context': ['https://www.w3.org/ns/activitystreams', 'https://w3id.org/security/v1'] })), headers: { 'Content-Type': 'application/activity+json' }) end it 'returns the nil' do diff --git a/spec/services/activitypub/fetch_remote_status_service_spec.rb b/spec/services/activitypub/fetch_remote_status_service_spec.rb index 9d8c6e0e0a..bed618935f 100644 --- a/spec/services/activitypub/fetch_remote_status_service_spec.rb +++ b/spec/services/activitypub/fetch_remote_status_service_spec.rb @@ -23,13 +23,13 @@ RSpec.describe ActivityPub::FetchRemoteStatusService do before do stub_request(:get, 'https://foo.bar/watch?v=12345').to_return(status: 404, body: '') - stub_request(:get, object[:id]).to_return(body: Oj.dump(object)) + stub_request(:get, object[:id]).to_return(body: JSON.dump(object)) end describe '#call' do before do existing_status - subject.call(object[:id], prefetched_body: Oj.dump(object)) + subject.call(object[:id], prefetched_body: JSON.dump(object)) end context 'with Note object' do @@ -309,7 +309,7 @@ RSpec.describe ActivityPub::FetchRemoteStatusService do end it 'creates statuses but not more than limit allows' do - expect { subject.call(object[:id], prefetched_body: Oj.dump(object)) } + expect { subject.call(object[:id], prefetched_body: JSON.dump(object)) } .to change { sender.statuses.count }.by_at_least(2) .and change { sender.statuses.count }.by_at_most(3) end @@ -359,7 +359,7 @@ RSpec.describe ActivityPub::FetchRemoteStatusService do end it 'creates statuses but not more than limit allows' do - expect { subject.call(object[:id], prefetched_body: Oj.dump(object)) } + expect { subject.call(object[:id], prefetched_body: JSON.dump(object)) } .to change { sender.statuses.count }.by_at_least(2) .and change { sender.statuses.count }.by_at_most(3) end diff --git a/spec/services/activitypub/fetch_replies_service_spec.rb b/spec/services/activitypub/fetch_replies_service_spec.rb index e7d8d3528a..5b919d9355 100644 --- a/spec/services/activitypub/fetch_replies_service_spec.rb +++ b/spec/services/activitypub/fetch_replies_service_spec.rb @@ -58,7 +58,7 @@ RSpec.describe ActivityPub::FetchRepliesService do context 'when passing the URL to the collection' do before do - stub_request(:get, collection_uri).to_return(status: 200, body: Oj.dump(payload), headers: { 'Content-Type': 'application/activity+json' }) + stub_request(:get, collection_uri).to_return(status: 200, body: JSON.dump(payload), headers: { 'Content-Type': 'application/activity+json' }) end it 'spawns workers for up to 5 replies on the same server' do @@ -93,7 +93,7 @@ RSpec.describe ActivityPub::FetchRepliesService do context 'when passing the URL to the collection' do before do - stub_request(:get, collection_uri).to_return(status: 200, body: Oj.dump(payload), headers: { 'Content-Type': 'application/activity+json' }) + stub_request(:get, collection_uri).to_return(status: 200, body: JSON.dump(payload), headers: { 'Content-Type': 'application/activity+json' }) end it 'spawns workers for up to 5 replies on the same server' do @@ -132,7 +132,7 @@ RSpec.describe ActivityPub::FetchRepliesService do context 'when passing the URL to the collection' do before do - stub_request(:get, collection_uri).to_return(status: 200, body: Oj.dump(payload), headers: { 'Content-Type': 'application/activity+json' }) + stub_request(:get, collection_uri).to_return(status: 200, body: JSON.dump(payload), headers: { 'Content-Type': 'application/activity+json' }) end it 'spawns workers for up to 5 replies on the same server' do diff --git a/spec/services/activitypub/process_collection_service_spec.rb b/spec/services/activitypub/process_collection_service_spec.rb index 74df0f9106..c7f090be08 100644 --- a/spec/services/activitypub/process_collection_service_spec.rb +++ b/spec/services/activitypub/process_collection_service_spec.rb @@ -21,7 +21,7 @@ RSpec.describe ActivityPub::ProcessCollectionService do } end - let(:json) { Oj.dump(payload) } + let(:json) { JSON.dump(payload) } describe '#call' do context 'when actor is suspended' do diff --git a/spec/services/activitypub/process_status_update_service_spec.rb b/spec/services/activitypub/process_status_update_service_spec.rb index 1a8ea2d170..b9011d28f0 100644 --- a/spec/services/activitypub/process_status_update_service_spec.rb +++ b/spec/services/activitypub/process_status_update_service_spec.rb @@ -22,7 +22,7 @@ RSpec.describe ActivityPub::ProcessStatusUpdateService do ], } end - let(:json) { Oj.load(Oj.dump(payload)) } + let(:json) { JSON.parse(JSON.dump(payload)) } let(:alice) { Fabricate(:account) } let(:bob) { Fabricate(:account) } diff --git a/spec/services/activitypub/synchronize_followers_service_spec.rb b/spec/services/activitypub/synchronize_followers_service_spec.rb index 974368b7d7..ee653b841b 100644 --- a/spec/services/activitypub/synchronize_followers_service_spec.rb +++ b/spec/services/activitypub/synchronize_followers_service_spec.rb @@ -53,7 +53,7 @@ RSpec.describe ActivityPub::SynchronizeFollowersService do describe '#call' do context 'when the endpoint is a Collection of actor URIs' do before do - stub_request(:get, collection_uri).to_return(status: 200, body: Oj.dump(payload), headers: { 'Content-Type': 'application/activity+json' }) + stub_request(:get, collection_uri).to_return(status: 200, body: JSON.dump(payload), headers: { 'Content-Type': 'application/activity+json' }) end it_behaves_like 'synchronizes followers' @@ -70,7 +70,7 @@ RSpec.describe ActivityPub::SynchronizeFollowersService do end before do - stub_request(:get, collection_uri).to_return(status: 200, body: Oj.dump(payload), headers: { 'Content-Type': 'application/activity+json' }) + stub_request(:get, collection_uri).to_return(status: 200, body: JSON.dump(payload), headers: { 'Content-Type': 'application/activity+json' }) end it_behaves_like 'synchronizes followers' @@ -91,7 +91,7 @@ RSpec.describe ActivityPub::SynchronizeFollowersService do end before do - stub_request(:get, collection_uri).to_return(status: 200, body: Oj.dump(payload), headers: { 'Content-Type': 'application/activity+json' }) + stub_request(:get, collection_uri).to_return(status: 200, body: JSON.dump(payload), headers: { 'Content-Type': 'application/activity+json' }) end it_behaves_like 'synchronizes followers' diff --git a/spec/services/backup_service_spec.rb b/spec/services/backup_service_spec.rb index 878405a0fe..1dcebc24d2 100644 --- a/spec/services/backup_service_spec.rb +++ b/spec/services/backup_service_spec.rb @@ -56,7 +56,7 @@ RSpec.describe BackupService do def expect_outbox_export body = export_json_raw(:outbox) - json = Oj.load(body) + json = JSON.parse(body) aggregate_failures do expect(body.scan('@context').count).to eq 1 @@ -93,7 +93,7 @@ RSpec.describe BackupService do end def export_json(type) - Oj.load(export_json_raw(type)) + JSON.parse(export_json_raw(type)) end def include_create_item(status) diff --git a/spec/services/fetch_remote_status_service_spec.rb b/spec/services/fetch_remote_status_service_spec.rb index a9c61e7b4e..7c10cd96da 100644 --- a/spec/services/fetch_remote_status_service_spec.rb +++ b/spec/services/fetch_remote_status_service_spec.rb @@ -19,7 +19,7 @@ RSpec.describe FetchRemoteStatusService do context 'when protocol is :activitypub' do subject { described_class.new.call(note[:id], prefetched_body: prefetched_body) } - let(:prefetched_body) { Oj.dump(note) } + let(:prefetched_body) { JSON.dump(note) } before do subject diff --git a/spec/services/remove_status_service_spec.rb b/spec/services/remove_status_service_spec.rb index f2b46f05b0..3b54c25d1d 100644 --- a/spec/services/remove_status_service_spec.rb +++ b/spec/services/remove_status_service_spec.rb @@ -40,7 +40,7 @@ RSpec.describe RemoveStatusService, :inline_jobs do .to_not include(status.id) expect(redis) - .to have_received(:publish).with('timeline:public:media', Oj.dump(event: :delete, payload: status.id.to_s)) + .to have_received(:publish).with('timeline:public:media', JSON.dump(event: :delete, payload: status.id.to_s)) expect(delete_delivery(hank, status)) .to have_been_made.once diff --git a/spec/services/resolve_account_service_spec.rb b/spec/services/resolve_account_service_spec.rb index 1bd4e9a8e3..211f35ad0d 100644 --- a/spec/services/resolve_account_service_spec.rb +++ b/spec/services/resolve_account_service_spec.rb @@ -103,7 +103,7 @@ RSpec.describe ResolveAccountService do context 'with a legitimate webfinger redirection' do before do webfinger = { subject: 'acct:foo@ap.example.com', links: [{ rel: 'self', href: 'https://ap.example.com/users/foo', type: 'application/activity+json' }] } - stub_request(:get, 'https://redirected.example.com/.well-known/webfinger?resource=acct:Foo@redirected.example.com').to_return(body: Oj.dump(webfinger), headers: { 'Content-Type': 'application/jrd+json' }) + stub_request(:get, 'https://redirected.example.com/.well-known/webfinger?resource=acct:Foo@redirected.example.com').to_return(body: JSON.dump(webfinger), headers: { 'Content-Type': 'application/jrd+json' }) end it 'returns new remote account' do @@ -121,7 +121,7 @@ RSpec.describe ResolveAccountService do context 'with a misconfigured redirection' do before do webfinger = { subject: 'acct:Foo@redirected.example.com', links: [{ rel: 'self', href: 'https://ap.example.com/users/foo', type: 'application/activity+json' }] } - stub_request(:get, 'https://redirected.example.com/.well-known/webfinger?resource=acct:Foo@redirected.example.com').to_return(body: Oj.dump(webfinger), headers: { 'Content-Type': 'application/jrd+json' }) + stub_request(:get, 'https://redirected.example.com/.well-known/webfinger?resource=acct:Foo@redirected.example.com').to_return(body: JSON.dump(webfinger), headers: { 'Content-Type': 'application/jrd+json' }) end it 'returns new remote account' do @@ -139,9 +139,9 @@ RSpec.describe ResolveAccountService do context 'with too many webfinger redirections' do before do webfinger = { subject: 'acct:foo@evil.example.com', links: [{ rel: 'self', href: 'https://ap.example.com/users/foo', type: 'application/activity+json' }] } - stub_request(:get, 'https://redirected.example.com/.well-known/webfinger?resource=acct:Foo@redirected.example.com').to_return(body: Oj.dump(webfinger), headers: { 'Content-Type': 'application/jrd+json' }) + stub_request(:get, 'https://redirected.example.com/.well-known/webfinger?resource=acct:Foo@redirected.example.com').to_return(body: JSON.dump(webfinger), headers: { 'Content-Type': 'application/jrd+json' }) webfinger2 = { subject: 'acct:foo@ap.example.com', links: [{ rel: 'self', href: 'https://ap.example.com/users/foo', type: 'application/activity+json' }] } - stub_request(:get, 'https://evil.example.com/.well-known/webfinger?resource=acct:foo@evil.example.com').to_return(body: Oj.dump(webfinger2), headers: { 'Content-Type': 'application/jrd+json' }) + stub_request(:get, 'https://evil.example.com/.well-known/webfinger?resource=acct:foo@evil.example.com').to_return(body: JSON.dump(webfinger2), headers: { 'Content-Type': 'application/jrd+json' }) end it 'does not return a new remote account' do @@ -150,7 +150,7 @@ RSpec.describe ResolveAccountService do end context 'with webfinger response subject missing a host value' do - let(:body) { Oj.dump({ subject: 'user@' }) } + let(:body) { JSON.dump({ subject: 'user@' }) } let(:url) { 'https://host.example/.well-known/webfinger?resource=acct:user@host.example' } before do diff --git a/spec/services/software_update_check_service_spec.rb b/spec/services/software_update_check_service_spec.rb index 73ffe6b899..30d841b4a0 100644 --- a/spec/services/software_update_check_service_spec.rb +++ b/spec/services/software_update_check_service_spec.rb @@ -82,7 +82,7 @@ RSpec.describe SoftwareUpdateCheckService do end before do - stub_request(:get, full_update_check_url).to_return(body: Oj.dump(server_json)) + stub_request(:get, full_update_check_url).to_return(body: JSON.dump(server_json)) end it 'updates the list of known updates' do diff --git a/spec/workers/activitypub/fetch_replies_worker_spec.rb b/spec/workers/activitypub/fetch_replies_worker_spec.rb index 56d19705a4..10980040c8 100644 --- a/spec/workers/activitypub/fetch_replies_worker_spec.rb +++ b/spec/workers/activitypub/fetch_replies_worker_spec.rb @@ -17,7 +17,7 @@ RSpec.describe ActivityPub::FetchRepliesWorker do } end - let(:json) { Oj.dump(payload) } + let(:json) { JSON.dump(payload) } describe 'perform' do it 'performs a request if the collection URI is from the same host' do From e1943f4a29d62a5de960d6bf76fc4608fd2f0e48 Mon Sep 17 00:00:00 2001 From: Matt Jankowski Date: Wed, 30 Oct 2024 15:37:58 -0400 Subject: [PATCH 2/6] Replace `Oj` with plain `JSON` across app/ --- app/controllers/activitypub/inboxes_controller.rb | 2 +- app/controllers/api/v1/accounts_controller.rb | 2 +- app/controllers/api/v1/markers_controller.rb | 2 +- app/controllers/api/v1/statuses/pins_controller.rb | 4 ++-- app/helpers/jsonld_helper.rb | 2 +- app/helpers/react_component_helper.rb | 4 ++-- app/lib/access_token_extension.rb | 2 +- app/lib/activitypub/activity/create.rb | 2 +- app/lib/activitypub/activity/follow.rb | 2 +- app/lib/activitypub/forwarder.rb | 2 +- .../dimension/software_versions_dimension.rb | 2 +- app/lib/application_extension.rb | 2 +- app/lib/feed_manager.rb | 4 ++-- app/lib/link_details_extractor.rb | 2 +- app/lib/translation_service/deepl.rb | 4 ++-- app/lib/translation_service/libre_translate.rb | 6 +++--- app/lib/user_settings_serializer.rb | 4 ++-- app/lib/video_metadata_extractor.rb | 2 +- app/lib/webfinger.rb | 2 +- app/lib/webhooks/payload_renderer.rb | 4 ++-- app/models/custom_filter.rb | 4 ++-- app/models/relay.rb | 4 ++-- app/models/user.rb | 2 +- .../activitypub/process_collection_service.rb | 2 +- .../activitypub/synchronize_followers_service.rb | 2 +- .../after_block_domain_from_account_service.rb | 2 +- app/services/authorize_follow_service.rb | 2 +- app/services/backup_service.rb | 14 +++++++------- app/services/batched_remove_status_service.rb | 2 +- app/services/block_service.rb | 2 +- app/services/create_featured_tag_service.rb | 2 +- app/services/delete_account_service.rb | 6 +++--- app/services/fan_out_on_write_service.rb | 2 +- app/services/favourite_service.rb | 2 +- app/services/fetch_oembed_service.rb | 2 +- app/services/follow_service.rb | 2 +- app/services/notify_service.rb | 2 +- app/services/reblog_service.rb | 2 +- app/services/reject_follow_service.rb | 2 +- .../remove_domains_from_followers_service.rb | 2 +- app/services/remove_featured_tag_service.rb | 2 +- app/services/remove_from_followers_service.rb | 2 +- app/services/remove_status_service.rb | 4 ++-- app/services/report_service.rb | 2 +- app/services/software_update_check_service.rb | 2 +- app/services/suspend_account_service.rb | 4 ++-- app/services/unblock_service.rb | 2 +- app/services/unfavourite_service.rb | 2 +- app/services/unfollow_service.rb | 4 ++-- app/services/unsuspend_account_service.rb | 2 +- app/services/vote_service.rb | 2 +- app/services/webhook_service.rb | 2 +- app/validators/reaction_validator.rb | 2 +- app/views/shared/_web_app.html.haml | 2 +- app/views/shares/show.html.haml | 2 +- app/views/statuses/embed.html.haml | 2 +- .../activitypub/distribute_poll_update_worker.rb | 2 +- app/workers/activitypub/distribution_worker.rb | 2 +- .../activitypub/move_distribution_worker.rb | 2 +- .../activitypub/update_distribution_worker.rb | 2 +- .../publish_announcement_reaction_worker.rb | 2 +- .../publish_scheduled_announcement_worker.rb | 2 +- app/workers/push_conversation_worker.rb | 2 +- app/workers/push_update_worker.rb | 2 +- app/workers/scheduler/self_destruct_scheduler.rb | 2 +- app/workers/unfilter_notifications_worker.rb | 2 +- app/workers/unpublish_announcement_worker.rb | 2 +- app/workers/web/push_notification_worker.rb | 2 +- 68 files changed, 89 insertions(+), 89 deletions(-) diff --git a/app/controllers/activitypub/inboxes_controller.rb b/app/controllers/activitypub/inboxes_controller.rb index 49cfc8ad1c..43a640501c 100644 --- a/app/controllers/activitypub/inboxes_controller.rb +++ b/app/controllers/activitypub/inboxes_controller.rb @@ -21,7 +21,7 @@ class ActivityPub::InboxesController < ActivityPub::BaseController end def unknown_affected_account? - json = Oj.load(body, mode: :strict) + json = JSON.parse(body) json.is_a?(Hash) && %w(Delete Update).include?(json['type']) && json['actor'].present? && json['actor'] == value_or_id(json['object']) && !Account.exists?(uri: json['actor']) rescue Oj::ParseError false diff --git a/app/controllers/api/v1/accounts_controller.rb b/app/controllers/api/v1/accounts_controller.rb index f7d3de7f94..3d81e22c55 100644 --- a/app/controllers/api/v1/accounts_controller.rb +++ b/app/controllers/api/v1/accounts_controller.rb @@ -37,7 +37,7 @@ class Api::V1::AccountsController < Api::BaseController headers.merge!(response.headers) - self.response_body = Oj.dump(response.body) + self.response_body = JSON.dump(response.body) self.status = response.status rescue ActiveRecord::RecordInvalid => e render json: ValidationErrorFormatter.new(e, 'account.username': :username, 'invite_request.text': :reason).as_json, status: 422 diff --git a/app/controllers/api/v1/markers_controller.rb b/app/controllers/api/v1/markers_controller.rb index 8eaf7767df..8422e9fa94 100644 --- a/app/controllers/api/v1/markers_controller.rb +++ b/app/controllers/api/v1/markers_controller.rb @@ -38,7 +38,7 @@ class Api::V1::MarkersController < Api::BaseController serialized[key] = ActiveModelSerializers::SerializableResource.new(value, serializer: REST::MarkerSerializer).as_json end - Oj.dump(serialized) + JSON.dump(serialized) end def resource_params diff --git a/app/controllers/api/v1/statuses/pins_controller.rb b/app/controllers/api/v1/statuses/pins_controller.rb index 7107890af1..1208cd35d3 100644 --- a/app/controllers/api/v1/statuses/pins_controller.rb +++ b/app/controllers/api/v1/statuses/pins_controller.rb @@ -30,7 +30,7 @@ class Api::V1::Statuses::PinsController < Api::V1::Statuses::BaseController adapter: ActivityPub::Adapter ).as_json - ActivityPub::RawDistributionWorker.perform_async(Oj.dump(json), current_account.id) + ActivityPub::RawDistributionWorker.perform_async(JSON.dump(json), current_account.id) end def distribute_remove_activity! @@ -40,6 +40,6 @@ class Api::V1::Statuses::PinsController < Api::V1::Statuses::BaseController adapter: ActivityPub::Adapter ).as_json - ActivityPub::RawDistributionWorker.perform_async(Oj.dump(json), current_account.id) + ActivityPub::RawDistributionWorker.perform_async(JSON.dump(json), current_account.id) end end diff --git a/app/helpers/jsonld_helper.rb b/app/helpers/jsonld_helper.rb index ba096427cf..45762abf2a 100644 --- a/app/helpers/jsonld_helper.rb +++ b/app/helpers/jsonld_helper.rb @@ -191,7 +191,7 @@ module JsonLdHelper end def body_to_json(body, compare_id: nil) - json = body.is_a?(String) ? Oj.load(body, mode: :strict) : body + json = body.is_a?(String) ? JSON.parse(body) : body return if compare_id.present? && json['id'] != compare_id diff --git a/app/helpers/react_component_helper.rb b/app/helpers/react_component_helper.rb index 821a6f1e2d..ca0f96b4eb 100644 --- a/app/helpers/react_component_helper.rb +++ b/app/helpers/react_component_helper.rb @@ -2,7 +2,7 @@ module ReactComponentHelper def react_component(name, props = {}, &block) - data = { component: name.to_s.camelcase, props: Oj.dump(props) } + data = { component: name.to_s.camelcase, props: JSON.dump(props) } if block.nil? div_tag_with_data(data) else @@ -11,7 +11,7 @@ module ReactComponentHelper end def react_admin_component(name, props = {}) - data = { 'admin-component': name.to_s.camelcase, props: Oj.dump(props) } + data = { 'admin-component': name.to_s.camelcase, props: JSON.dump(props) } div_tag_with_data(data) end diff --git a/app/lib/access_token_extension.rb b/app/lib/access_token_extension.rb index 6e06f988a5..0ef299dbd3 100644 --- a/app/lib/access_token_extension.rb +++ b/app/lib/access_token_extension.rb @@ -24,6 +24,6 @@ module AccessTokenExtension end def push_to_streaming_api - redis.publish("timeline:access_token:#{id}", Oj.dump(event: :kill)) if revoked? || destroyed? + redis.publish("timeline:access_token:#{id}", JSON.dump(event: :kill)) if revoked? || destroyed? end end diff --git a/app/lib/activitypub/activity/create.rb b/app/lib/activitypub/activity/create.rb index a756912592..59e5baf0b8 100644 --- a/app/lib/activitypub/activity/create.rb +++ b/app/lib/activitypub/activity/create.rb @@ -426,7 +426,7 @@ class ActivityPub::Activity::Create < ActivityPub::Activity def forward_for_reply return unless @status.distributable? && @json['signature'].present? && reply_to_local? - ActivityPub::RawDistributionWorker.perform_async(Oj.dump(@json), replied_to_status.account_id, [@account.preferred_inbox_url]) + ActivityPub::RawDistributionWorker.perform_async(JSON.dump(@json), replied_to_status.account_id, [@account.preferred_inbox_url]) end def increment_voters_count! diff --git a/app/lib/activitypub/activity/follow.rb b/app/lib/activitypub/activity/follow.rb index 97e41ab789..52d2b34f87 100644 --- a/app/lib/activitypub/activity/follow.rb +++ b/app/lib/activitypub/activity/follow.rb @@ -39,7 +39,7 @@ class ActivityPub::Activity::Follow < ActivityPub::Activity end def reject_follow_request!(target_account) - json = Oj.dump(serialize_payload(FollowRequest.new(account: @account, target_account: target_account, uri: @json['id']), ActivityPub::RejectFollowSerializer)) + json = JSON.dump(serialize_payload(FollowRequest.new(account: @account, target_account: target_account, uri: @json['id']), ActivityPub::RejectFollowSerializer)) ActivityPub::DeliveryWorker.perform_async(json, target_account.id, @account.inbox_url) end end diff --git a/app/lib/activitypub/forwarder.rb b/app/lib/activitypub/forwarder.rb index 3a94f9669a..ac16be31be 100644 --- a/app/lib/activitypub/forwarder.rb +++ b/app/lib/activitypub/forwarder.rb @@ -20,7 +20,7 @@ class ActivityPub::Forwarder private def payload - @payload ||= Oj.dump(@json) + @payload ||= JSON.dump(@json) end def reblogged_by_account_ids diff --git a/app/lib/admin/metrics/dimension/software_versions_dimension.rb b/app/lib/admin/metrics/dimension/software_versions_dimension.rb index 84ffc41d74..bd79e25c9e 100644 --- a/app/lib/admin/metrics/dimension/software_versions_dimension.rb +++ b/app/lib/admin/metrics/dimension/software_versions_dimension.rb @@ -106,7 +106,7 @@ class Admin::Metrics::Dimension::SoftwareVersionsDimension < Admin::Metrics::Dim def ffmpeg_version version_output = Terrapin::CommandLine.new(Rails.configuration.x.ffprobe_binary, '-show_program_version -v 0 -of json').run - version = Oj.load(version_output, mode: :strict, symbol_keys: true).dig(:program_version, :version) + version = JSON.parse(version_output, symbolize_names: true).dig(:program_version, :version) { key: 'ffmpeg', diff --git a/app/lib/application_extension.rb b/app/lib/application_extension.rb index d7aaeba5bd..b5a4c8f690 100644 --- a/app/lib/application_extension.rb +++ b/app/lib/application_extension.rb @@ -31,7 +31,7 @@ module ApplicationExtension def close_streaming_sessions(resource_owner = nil) # TODO: #28793 Combine into a single topic - payload = Oj.dump(event: :kill) + payload = JSON.dump(event: :kill) scope = access_tokens scope = scope.where(resource_owner_id: resource_owner.id) unless resource_owner.nil? scope.in_batches do |tokens| diff --git a/app/lib/feed_manager.rb b/app/lib/feed_manager.rb index 8a0043268b..dd410872f7 100644 --- a/app/lib/feed_manager.rb +++ b/app/lib/feed_manager.rb @@ -81,7 +81,7 @@ class FeedManager def unpush_from_home(account, status, update: false) return false unless remove_from_feed(:home, account.id, status, aggregate_reblogs: account.user&.aggregates_reblogs?) - redis.publish("timeline:#{account.id}", Oj.dump(event: :delete, payload: status.id.to_s)) unless update + redis.publish("timeline:#{account.id}", JSON.dump(event: :delete, payload: status.id.to_s)) unless update true end @@ -108,7 +108,7 @@ class FeedManager def unpush_from_list(list, status, update: false) return false unless remove_from_feed(:list, list.id, status, aggregate_reblogs: list.account.user&.aggregates_reblogs?) - redis.publish("timeline:list:#{list.id}", Oj.dump(event: :delete, payload: status.id.to_s)) unless update + redis.publish("timeline:list:#{list.id}", JSON.dump(event: :delete, payload: status.id.to_s)) unless update true end diff --git a/app/lib/link_details_extractor.rb b/app/lib/link_details_extractor.rb index fe7f23f481..91729e55df 100644 --- a/app/lib/link_details_extractor.rb +++ b/app/lib/link_details_extractor.rb @@ -101,7 +101,7 @@ class LinkDetailsExtractor end def json - @json ||= root_array(Oj.load(@data)).compact.find { |obj| SUPPORTED_TYPES.include?(obj['@type']) } || {} + @json ||= root_array(JSON.parse(@data)).compact.find { |obj| SUPPORTED_TYPES.include?(obj['@type']) } || {} end end diff --git a/app/lib/translation_service/deepl.rb b/app/lib/translation_service/deepl.rb index 7761dbe626..59c255a7ce 100644 --- a/app/lib/translation_service/deepl.rb +++ b/app/lib/translation_service/deepl.rb @@ -31,7 +31,7 @@ class TranslationService::DeepL < TranslationService def fetch_languages(type) request(:get, "/v2/languages?type=#{type}") do |res| - Oj.load(res.body_with_limit).map { |language| normalize_language(language['language']) } + JSON.parse(res.body_with_limit).map { |language| normalize_language(language['language']) } end end @@ -68,7 +68,7 @@ class TranslationService::DeepL < TranslationService end def transform_response(json) - data = Oj.load(json, mode: :strict) + data = JSON.parse(json) raise UnexpectedResponseError unless data.is_a?(Hash) data['translations'].map do |translation| diff --git a/app/lib/translation_service/libre_translate.rb b/app/lib/translation_service/libre_translate.rb index 0df8590f87..8d6472c215 100644 --- a/app/lib/translation_service/libre_translate.rb +++ b/app/lib/translation_service/libre_translate.rb @@ -9,7 +9,7 @@ class TranslationService::LibreTranslate < TranslationService end def translate(texts, source_language, target_language) - body = Oj.dump(q: texts, source: source_language.presence || 'auto', target: target_language, format: 'html', api_key: @api_key) + body = JSON.dump(q: texts, source: source_language.presence || 'auto', target: target_language, format: 'html', api_key: @api_key) request(:post, '/translate', body: body) do |res| transform_response(res.body_with_limit, source_language) end @@ -17,7 +17,7 @@ class TranslationService::LibreTranslate < TranslationService def languages request(:get, '/languages') do |res| - languages = Oj.load(res.body_with_limit).to_h do |language| + languages = JSON.parse(res.body_with_limit).to_h do |language| [language['code'], language['targets'].without(language['code'])] end languages[nil] = languages.values.flatten.uniq.sort @@ -45,7 +45,7 @@ class TranslationService::LibreTranslate < TranslationService end def transform_response(json, source_language) - data = Oj.load(json, mode: :strict) + data = JSON.parse(json) raise UnexpectedResponseError unless data.is_a?(Hash) data['translatedText'].map.with_index do |text, index| diff --git a/app/lib/user_settings_serializer.rb b/app/lib/user_settings_serializer.rb index 10d1be04d5..f393aa4a8e 100644 --- a/app/lib/user_settings_serializer.rb +++ b/app/lib/user_settings_serializer.rb @@ -6,7 +6,7 @@ class UserSettingsSerializer if value.blank? {} else - Oj.load(value, symbol_keys: true) + JSON.parse(value, symbolize_names: true) end end @@ -14,6 +14,6 @@ class UserSettingsSerializer end def self.dump(value) - Oj.dump(value.as_json) + JSON.dump(value.as_json) end end diff --git a/app/lib/video_metadata_extractor.rb b/app/lib/video_metadata_extractor.rb index 6e544486d6..66f4c1b772 100644 --- a/app/lib/video_metadata_extractor.rb +++ b/app/lib/video_metadata_extractor.rb @@ -6,7 +6,7 @@ class VideoMetadataExtractor def initialize(path) @path = path - @metadata = Oj.load(ffmpeg_command_output, mode: :strict, symbol_keys: true) + @metadata = JSON.parse(ffmpeg_command_output, symbolize_names: true) parse_metadata rescue Terrapin::ExitStatusError, Oj::ParseError diff --git a/app/lib/webfinger.rb b/app/lib/webfinger.rb index 01a5dbc21d..6e13d2f163 100644 --- a/app/lib/webfinger.rb +++ b/app/lib/webfinger.rb @@ -12,7 +12,7 @@ class Webfinger def initialize(uri, body) @uri = uri - @json = Oj.load(body, mode: :strict) + @json = JSON.parse(body) validate_response! end diff --git a/app/lib/webhooks/payload_renderer.rb b/app/lib/webhooks/payload_renderer.rb index 3d2731f6dc..a7f17848ac 100644 --- a/app/lib/webhooks/payload_renderer.rb +++ b/app/lib/webhooks/payload_renderer.rb @@ -10,7 +10,7 @@ class Webhooks::PayloadRenderer def get(path) value = @document.dig(*parse_path(path)) - string = Oj.dump(value) + string = JSON.dump(value) # We want to make sure people can use the variable inside # other strings, so it can't be wrapped in quotes. @@ -58,7 +58,7 @@ class Webhooks::PayloadRenderer /iox def initialize(json) - @document = DocumentTraverser.new(Oj.load(json)) + @document = DocumentTraverser.new(JSON.parse(json)) end def render(template) diff --git a/app/models/custom_filter.rb b/app/models/custom_filter.rb index a351a140a0..1b6e9d06fd 100644 --- a/app/models/custom_filter.rb +++ b/app/models/custom_filter.rb @@ -112,8 +112,8 @@ class CustomFilter < ApplicationRecord @should_invalidate_cache = false Rails.cache.delete("filters:v3:#{account_id}") - redis.publish("timeline:#{account_id}", Oj.dump(event: :filters_changed)) - redis.publish("timeline:system:#{account_id}", Oj.dump(event: :filters_changed)) + redis.publish("timeline:#{account_id}", JSON.dump(event: :filters_changed)) + redis.publish("timeline:system:#{account_id}", JSON.dump(event: :filters_changed)) end private diff --git a/app/models/relay.rb b/app/models/relay.rb index 813a861c68..d38f273b19 100644 --- a/app/models/relay.rb +++ b/app/models/relay.rb @@ -31,7 +31,7 @@ class Relay < ApplicationRecord def enable! activity_id = ActivityPub::TagManager.instance.generate_uri_for(nil) - payload = Oj.dump(follow_activity(activity_id)) + payload = JSON.dump(follow_activity(activity_id)) update!(state: :pending, follow_activity_id: activity_id) DeliveryFailureTracker.reset!(inbox_url) @@ -40,7 +40,7 @@ class Relay < ApplicationRecord def disable! activity_id = ActivityPub::TagManager.instance.generate_uri_for(nil) - payload = Oj.dump(unfollow_activity(activity_id)) + payload = JSON.dump(unfollow_activity(activity_id)) update!(state: :idle, follow_activity_id: nil) DeliveryFailureTracker.reset!(inbox_url) diff --git a/app/models/user.rb b/app/models/user.rb index ce24d34651..2bccaa19c3 100644 --- a/app/models/user.rb +++ b/app/models/user.rb @@ -359,7 +359,7 @@ class User < ApplicationRecord # Revoke each access token for the Streaming API, since `update_all`` # doesn't trigger ActiveRecord Callbacks: # TODO: #28793 Combine into a single topic - payload = Oj.dump(event: :kill) + payload = JSON.dump(event: :kill) redis.pipelined do |pipeline| batch.ids.each do |id| pipeline.publish("timeline:access_token:#{id}", payload) diff --git a/app/services/activitypub/process_collection_service.rb b/app/services/activitypub/process_collection_service.rb index cadc7d2d10..d9ba5d5822 100644 --- a/app/services/activitypub/process_collection_service.rb +++ b/app/services/activitypub/process_collection_service.rb @@ -6,7 +6,7 @@ class ActivityPub::ProcessCollectionService < BaseService def call(body, actor, **options) @account = actor - @json = original_json = Oj.load(body, mode: :strict) + @json = original_json = JSON.parse(body) @options = options return unless @json.is_a?(Hash) diff --git a/app/services/activitypub/synchronize_followers_service.rb b/app/services/activitypub/synchronize_followers_service.rb index f51d671a00..93a19cee29 100644 --- a/app/services/activitypub/synchronize_followers_service.rb +++ b/app/services/activitypub/synchronize_followers_service.rb @@ -47,7 +47,7 @@ class ActivityPub::SynchronizeFollowersService < BaseService end def build_undo_follow_json(follow) - Oj.dump(serialize_payload(follow, ActivityPub::UndoFollowSerializer)) + JSON.dump(serialize_payload(follow, ActivityPub::UndoFollowSerializer)) end def collection_items(collection_or_uri) diff --git a/app/services/after_block_domain_from_account_service.rb b/app/services/after_block_domain_from_account_service.rb index fc5dc65681..d8d1c9cc49 100644 --- a/app/services/after_block_domain_from_account_service.rb +++ b/app/services/after_block_domain_from_account_service.rb @@ -54,7 +54,7 @@ class AfterBlockDomainFromAccountService < BaseService return unless follow.account.activitypub? - ActivityPub::DeliveryWorker.perform_async(Oj.dump(serialize_payload(follow, ActivityPub::RejectFollowSerializer)), @account.id, follow.account.inbox_url) + ActivityPub::DeliveryWorker.perform_async(JSON.dump(serialize_payload(follow, ActivityPub::RejectFollowSerializer)), @account.id, follow.account.inbox_url) end def notify_of_severed_relationships! diff --git a/app/services/authorize_follow_service.rb b/app/services/authorize_follow_service.rb index 49bef727e6..ae91cf9109 100644 --- a/app/services/authorize_follow_service.rb +++ b/app/services/authorize_follow_service.rb @@ -22,6 +22,6 @@ class AuthorizeFollowService < BaseService end def build_json(follow_request) - Oj.dump(serialize_payload(follow_request, ActivityPub::AcceptFollowSerializer)) + JSON.dump(serialize_payload(follow_request, ActivityPub::AcceptFollowSerializer)) end end diff --git a/app/services/backup_service.rb b/app/services/backup_service.rb index 133a764873..f6a28ba068 100644 --- a/app/services/backup_service.rb +++ b/app/services/backup_service.rb @@ -21,7 +21,7 @@ class BackupService < BaseService skeleton = serialize(collection_presenter, ActivityPub::CollectionSerializer) skeleton[:@context] = full_context skeleton[:orderedItems] = ['!PLACEHOLDER!'] - skeleton = Oj.dump(skeleton) + skeleton = JSON.dump(skeleton) prepend, append = skeleton.split('"!PLACEHOLDER!"') add_comma = false @@ -41,7 +41,7 @@ class BackupService < BaseService end end - Oj.dump(item) + JSON.dump(item) end.join(',')) GC.start @@ -104,7 +104,7 @@ class BackupService < BaseService download_to_zip(zipfile, account.avatar, "avatar#{File.extname(account.avatar.path)}") if account.avatar.exists? download_to_zip(zipfile, account.header, "header#{File.extname(account.header.path)}") if account.header.exists? - json = Oj.dump(actor) + json = JSON.dump(actor) zipfile.get_output_stream('actor.json') do |io| io.write(json) @@ -115,7 +115,7 @@ class BackupService < BaseService skeleton = serialize(ActivityPub::CollectionPresenter.new(id: 'likes.json', type: :ordered, size: 0, items: []), ActivityPub::CollectionSerializer) skeleton.delete(:totalItems) skeleton[:orderedItems] = ['!PLACEHOLDER!'] - skeleton = Oj.dump(skeleton) + skeleton = JSON.dump(skeleton) prepend, append = skeleton.split('"!PLACEHOLDER!"') zipfile.get_output_stream('likes.json') do |io| @@ -128,7 +128,7 @@ class BackupService < BaseService add_comma = true io.write(statuses.map do |status| - Oj.dump(ActivityPub::TagManager.instance.uri_for(status)) + JSON.dump(ActivityPub::TagManager.instance.uri_for(status)) end.join(',')) GC.start @@ -142,7 +142,7 @@ class BackupService < BaseService skeleton = serialize(ActivityPub::CollectionPresenter.new(id: 'bookmarks.json', type: :ordered, size: 0, items: []), ActivityPub::CollectionSerializer) skeleton.delete(:totalItems) skeleton[:orderedItems] = ['!PLACEHOLDER!'] - skeleton = Oj.dump(skeleton) + skeleton = JSON.dump(skeleton) prepend, append = skeleton.split('"!PLACEHOLDER!"') zipfile.get_output_stream('bookmarks.json') do |io| @@ -154,7 +154,7 @@ class BackupService < BaseService add_comma = true io.write(statuses.map do |status| - Oj.dump(ActivityPub::TagManager.instance.uri_for(status)) + JSON.dump(ActivityPub::TagManager.instance.uri_for(status)) end.join(',')) GC.start diff --git a/app/services/batched_remove_status_service.rb b/app/services/batched_remove_status_service.rb index de4ee16e91..40e7137dd4 100644 --- a/app/services/batched_remove_status_service.rb +++ b/app/services/batched_remove_status_service.rb @@ -82,7 +82,7 @@ class BatchedRemoveStatusService < BaseService def unpush_from_public_timelines(status, pipeline) return unless status.public_visibility? && status.id > @status_id_cutoff - payload = Oj.dump(event: :delete, payload: status.id.to_s) + payload = JSON.dump(event: :delete, payload: status.id.to_s) pipeline.publish('timeline:public', payload) pipeline.publish(status.local? ? 'timeline:public:local' : 'timeline:public:remote', payload) diff --git a/app/services/block_service.rb b/app/services/block_service.rb index 98229d98c0..0bee741f89 100644 --- a/app/services/block_service.rb +++ b/app/services/block_service.rb @@ -26,6 +26,6 @@ class BlockService < BaseService end def build_json(block) - Oj.dump(serialize_payload(block, ActivityPub::BlockSerializer)) + JSON.dump(serialize_payload(block, ActivityPub::BlockSerializer)) end end diff --git a/app/services/create_featured_tag_service.rb b/app/services/create_featured_tag_service.rb index 3cc59156db..99a8cc25aa 100644 --- a/app/services/create_featured_tag_service.rb +++ b/app/services/create_featured_tag_service.rb @@ -20,6 +20,6 @@ class CreateFeaturedTagService < BaseService private def build_json(featured_tag) - Oj.dump(serialize_payload(featured_tag, ActivityPub::AddSerializer, signer: @account)) + JSON.dump(serialize_payload(featured_tag, ActivityPub::AddSerializer, signer: @account)) end end diff --git a/app/services/delete_account_service.rb b/app/services/delete_account_service.rb index 7d06302af5..63bbd20c74 100644 --- a/app/services/delete_account_service.rb +++ b/app/services/delete_account_service.rb @@ -114,7 +114,7 @@ class DeleteAccountService < BaseService # we have to force it to unfollow them. ActivityPub::DeliveryWorker.push_bulk(Follow.where(account: @account)) do |follow| - [Oj.dump(serialize_payload(follow, ActivityPub::RejectFollowSerializer)), follow.target_account_id, @account.inbox_url] + [JSON.dump(serialize_payload(follow, ActivityPub::RejectFollowSerializer)), follow.target_account_id, @account.inbox_url] end end @@ -126,7 +126,7 @@ class DeleteAccountService < BaseService # if the remote account gets un-suspended. ActivityPub::DeliveryWorker.push_bulk(Follow.where(target_account: @account)) do |follow| - [Oj.dump(serialize_payload(follow, ActivityPub::UndoFollowSerializer)), follow.account_id, @account.inbox_url] + [JSON.dump(serialize_payload(follow, ActivityPub::UndoFollowSerializer)), follow.account_id, @account.inbox_url] end end @@ -285,7 +285,7 @@ class DeleteAccountService < BaseService end def delete_actor_json - @delete_actor_json ||= Oj.dump(serialize_payload(@account, ActivityPub::DeleteActorSerializer, signer: @account, always_sign: true)) + @delete_actor_json ||= JSON.dump(serialize_payload(@account, ActivityPub::DeleteActorSerializer, signer: @account, always_sign: true)) end def delivery_inboxes diff --git a/app/services/fan_out_on_write_service.rb b/app/services/fan_out_on_write_service.rb index 3c084bc857..71234174bc 100644 --- a/app/services/fan_out_on_write_service.rb +++ b/app/services/fan_out_on_write_service.rb @@ -154,7 +154,7 @@ class FanOutOnWriteService < BaseService end def anonymous_payload - @anonymous_payload ||= Oj.dump( + @anonymous_payload ||= JSON.dump( event: update? ? :'status.update' : :update, payload: rendered_status ) diff --git a/app/services/favourite_service.rb b/app/services/favourite_service.rb index ded50187f7..6baa1ca460 100644 --- a/app/services/favourite_service.rb +++ b/app/services/favourite_service.rb @@ -42,6 +42,6 @@ class FavouriteService < BaseService end def build_json(favourite) - Oj.dump(serialize_payload(favourite, ActivityPub::LikeSerializer)) + JSON.dump(serialize_payload(favourite, ActivityPub::LikeSerializer)) end end diff --git a/app/services/fetch_oembed_service.rb b/app/services/fetch_oembed_service.rb index c7d4f7e292..c2887e3017 100644 --- a/app/services/fetch_oembed_service.rb +++ b/app/services/fetch_oembed_service.rb @@ -93,7 +93,7 @@ class FetchOEmbedService def parse_for_format(body) case @format when :json - Oj.load(body, mode: :strict)&.with_indifferent_access + JSON.parse(body)&.with_indifferent_access when :xml Ox.load(body, mode: :hash_no_attrs)&.with_indifferent_access&.dig(:oembed) end diff --git a/app/services/follow_service.rb b/app/services/follow_service.rb index cff38b8e6e..676f42101a 100644 --- a/app/services/follow_service.rb +++ b/app/services/follow_service.rb @@ -90,7 +90,7 @@ class FollowService < BaseService end def build_json(follow_request) - Oj.dump(serialize_payload(follow_request, ActivityPub::FollowSerializer)) + JSON.dump(serialize_payload(follow_request, ActivityPub::FollowSerializer)) end def follow_options diff --git a/app/services/notify_service.rb b/app/services/notify_service.rb index e87e5024fe..a3d2501e9b 100644 --- a/app/services/notify_service.rb +++ b/app/services/notify_service.rb @@ -258,7 +258,7 @@ class NotifyService < BaseService end def push_to_streaming_api! - redis.publish("timeline:#{@recipient.id}:notifications", Oj.dump(event: :notification, payload: InlineRenderer.render(@notification, @recipient, :notification))) + redis.publish("timeline:#{@recipient.id}:notifications", JSON.dump(event: :notification, payload: InlineRenderer.render(@notification, @recipient, :notification))) end def subscribed_to_streaming_api? diff --git a/app/services/reblog_service.rb b/app/services/reblog_service.rb index cca79eced6..48cc08e286 100644 --- a/app/services/reblog_service.rb +++ b/app/services/reblog_service.rb @@ -51,6 +51,6 @@ class ReblogService < BaseService end def build_json(reblog) - Oj.dump(serialize_payload(ActivityPub::ActivityPresenter.from_status(reblog), ActivityPub::ActivitySerializer, signer: reblog.account)) + JSON.dump(serialize_payload(ActivityPub::ActivityPresenter.from_status(reblog), ActivityPub::ActivitySerializer, signer: reblog.account)) end end diff --git a/app/services/reject_follow_service.rb b/app/services/reject_follow_service.rb index bc0000c8c8..f09cd9ecae 100644 --- a/app/services/reject_follow_service.rb +++ b/app/services/reject_follow_service.rb @@ -17,6 +17,6 @@ class RejectFollowService < BaseService end def build_json(follow_request) - Oj.dump(serialize_payload(follow_request, ActivityPub::RejectFollowSerializer)) + JSON.dump(serialize_payload(follow_request, ActivityPub::RejectFollowSerializer)) end end diff --git a/app/services/remove_domains_from_followers_service.rb b/app/services/remove_domains_from_followers_service.rb index d76763409d..d7384cf50f 100644 --- a/app/services/remove_domains_from_followers_service.rb +++ b/app/services/remove_domains_from_followers_service.rb @@ -18,6 +18,6 @@ class RemoveDomainsFromFollowersService < BaseService end def build_json(follow) - Oj.dump(serialize_payload(follow, ActivityPub::RejectFollowSerializer)) + JSON.dump(serialize_payload(follow, ActivityPub::RejectFollowSerializer)) end end diff --git a/app/services/remove_featured_tag_service.rb b/app/services/remove_featured_tag_service.rb index 2aa70e8fc6..5a1f8f754f 100644 --- a/app/services/remove_featured_tag_service.rb +++ b/app/services/remove_featured_tag_service.rb @@ -13,6 +13,6 @@ class RemoveFeaturedTagService < BaseService private def build_json(featured_tag) - Oj.dump(serialize_payload(featured_tag, ActivityPub::RemoveSerializer, signer: @account)) + JSON.dump(serialize_payload(featured_tag, ActivityPub::RemoveSerializer, signer: @account)) end end diff --git a/app/services/remove_from_followers_service.rb b/app/services/remove_from_followers_service.rb index 007d5b1fdd..32cb6e3d3c 100644 --- a/app/services/remove_from_followers_service.rb +++ b/app/services/remove_from_followers_service.rb @@ -18,6 +18,6 @@ class RemoveFromFollowersService < BaseService end def build_json(follow) - Oj.dump(serialize_payload(follow, ActivityPub::RejectFollowSerializer)) + JSON.dump(serialize_payload(follow, ActivityPub::RejectFollowSerializer)) end end diff --git a/app/services/remove_status_service.rb b/app/services/remove_status_service.rb index dc9fb6cab6..99cff7fee6 100644 --- a/app/services/remove_status_service.rb +++ b/app/services/remove_status_service.rb @@ -14,7 +14,7 @@ class RemoveStatusService < BaseService # @option [Boolean] :original_removed # @option [Boolean] :skip_streaming def call(status, **options) - @payload = Oj.dump(event: :delete, payload: status.id.to_s) + @payload = JSON.dump(event: :delete, payload: status.id.to_s) @status = status @account = status.account @options = options @@ -100,7 +100,7 @@ class RemoveStatusService < BaseService end def signed_activity_json - @signed_activity_json ||= Oj.dump(serialize_payload(@status, @status.reblog? ? ActivityPub::UndoAnnounceSerializer : ActivityPub::DeleteSerializer, signer: @account, always_sign: true)) + @signed_activity_json ||= JSON.dump(serialize_payload(@status, @status.reblog? ? ActivityPub::UndoAnnounceSerializer : ActivityPub::DeleteSerializer, signer: @account, always_sign: true)) end def remove_reblogs diff --git a/app/services/report_service.rb b/app/services/report_service.rb index c95e216c79..32e9d79c3f 100644 --- a/app/services/report_service.rb +++ b/app/services/report_service.rb @@ -92,7 +92,7 @@ class ReportService < BaseService end def payload - Oj.dump(serialize_payload(@report, ActivityPub::FlagSerializer, account: some_local_account)) + JSON.dump(serialize_payload(@report, ActivityPub::FlagSerializer, account: some_local_account)) end def some_local_account diff --git a/app/services/software_update_check_service.rb b/app/services/software_update_check_service.rb index 45ec1f50db..e3bc112964 100644 --- a/app/services/software_update_check_service.rb +++ b/app/services/software_update_check_service.rb @@ -20,7 +20,7 @@ class SoftwareUpdateCheckService < BaseService def fetch_update_notices Request.new(:get, "#{api_url}?version=#{version}").add_headers('Accept' => 'application/json', 'User-Agent' => 'Mastodon update checker').perform do |res| - return Oj.load(res.body_with_limit, mode: :strict) if res.code == 200 + return JSON.parse(res.body_with_limit) if res.code == 200 end rescue *Mastodon::HTTP_CONNECTION_ERRORS, Oj::ParseError nil diff --git a/app/services/suspend_account_service.rb b/app/services/suspend_account_service.rb index 44210799f9..6a7833ef14 100644 --- a/app/services/suspend_account_service.rb +++ b/app/services/suspend_account_service.rb @@ -33,7 +33,7 @@ class SuspendAccountService < BaseService Follow.where(account: @account).find_in_batches do |follows| ActivityPub::DeliveryWorker.push_bulk(follows) do |follow| - [Oj.dump(serialize_payload(follow, ActivityPub::RejectFollowSerializer)), follow.target_account_id, @account.inbox_url] + [JSON.dump(serialize_payload(follow, ActivityPub::RejectFollowSerializer)), follow.target_account_id, @account.inbox_url] end follows.each(&:destroy) @@ -102,6 +102,6 @@ class SuspendAccountService < BaseService end def signed_activity_json - @signed_activity_json ||= Oj.dump(serialize_payload(@account, ActivityPub::UpdateSerializer, signer: @account)) + @signed_activity_json ||= JSON.dump(serialize_payload(@account, ActivityPub::UpdateSerializer, signer: @account)) end end diff --git a/app/services/unblock_service.rb b/app/services/unblock_service.rb index c263ac8afe..c543750410 100644 --- a/app/services/unblock_service.rb +++ b/app/services/unblock_service.rb @@ -18,6 +18,6 @@ class UnblockService < BaseService end def build_json(unblock) - Oj.dump(serialize_payload(unblock, ActivityPub::UndoBlockSerializer)) + JSON.dump(serialize_payload(unblock, ActivityPub::UndoBlockSerializer)) end end diff --git a/app/services/unfavourite_service.rb b/app/services/unfavourite_service.rb index 37917a64f1..d8fec552bc 100644 --- a/app/services/unfavourite_service.rb +++ b/app/services/unfavourite_service.rb @@ -18,6 +18,6 @@ class UnfavouriteService < BaseService end def build_json(favourite) - Oj.dump(serialize_payload(favourite, ActivityPub::UndoLikeSerializer)) + JSON.dump(serialize_payload(favourite, ActivityPub::UndoLikeSerializer)) end end diff --git a/app/services/unfollow_service.rb b/app/services/unfollow_service.rb index b3f2cd66f6..a0d94b22ba 100644 --- a/app/services/unfollow_service.rb +++ b/app/services/unfollow_service.rb @@ -63,10 +63,10 @@ class UnfollowService < BaseService end def build_json(follow) - Oj.dump(serialize_payload(follow, ActivityPub::UndoFollowSerializer)) + JSON.dump(serialize_payload(follow, ActivityPub::UndoFollowSerializer)) end def build_reject_json(follow) - Oj.dump(serialize_payload(follow, ActivityPub::RejectFollowSerializer)) + JSON.dump(serialize_payload(follow, ActivityPub::RejectFollowSerializer)) end end diff --git a/app/services/unsuspend_account_service.rb b/app/services/unsuspend_account_service.rb index 652dd6a845..dbe1147c57 100644 --- a/app/services/unsuspend_account_service.rb +++ b/app/services/unsuspend_account_service.rb @@ -98,6 +98,6 @@ class UnsuspendAccountService < BaseService end def signed_activity_json - @signed_activity_json ||= Oj.dump(serialize_payload(@account, ActivityPub::UpdateSerializer, signer: @account)) + @signed_activity_json ||= JSON.dump(serialize_payload(@account, ActivityPub::UpdateSerializer, signer: @account)) end end diff --git a/app/services/vote_service.rb b/app/services/vote_service.rb index 878350388b..356ecde6a6 100644 --- a/app/services/vote_service.rb +++ b/app/services/vote_service.rb @@ -65,7 +65,7 @@ class VoteService < BaseService end def build_json(vote) - Oj.dump(serialize_payload(vote, ActivityPub::VoteSerializer)) + JSON.dump(serialize_payload(vote, ActivityPub::VoteSerializer)) end def increment_voters_count! diff --git a/app/services/webhook_service.rb b/app/services/webhook_service.rb index aafa383181..4f964c409d 100644 --- a/app/services/webhook_service.rb +++ b/app/services/webhook_service.rb @@ -17,6 +17,6 @@ class WebhookService < BaseService end def serialize_event - Oj.dump(ActiveModelSerializers::SerializableResource.new(@event, serializer: REST::Admin::WebhookEventSerializer, scope: nil, scope_name: :current_user).as_json) + JSON.dump(ActiveModelSerializers::SerializableResource.new(@event, serializer: REST::Admin::WebhookEventSerializer, scope: nil, scope_name: :current_user).as_json) end end diff --git a/app/validators/reaction_validator.rb b/app/validators/reaction_validator.rb index 89d83de5a2..51e6a01f3c 100644 --- a/app/validators/reaction_validator.rb +++ b/app/validators/reaction_validator.rb @@ -1,7 +1,7 @@ # frozen_string_literal: true class ReactionValidator < ActiveModel::Validator - SUPPORTED_EMOJIS = Oj.load_file(Rails.root.join('app', 'javascript', 'mastodon', 'features', 'emoji', 'emoji_map.json').to_s).keys.freeze + SUPPORTED_EMOJIS = JSON.load_file(Rails.root.join('app', 'javascript', 'mastodon', 'features', 'emoji', 'emoji_map.json').to_s).keys.freeze LIMIT = 8 diff --git a/app/views/shared/_web_app.html.haml b/app/views/shared/_web_app.html.haml index 4f9a20a9f4..fbcfa60da0 100644 --- a/app/views/shared/_web_app.html.haml +++ b/app/views/shared/_web_app.html.haml @@ -11,7 +11,7 @@ = render_initial_state = javascript_pack_tag 'application', crossorigin: 'anonymous' -.notranslate.app-holder#mastodon{ data: { props: Oj.dump(default_props) } } +.notranslate.app-holder#mastodon{ data: { props: JSON.dump(default_props) } } %noscript = image_tag frontend_asset_path('images/logo.svg'), alt: 'Mastodon' diff --git a/app/views/shares/show.html.haml b/app/views/shares/show.html.haml index 1c0bbf6765..f54003c972 100644 --- a/app/views/shares/show.html.haml +++ b/app/views/shares/show.html.haml @@ -2,4 +2,4 @@ = render_initial_state = javascript_pack_tag 'share', crossorigin: 'anonymous' -#mastodon-compose{ data: { props: Oj.dump(default_props) } } +#mastodon-compose{ data: { props: JSON.dump(default_props) } } diff --git a/app/views/statuses/embed.html.haml b/app/views/statuses/embed.html.haml index 09d0792ea2..2dba8ddf50 100644 --- a/app/views/statuses/embed.html.haml +++ b/app/views/statuses/embed.html.haml @@ -1 +1 @@ -#mastodon-status{ data: { props: Oj.dump(default_props.merge(id: @status.id.to_s)) } } +#mastodon-status{ data: { props: JSON.dump(default_props.merge(id: @status.id.to_s)) } } diff --git a/app/workers/activitypub/distribute_poll_update_worker.rb b/app/workers/activitypub/distribute_poll_update_worker.rb index 8c1eefd93d..d28cc060cd 100644 --- a/app/workers/activitypub/distribute_poll_update_worker.rb +++ b/app/workers/activitypub/distribute_poll_update_worker.rb @@ -43,7 +43,7 @@ class ActivityPub::DistributePollUpdateWorker end def payload - @payload ||= Oj.dump(serialize_payload(@status, ActivityPub::UpdatePollSerializer, signer: @account)) + @payload ||= JSON.dump(serialize_payload(@status, ActivityPub::UpdatePollSerializer, signer: @account)) end def relay! diff --git a/app/workers/activitypub/distribution_worker.rb b/app/workers/activitypub/distribution_worker.rb index 575e110257..87876cca93 100644 --- a/app/workers/activitypub/distribution_worker.rb +++ b/app/workers/activitypub/distribution_worker.rb @@ -19,7 +19,7 @@ class ActivityPub::DistributionWorker < ActivityPub::RawDistributionWorker end def payload - @payload ||= Oj.dump(serialize_payload(activity, ActivityPub::ActivitySerializer, signer: @account)) + @payload ||= JSON.dump(serialize_payload(activity, ActivityPub::ActivitySerializer, signer: @account)) end def activity diff --git a/app/workers/activitypub/move_distribution_worker.rb b/app/workers/activitypub/move_distribution_worker.rb index 1680fcc76e..3eb9839c5e 100644 --- a/app/workers/activitypub/move_distribution_worker.rb +++ b/app/workers/activitypub/move_distribution_worker.rb @@ -28,6 +28,6 @@ class ActivityPub::MoveDistributionWorker end def signed_payload - @signed_payload ||= Oj.dump(serialize_payload(@migration, ActivityPub::MoveSerializer, signer: @account)) + @signed_payload ||= JSON.dump(serialize_payload(@migration, ActivityPub::MoveSerializer, signer: @account)) end end diff --git a/app/workers/activitypub/update_distribution_worker.rb b/app/workers/activitypub/update_distribution_worker.rb index a04ac621f3..89d9c4a5e8 100644 --- a/app/workers/activitypub/update_distribution_worker.rb +++ b/app/workers/activitypub/update_distribution_worker.rb @@ -21,6 +21,6 @@ class ActivityPub::UpdateDistributionWorker < ActivityPub::RawDistributionWorker end def payload - @payload ||= Oj.dump(serialize_payload(@account, ActivityPub::UpdateSerializer, signer: @account, sign_with: @options[:sign_with])) + @payload ||= JSON.dump(serialize_payload(@account, ActivityPub::UpdateSerializer, signer: @account, sign_with: @options[:sign_with])) end end diff --git a/app/workers/publish_announcement_reaction_worker.rb b/app/workers/publish_announcement_reaction_worker.rb index 03da56550a..e0317d2275 100644 --- a/app/workers/publish_announcement_reaction_worker.rb +++ b/app/workers/publish_announcement_reaction_worker.rb @@ -11,7 +11,7 @@ class PublishAnnouncementReactionWorker reaction ||= announcement.announcement_reactions.new(name: name) payload = InlineRenderer.render(reaction, nil, :reaction).tap { |h| h[:announcement_id] = announcement_id.to_s } - payload = Oj.dump(event: :'announcement.reaction', payload: payload) + payload = JSON.dump(event: :'announcement.reaction', payload: payload) FeedManager.instance.with_active_accounts do |account| redis.publish("timeline:#{account.id}", payload) if redis.exists?("subscribed:timeline:#{account.id}") diff --git a/app/workers/publish_scheduled_announcement_worker.rb b/app/workers/publish_scheduled_announcement_worker.rb index c23eae6af7..732fd468ab 100644 --- a/app/workers/publish_scheduled_announcement_worker.rb +++ b/app/workers/publish_scheduled_announcement_worker.rb @@ -12,7 +12,7 @@ class PublishScheduledAnnouncementWorker @announcement.publish! unless @announcement.published? payload = InlineRenderer.render(@announcement, nil, :announcement) - payload = Oj.dump(event: :announcement, payload: payload) + payload = JSON.dump(event: :announcement, payload: payload) FeedManager.instance.with_active_accounts do |account| redis.publish("timeline:#{account.id}", payload) if redis.exists?("subscribed:timeline:#{account.id}") diff --git a/app/workers/push_conversation_worker.rb b/app/workers/push_conversation_worker.rb index 23b1469f11..3f27c6e34f 100644 --- a/app/workers/push_conversation_worker.rb +++ b/app/workers/push_conversation_worker.rb @@ -9,7 +9,7 @@ class PushConversationWorker message = InlineRenderer.render(conversation, conversation.account, :conversation) timeline_id = "timeline:direct:#{conversation.account_id}" - redis.publish(timeline_id, Oj.dump(event: :conversation, payload: message)) + redis.publish(timeline_id, JSON.dump(event: :conversation, payload: message)) rescue ActiveRecord::RecordNotFound true end diff --git a/app/workers/push_update_worker.rb b/app/workers/push_update_worker.rb index c32975a986..574a9a5a02 100644 --- a/app/workers/push_update_worker.rb +++ b/app/workers/push_update_worker.rb @@ -23,7 +23,7 @@ class PushUpdateWorker end def message - Oj.dump( + JSON.dump( event: update? ? :'status.update' : :update, payload: @payload ) diff --git a/app/workers/scheduler/self_destruct_scheduler.rb b/app/workers/scheduler/self_destruct_scheduler.rb index d0b6ce8a07..544d1811b5 100644 --- a/app/workers/scheduler/self_destruct_scheduler.rb +++ b/app/workers/scheduler/self_destruct_scheduler.rb @@ -60,7 +60,7 @@ class Scheduler::SelfDestructScheduler adapter: ActivityPub::Adapter ).as_json - json = Oj.dump(ActivityPub::LinkedDataSignature.new(payload).sign!(account)) + json = JSON.dump(ActivityPub::LinkedDataSignature.new(payload).sign!(account)) ActivityPub::DeliveryWorker.push_bulk(inboxes, limit: 1_000) do |inbox_url| [json, account.id, inbox_url] diff --git a/app/workers/unfilter_notifications_worker.rb b/app/workers/unfilter_notifications_worker.rb index 53a35ce12c..c1eaa4278a 100644 --- a/app/workers/unfilter_notifications_worker.rb +++ b/app/workers/unfilter_notifications_worker.rb @@ -54,7 +54,7 @@ class UnfilterNotificationsWorker end def push_streaming_event! - redis.publish("timeline:#{@recipient.id}:notifications", Oj.dump(event: :notifications_merged, payload: '1')) + redis.publish("timeline:#{@recipient.id}:notifications", JSON.dump(event: :notifications_merged, payload: '1')) end def subscribed_to_streaming_api? diff --git a/app/workers/unpublish_announcement_worker.rb b/app/workers/unpublish_announcement_worker.rb index e58c07554a..14f3a1ea81 100644 --- a/app/workers/unpublish_announcement_worker.rb +++ b/app/workers/unpublish_announcement_worker.rb @@ -5,7 +5,7 @@ class UnpublishAnnouncementWorker include Redisable def perform(announcement_id) - payload = Oj.dump(event: :'announcement.delete', payload: announcement_id.to_s) + payload = JSON.dump(event: :'announcement.delete', payload: announcement_id.to_s) FeedManager.instance.with_active_accounts do |account| redis.publish("timeline:#{account.id}", payload) if redis.exists?("subscribed:timeline:#{account.id}") diff --git a/app/workers/web/push_notification_worker.rb b/app/workers/web/push_notification_worker.rb index 3629904fa7..78acf0eaab 100644 --- a/app/workers/web/push_notification_worker.rb +++ b/app/workers/web/push_notification_worker.rb @@ -60,7 +60,7 @@ class Web::PushNotificationWorker def push_notification_json I18n.with_locale(@subscription.locale.presence || I18n.default_locale) do - Oj.dump(serialized_notification.as_json) + JSON.dump(serialized_notification.as_json) end end From c4b95481b8b1d2be289bd34ba0e3d6b3fec89b51 Mon Sep 17 00:00:00 2001 From: Matt Jankowski Date: Wed, 30 Oct 2024 15:39:35 -0400 Subject: [PATCH 3/6] Replace `Oj` with plain `JSON` across db/ --- db/migrate/20180608213548_reject_following_blocked_users.rb | 2 +- db/migrate/20230215074423_move_user_settings.rb | 2 +- .../20240304090449_migrate_interaction_settings_to_policy.rb | 2 +- db/post_migrate/20230904134623_fix_kmr_locale_settings.rb | 4 ++-- ...0321160706_migrate_interaction_settings_to_policy_again.rb | 2 +- 5 files changed, 6 insertions(+), 6 deletions(-) diff --git a/db/migrate/20180608213548_reject_following_blocked_users.rb b/db/migrate/20180608213548_reject_following_blocked_users.rb index 4cb6395469..6f22c8d00c 100644 --- a/db/migrate/20180608213548_reject_following_blocked_users.rb +++ b/db/migrate/20180608213548_reject_following_blocked_users.rb @@ -28,7 +28,7 @@ class RejectFollowingBlockedUsers < ActiveRecord::Migration[5.2] next follow.destroy! if blocked_account.local? - reject_follow_json = Oj.dump(ActivityPub::LinkedDataSignature.new(ActiveModelSerializers::SerializableResource.new(follow, serializer: ActivityPub::RejectFollowSerializer, adapter: ActivityPub::Adapter).as_json).sign!(followed_account)) + reject_follow_json = JSON.dump(ActivityPub::LinkedDataSignature.new(ActiveModelSerializers::SerializableResource.new(follow, serializer: ActivityPub::RejectFollowSerializer, adapter: ActivityPub::Adapter).as_json).sign!(followed_account)) ActivityPub::DeliveryWorker.perform_async(reject_follow_json, followed_account, blocked_account.inbox_url) diff --git a/db/migrate/20230215074423_move_user_settings.rb b/db/migrate/20230215074423_move_user_settings.rb index 86231e49e8..6476afdbd3 100644 --- a/db/migrate/20230215074423_move_user_settings.rb +++ b/db/migrate/20230215074423_move_user_settings.rb @@ -80,7 +80,7 @@ class MoveUserSettings < ActiveRecord::Migration[6.1] end end - user.update_column('settings', Oj.dump(user_settings)) + user.update_column('settings', JSON.dump(user_settings)) end end end diff --git a/db/migrate/20240304090449_migrate_interaction_settings_to_policy.rb b/db/migrate/20240304090449_migrate_interaction_settings_to_policy.rb index ea4cfccdf9..1736d1b17d 100644 --- a/db/migrate/20240304090449_migrate_interaction_settings_to_policy.rb +++ b/db/migrate/20240304090449_migrate_interaction_settings_to_policy.rb @@ -21,7 +21,7 @@ class MigrateInteractionSettingsToPolicy < ActiveRecord::Migration[7.1] private def policy_for_user(user) - deserialized_settings = Oj.load(user.attributes_before_type_cast['settings']) + deserialized_settings = JSON.parse(user.attributes_before_type_cast['settings']) return if deserialized_settings.nil? requires_new_policy = false diff --git a/db/post_migrate/20230904134623_fix_kmr_locale_settings.rb b/db/post_migrate/20230904134623_fix_kmr_locale_settings.rb index 10e3f1da99..9df87b492d 100644 --- a/db/post_migrate/20230904134623_fix_kmr_locale_settings.rb +++ b/db/post_migrate/20230904134623_fix_kmr_locale_settings.rb @@ -11,11 +11,11 @@ class FixKmrLocaleSettings < ActiveRecord::Migration[7.0] MigrationUser.reset_column_information MigrationUser.where.not(settings: [nil, '{}']).find_each do |user| - user_settings = Oj.load(user.settings) + user_settings = JSON.parse(user.settings) next unless user_settings['default_language'] == 'kmr' user_settings['default_language'] = 'ku' - user.update!(settings: Oj.dump(user_settings)) + user.update!(settings: JSON.dump(user_settings)) end MigrationUser.where.not(chosen_languages: nil).where('chosen_languages && ?', '{kmr}').find_each do |user| diff --git a/db/post_migrate/20240321160706_migrate_interaction_settings_to_policy_again.rb b/db/post_migrate/20240321160706_migrate_interaction_settings_to_policy_again.rb index c789b63951..92dbd90c79 100644 --- a/db/post_migrate/20240321160706_migrate_interaction_settings_to_policy_again.rb +++ b/db/post_migrate/20240321160706_migrate_interaction_settings_to_policy_again.rb @@ -21,7 +21,7 @@ class MigrateInteractionSettingsToPolicyAgain < ActiveRecord::Migration[7.1] private def policy_for_user(user) - deserialized_settings = Oj.load(user.attributes_before_type_cast['settings']) + deserialized_settings = JSON.parse(user.attributes_before_type_cast['settings']) return if deserialized_settings.nil? return if user.notification_policy.present? From 34d0afb1d22bbb831e97dad0d6d648fd1fd7e2b5 Mon Sep 17 00:00:00 2001 From: Matt Jankowski Date: Wed, 30 Oct 2024 15:41:12 -0400 Subject: [PATCH 4/6] Replace `Oj` with plain `JSON` across lib/ --- lib/mastodon/cli/domains.rb | 8 ++++---- lib/tasks/emojis.rake | 4 ++-- lib/tasks/repo.rake | 4 ++-- 3 files changed, 8 insertions(+), 8 deletions(-) diff --git a/lib/mastodon/cli/domains.rb b/lib/mastodon/cli/domains.rb index c247463af5..20927dae6a 100644 --- a/lib/mastodon/cli/domains.rb +++ b/lib/mastodon/cli/domains.rb @@ -140,13 +140,13 @@ module Mastodon::CLI Request.new(:get, "https://#{domain}/api/v1/instance").perform do |res| next unless res.code == 200 - stats[domain] = Oj.load(res.to_s) + stats[domain] = JSON.parse(res.to_s) end Request.new(:get, "https://#{domain}/api/v1/instance/peers").perform do |res| next unless res.code == 200 - Oj.load(res.to_s).reject { |peer| stats.key?(peer) }.each do |peer| + JSON.parse(res.to_s).reject { |peer| stats.key?(peer) }.each do |peer| pool.post(peer, &work_unit) end end @@ -154,7 +154,7 @@ module Mastodon::CLI Request.new(:get, "https://#{domain}/api/v1/instance/activity").perform do |res| next unless res.code == 200 - stats[domain]['activity'] = Oj.load(res.to_s) + stats[domain]['activity'] = JSON.parse(res.to_s) end rescue failed.increment @@ -214,7 +214,7 @@ module Mastodon::CLI def stats_to_json(stats) stats.compact! - say(Oj.dump(stats)) + say(JSON.dump(stats)) end end end diff --git a/lib/tasks/emojis.rake b/lib/tasks/emojis.rake index fb18f21cf5..3bbda39a60 100644 --- a/lib/tasks/emojis.rake +++ b/lib/tasks/emojis.rake @@ -84,7 +84,7 @@ namespace :emojis do map = map.sort { |a, b| a[0].size <=> b[0].size }.to_h - File.write(dest, Oj.dump(map)) + File.write(dest, JSON.dump(map)) puts "Wrote emojo to destination! (#{dest})" end @@ -94,7 +94,7 @@ namespace :emojis do emojis_light = 'đŸ‘ŊâšžđŸ”â˜ī¸đŸ’¨đŸ•Šī¸đŸ‘€đŸĨđŸ‘ģđŸâ•â”â›¸ī¸đŸŒŠī¸đŸ”ŠđŸ”‡đŸ“ƒđŸŒ§ī¸đŸđŸšđŸ™đŸ“đŸ‘đŸ’€â˜ ī¸đŸŒ¨ī¸đŸ”‰đŸ”ˆđŸ’ŦđŸ’­đŸđŸŗī¸âšĒâŦœâ—Ŋâ—ģī¸â–Ģī¸đŸĒŊđŸĒŋ' emojis_dark = '🎱🐜âšĢ🖤âŦ›â—ŧī¸â—žâ—ŧī¸âœ’ī¸â–Ēī¸đŸ’ŖđŸŽŗđŸ“ˇđŸ“¸â™Ŗī¸đŸ•ļī¸âœ´ī¸đŸ”ŒđŸ’‚â€â™€ī¸đŸ“Ŋī¸đŸŗđŸĻđŸ’‚đŸ”ĒđŸ•ŗī¸đŸ•šī¸đŸ•‹đŸ–Šī¸đŸ–‹ī¸đŸ’‚â€â™‚ī¸đŸŽ¤đŸŽ“đŸŽĨđŸŽŧâ™ ī¸đŸŽŠđŸĻƒđŸ“ŧ📹🎮🐃🏴🐞đŸ•ē📱📲🚲đŸĒŽđŸĻ‍âŦ›' - map = Oj.load(File.read(src)) + map = JSON.parse(File.read(src)) emojis_light.each_grapheme_cluster do |emoji| gen_border map[emoji], 'black' diff --git a/lib/tasks/repo.rake b/lib/tasks/repo.rake index c8f977f651..d834b99055 100644 --- a/lib/tasks/repo.rake +++ b/lib/tasks/repo.rake @@ -22,7 +22,7 @@ namespace :repo do while url.present? response = HTTP.get(url) - contributors = Oj.load(response.body) + contributors = JSON.parse(response.body) contributors.each do |c| file << "* [#{c['login']}](#{c['html_url']})\n" if c['login'] @@ -68,7 +68,7 @@ namespace :repo do end end - pull_request = Oj.load(response.to_s) + pull_request = JSON.parse(response.to_s) pull_request['user']['login'] end From 0fad3b030da846da4793f9138cb11d4a370e15b4 Mon Sep 17 00:00:00 2001 From: Matt Jankowski Date: Wed, 30 Oct 2024 15:46:46 -0400 Subject: [PATCH 5/6] Rename error classes --- app/controllers/activitypub/inboxes_controller.rb | 2 +- app/helpers/jsonld_helper.rb | 2 +- app/lib/admin/metrics/dimension/software_versions_dimension.rb | 2 +- app/lib/link_details_extractor.rb | 2 +- app/lib/translation_service/deepl.rb | 2 +- app/lib/translation_service/libre_translate.rb | 2 +- app/lib/video_metadata_extractor.rb | 2 +- app/lib/webfinger.rb | 2 +- app/services/activitypub/fetch_remote_actor_service.rb | 2 +- app/services/activitypub/process_account_service.rb | 2 +- app/services/activitypub/process_collection_service.rb | 2 +- app/services/fetch_oembed_service.rb | 2 +- app/services/software_update_check_service.rb | 2 +- 13 files changed, 13 insertions(+), 13 deletions(-) diff --git a/app/controllers/activitypub/inboxes_controller.rb b/app/controllers/activitypub/inboxes_controller.rb index 43a640501c..fc153a63ba 100644 --- a/app/controllers/activitypub/inboxes_controller.rb +++ b/app/controllers/activitypub/inboxes_controller.rb @@ -23,7 +23,7 @@ class ActivityPub::InboxesController < ActivityPub::BaseController def unknown_affected_account? json = JSON.parse(body) json.is_a?(Hash) && %w(Delete Update).include?(json['type']) && json['actor'].present? && json['actor'] == value_or_id(json['object']) && !Account.exists?(uri: json['actor']) - rescue Oj::ParseError + rescue JSON::ParserError false end diff --git a/app/helpers/jsonld_helper.rb b/app/helpers/jsonld_helper.rb index 45762abf2a..9c10cc23c7 100644 --- a/app/helpers/jsonld_helper.rb +++ b/app/helpers/jsonld_helper.rb @@ -196,7 +196,7 @@ module JsonLdHelper return if compare_id.present? && json['id'] != compare_id json - rescue Oj::ParseError + rescue JSON::ParserError nil end diff --git a/app/lib/admin/metrics/dimension/software_versions_dimension.rb b/app/lib/admin/metrics/dimension/software_versions_dimension.rb index bd79e25c9e..d4f25a4bf7 100644 --- a/app/lib/admin/metrics/dimension/software_versions_dimension.rb +++ b/app/lib/admin/metrics/dimension/software_versions_dimension.rb @@ -114,7 +114,7 @@ class Admin::Metrics::Dimension::SoftwareVersionsDimension < Admin::Metrics::Dim value: version, human_value: version, } - rescue Terrapin::CommandNotFoundError, Terrapin::ExitStatusError, Oj::ParseError + rescue Terrapin::CommandNotFoundError, Terrapin::ExitStatusError, JSON::ParserError nil end diff --git a/app/lib/link_details_extractor.rb b/app/lib/link_details_extractor.rb index 91729e55df..5fd28d9468 100644 --- a/app/lib/link_details_extractor.rb +++ b/app/lib/link_details_extractor.rb @@ -265,7 +265,7 @@ class LinkDetailsExtractor next unless structured_data.valid? structured_data - rescue Oj::ParseError, EncodingError + rescue JSON::ParserError, EncodingError Rails.logger.debug { "Invalid JSON-LD in #{@original_url}" } next end.first diff --git a/app/lib/translation_service/deepl.rb b/app/lib/translation_service/deepl.rb index 59c255a7ce..98536fe2de 100644 --- a/app/lib/translation_service/deepl.rb +++ b/app/lib/translation_service/deepl.rb @@ -78,7 +78,7 @@ class TranslationService::DeepL < TranslationService provider: 'DeepL.com' ) end - rescue Oj::ParseError + rescue JSON::ParserError raise UnexpectedResponseError end end diff --git a/app/lib/translation_service/libre_translate.rb b/app/lib/translation_service/libre_translate.rb index 8d6472c215..817af7d991 100644 --- a/app/lib/translation_service/libre_translate.rb +++ b/app/lib/translation_service/libre_translate.rb @@ -55,7 +55,7 @@ class TranslationService::LibreTranslate < TranslationService provider: 'LibreTranslate' ) end - rescue Oj::ParseError + rescue JSON::ParserError raise UnexpectedResponseError end end diff --git a/app/lib/video_metadata_extractor.rb b/app/lib/video_metadata_extractor.rb index 66f4c1b772..f94df7cf58 100644 --- a/app/lib/video_metadata_extractor.rb +++ b/app/lib/video_metadata_extractor.rb @@ -9,7 +9,7 @@ class VideoMetadataExtractor @metadata = JSON.parse(ffmpeg_command_output, symbolize_names: true) parse_metadata - rescue Terrapin::ExitStatusError, Oj::ParseError + rescue Terrapin::ExitStatusError, JSON::ParserError @invalid = true rescue Terrapin::CommandNotFoundError raise Paperclip::Errors::CommandNotFoundError, 'Could not run the `ffprobe` command. Please install ffmpeg.' diff --git a/app/lib/webfinger.rb b/app/lib/webfinger.rb index 6e13d2f163..4a978c5921 100644 --- a/app/lib/webfinger.rb +++ b/app/lib/webfinger.rb @@ -57,7 +57,7 @@ class Webfinger def perform Response.new(@uri, body_from_webfinger) - rescue Oj::ParseError + rescue JSON::ParserError raise Webfinger::Error, "Invalid JSON in response for #{@uri}" rescue Addressable::URI::InvalidURIError raise Webfinger::Error, "Invalid URI for #{@uri}" diff --git a/app/services/activitypub/fetch_remote_actor_service.rb b/app/services/activitypub/fetch_remote_actor_service.rb index 560cf424e1..1fb3f45ce5 100644 --- a/app/services/activitypub/fetch_remote_actor_service.rb +++ b/app/services/activitypub/fetch_remote_actor_service.rb @@ -19,7 +19,7 @@ class ActivityPub::FetchRemoteActorService < BaseService else body_to_json(prefetched_body, compare_id: uri) end - rescue Oj::ParseError + rescue JSON::ParserError raise Error, "Error parsing JSON-LD document #{uri}" end diff --git a/app/services/activitypub/process_account_service.rb b/app/services/activitypub/process_account_service.rb index df6f23c021..97c7f11a3a 100644 --- a/app/services/activitypub/process_account_service.rb +++ b/app/services/activitypub/process_account_service.rb @@ -61,7 +61,7 @@ class ActivityPub::ProcessAccountService < BaseService end @account - rescue Oj::ParseError + rescue JSON::ParserError nil end diff --git a/app/services/activitypub/process_collection_service.rb b/app/services/activitypub/process_collection_service.rb index d9ba5d5822..2b5043dc66 100644 --- a/app/services/activitypub/process_collection_service.rb +++ b/app/services/activitypub/process_collection_service.rb @@ -38,7 +38,7 @@ class ActivityPub::ProcessCollectionService < BaseService else process_items [@json] end - rescue Oj::ParseError + rescue JSON::ParserError nil end diff --git a/app/services/fetch_oembed_service.rb b/app/services/fetch_oembed_service.rb index c2887e3017..cc71a5f92b 100644 --- a/app/services/fetch_oembed_service.rb +++ b/app/services/fetch_oembed_service.rb @@ -86,7 +86,7 @@ class FetchOEmbedService end validate(parse_for_format(body)) if body.present? - rescue Oj::ParseError, Ox::ParseError + rescue JSON::ParserError, Ox::ParseError nil end diff --git a/app/services/software_update_check_service.rb b/app/services/software_update_check_service.rb index e3bc112964..aa2eadd94c 100644 --- a/app/services/software_update_check_service.rb +++ b/app/services/software_update_check_service.rb @@ -22,7 +22,7 @@ class SoftwareUpdateCheckService < BaseService Request.new(:get, "#{api_url}?version=#{version}").add_headers('Accept' => 'application/json', 'User-Agent' => 'Mastodon update checker').perform do |res| return JSON.parse(res.body_with_limit) if res.code == 200 end - rescue *Mastodon::HTTP_CONNECTION_ERRORS, Oj::ParseError + rescue *Mastodon::HTTP_CONNECTION_ERRORS, JSON::ParserError nil end From e2a8f8b1f9419a103ed7204d2d47a271656b0f5f Mon Sep 17 00:00:00 2001 From: Matt Jankowski Date: Wed, 30 Oct 2024 15:42:55 -0400 Subject: [PATCH 6/6] Remove `oj` gem --- Gemfile | 1 - Gemfile.lock | 5 ----- config/initializers/oj.rb | 3 --- 3 files changed, 9 deletions(-) delete mode 100644 config/initializers/oj.rb diff --git a/Gemfile b/Gemfile index ad174cfdc4..1c77ea6ea0 100644 --- a/Gemfile +++ b/Gemfile @@ -65,7 +65,6 @@ gem 'mario-redis-lock', '~> 1.2', require: 'redis_lock' gem 'mime-types', '~> 3.6.0', require: 'mime/types/columnar' gem 'mutex_m' gem 'nokogiri', '~> 1.15' -gem 'oj', '~> 3.14' gem 'ox', '~> 2.14' gem 'parslet' gem 'premailer-rails' diff --git a/Gemfile.lock b/Gemfile.lock index f49de6bf3b..39fe1a5340 100644 --- a/Gemfile.lock +++ b/Gemfile.lock @@ -429,9 +429,6 @@ GEM nokogiri (1.18.1) mini_portile2 (~> 2.8.2) racc (~> 1.4) - oj (3.16.9) - bigdecimal (>= 3.0) - ostruct (>= 0.2) omniauth (2.1.2) hashie (>= 3.4.6) rack (>= 2.2.3) @@ -554,7 +551,6 @@ GEM opentelemetry-semantic_conventions (1.10.1) opentelemetry-api (~> 1.0) orm_adapter (0.5.0) - ostruct (0.6.1) ox (2.14.19) bigdecimal (>= 3.0) parallel (1.26.3) @@ -951,7 +947,6 @@ DEPENDENCIES net-http (~> 0.6.0) net-ldap (~> 0.18) nokogiri (~> 1.15) - oj (~> 3.14) omniauth (~> 2.0) omniauth-cas (~> 3.0.0.beta.1) omniauth-rails_csrf_protection (~> 1.0) diff --git a/config/initializers/oj.rb b/config/initializers/oj.rb deleted file mode 100644 index 9b2d908637..0000000000 --- a/config/initializers/oj.rb +++ /dev/null @@ -1,3 +0,0 @@ -# frozen_string_literal: true - -Oj.default_options = { mode: :compat, time_format: :ruby, use_to_json: true }