From 31f396b57dea684685d0affc3727a75eed2f38c9 Mon Sep 17 00:00:00 2001 From: Eugen Rochko Date: Fri, 18 Jan 2019 15:56:21 +0100 Subject: [PATCH] Add support for non-public reblogs from ActivityPub (#9841) Fix #9838 --- app/lib/activitypub/activity/announce.rb | 14 +++++++++++++- app/models/status.rb | 4 ++-- 2 files changed, 15 insertions(+), 3 deletions(-) diff --git a/app/lib/activitypub/activity/announce.rb b/app/lib/activitypub/activity/announce.rb index 1147a4481..34d1b7cbd 100644 --- a/app/lib/activitypub/activity/announce.rb +++ b/app/lib/activitypub/activity/announce.rb @@ -17,7 +17,7 @@ class ActivityPub::Activity::Announce < ActivityPub::Activity uri: @json['id'], created_at: @json['published'], override_timestamps: @options[:override_timestamps], - visibility: original_status.visibility + visibility: visibility_from_audience ) distribute(status) @@ -26,6 +26,18 @@ class ActivityPub::Activity::Announce < ActivityPub::Activity private + def visibility_from_audience + if equals_or_includes?(@json['to'], ActivityPub::TagManager::COLLECTIONS[:public]) + :public + elsif equals_or_includes?(@json['cc'], ActivityPub::TagManager::COLLECTIONS[:public]) + :unlisted + elsif equals_or_includes?(@json['to'], @account.followers_url) + :private + else + :direct + end + end + def announceable?(status) status.account_id == @account.id || status.public_visibility? || status.unlisted_visibility? end diff --git a/app/models/status.rb b/app/models/status.rb index 0705ba4c1..035423b40 100644 --- a/app/models/status.rb +++ b/app/models/status.rb @@ -478,7 +478,7 @@ class Status < ApplicationRecord return if direct_visibility? account&.increment_count!(:statuses_count) - reblog&.increment_count!(:reblogs_count) if reblog? + reblog&.increment_count!(:reblogs_count) if reblog? && (public_visibility? || unlisted_visibility?) thread&.increment_count!(:replies_count) if in_reply_to_id.present? && (public_visibility? || unlisted_visibility?) end @@ -486,7 +486,7 @@ class Status < ApplicationRecord return if direct_visibility? || marked_for_mass_destruction? account&.decrement_count!(:statuses_count) - reblog&.decrement_count!(:reblogs_count) if reblog? + reblog&.decrement_count!(:reblogs_count) if reblog? && (public_visibility? || unlisted_visibility?) thread&.decrement_count!(:replies_count) if in_reply_to_id.present? && (public_visibility? || unlisted_visibility?) end