From a03d5066265c9555ea2e42cf4bb06edc7439e50c Mon Sep 17 00:00:00 2001 From: ThibG Date: Tue, 30 Oct 2018 15:02:24 +0100 Subject: Fix Pleroma mentions being fetched as preview cards (#9158) --- app/services/fetch_link_card_service.rb | 8 +++----- 1 file changed, 3 insertions(+), 5 deletions(-) (limited to 'app/services') diff --git a/app/services/fetch_link_card_service.rb b/app/services/fetch_link_card_service.rb index 462e5ee13..3e77579bb 100644 --- a/app/services/fetch_link_card_service.rb +++ b/app/services/fetch_link_card_service.rb @@ -17,8 +17,7 @@ class FetchLinkCardService < BaseService return if @url.nil? || @status.preview_cards.any? - @mentions = status.mentions - @url = @url.to_s + @url = @url.to_s RedisLock.acquire(lock_options) do |lock| if lock.acquired? @@ -84,9 +83,8 @@ class FetchLinkCardService < BaseService end def mention_link?(a) - return false if @mentions.nil? - @mentions.any? do |mention| - a['href'] == TagManager.instance.url_for(mention.target) + @status.mentions.any? do |mention| + a['href'] == TagManager.instance.url_for(mention.account) end end -- cgit From 47b8d195e6ea5bc5f3cd4fe3a5be0b25ec322f10 Mon Sep 17 00:00:00 2001 From: Eugen Rochko Date: Tue, 30 Oct 2018 15:02:55 +0100 Subject: Always let through notifications from staff (#9152) * Always let through notifications from staff Follow-up to #8993 * Let messages from staff through, but no other notifications --- app/services/notify_service.rb | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) (limited to 'app/services') diff --git a/app/services/notify_service.rb b/app/services/notify_service.rb index a8b7bb30b..b80ceef03 100644 --- a/app/services/notify_service.rb +++ b/app/services/notify_service.rb @@ -51,8 +51,12 @@ class NotifyService < BaseService @recipient.user.settings.interactions['must_be_following'] && !following_sender? end + def message? + @notification.type == :mention + end + def direct_message? - @notification.type == :mention && @notification.target_status.direct_visibility? + message? && @notification.target_status.direct_visibility? end def response_to_recipient? @@ -66,7 +70,6 @@ class NotifyService < BaseService def optional_non_following_and_direct? direct_message? && @recipient.user.settings.interactions['must_be_following_dm'] && - !from_staff? && !following_sender? && !response_to_recipient? end @@ -86,6 +89,9 @@ class NotifyService < BaseService def blocked? blocked = @recipient.suspended? # Skip if the recipient account is suspended anyway blocked ||= from_self? # Skip for interactions with self + + return blocked if message? && from_staff? + blocked ||= domain_blocking? # Skip for domain blocked accounts blocked ||= @recipient.blocking?(@notification.from_account) # Skip for blocked accounts blocked ||= @recipient.muting_notifications?(@notification.from_account) -- cgit From be202f9377fecfc801befac0be6d11d9f0039c5d Mon Sep 17 00:00:00 2001 From: Eugen Rochko Date: Tue, 30 Oct 2018 15:03:55 +0100 Subject: Accept the same payload in multiple inboxes and deliver (#9150) --- app/lib/activitypub/activity/create.rb | 20 +++++++++++++++++++- app/services/fan_out_on_write_service.rb | 6 ++---- 2 files changed, 21 insertions(+), 5 deletions(-) (limited to 'app/services') diff --git a/app/lib/activitypub/activity/create.rb b/app/lib/activitypub/activity/create.rb index baa05e14c..45079e2b3 100644 --- a/app/lib/activitypub/activity/create.rb +++ b/app/lib/activitypub/activity/create.rb @@ -10,7 +10,12 @@ class ActivityPub::Activity::Create < ActivityPub::Activity RedisLock.acquire(lock_options) do |lock| if lock.acquired? @status = find_existing_status - process_status if @status.nil? + + if @status.nil? + process_status + elsif @options[:delivered_to_account_id].present? + postprocess_audience_and_deliver + end else raise Mastodon::RaceConditionError end @@ -99,6 +104,19 @@ class ActivityPub::Activity::Create < ActivityPub::Activity @params[:visibility] = :limited end + def postprocess_audience_and_deliver + return if @status.mentions.find_by(account_id: @options[:delivered_to_account_id]) + + delivered_to_account = Account.find(@options[:delivered_to_account_id]) + + @status.mentions.create(account: delivered_to_account, silent: true) + @status.update(visibility: :limited) if @status.direct_visibility? + + return unless delivered_to_account.following?(@account) + + FeedInsertWorker.perform_async(@status.id, delivered_to_account.id, :home) + end + def attach_tags(status) @tags.each do |tag| status.tags << tag diff --git a/app/services/fan_out_on_write_service.rb b/app/services/fan_out_on_write_service.rb index 7f2a91775..f3e9c855d 100644 --- a/app/services/fan_out_on_write_service.rb +++ b/app/services/fan_out_on_write_service.rb @@ -58,10 +58,8 @@ class FanOutOnWriteService < BaseService def deliver_to_mentioned_followers(status) Rails.logger.debug "Delivering status #{status.id} to limited followers" - status.mentions.includes(:account).each do |mention| - mentioned_account = mention.account - next if !mentioned_account.local? || !mentioned_account.following?(status.account) || FeedManager.instance.filter?(:home, status, mention.account_id) - FeedManager.instance.push_to_home(mentioned_account, status) + FeedInsertWorker.push_bulk(status.mentions.includes(:account).map(&:account).select { |mentioned_account| mentioned_account.local? && mentioned_account.following?(status.account) }) do |follower| + [status.id, follower.id, :home] end end -- cgit From c36a4a16178441968715e13c77859b1eb813c2af Mon Sep 17 00:00:00 2001 From: valerauko Date: Tue, 30 Oct 2018 23:07:57 +0900 Subject: Fix FetchAtomService content type handling (#9132) * Add profile to json+ld in Accept It's required by the ActivityPub spec * Use headers['Content-type'] instead of mime_type mime_type strips the profile from the content type, but it's still available raw in the headers hash * Add test for ld+json with profile --- app/services/fetch_atom_service.rb | 10 ++++++---- spec/services/fetch_atom_service_spec.rb | 9 ++++++++- 2 files changed, 14 insertions(+), 5 deletions(-) (limited to 'app/services') diff --git a/app/services/fetch_atom_service.rb b/app/services/fetch_atom_service.rb index 550e75f33..b6c6cdd1c 100644 --- a/app/services/fetch_atom_service.rb +++ b/app/services/fetch_atom_service.rb @@ -29,7 +29,7 @@ class FetchAtomService < BaseService def perform_request(&block) accept = 'text/html' - accept = 'application/activity+json, application/ld+json, application/atom+xml, ' + accept unless @unsupported_activity + accept = 'application/activity+json, application/ld+json; profile="https://www.w3.org/ns/activitystreams", application/atom+xml, ' + accept unless @unsupported_activity Request.new(:get, @url).add_headers('Accept' => accept).perform(&block) end @@ -37,9 +37,11 @@ class FetchAtomService < BaseService def process_response(response, terminal = false) return nil if response.code != 200 - if response.mime_type == 'application/atom+xml' + response_type = response.headers['Content-type'] + + if response_type == 'application/atom+xml' [@url, { prefetched_body: response.body_with_limit }, :ostatus] - elsif ['application/activity+json', 'application/ld+json; profile="https://www.w3.org/ns/activitystreams"'].include?(response.mime_type) + elsif ['application/activity+json', 'application/ld+json; profile="https://www.w3.org/ns/activitystreams"'].include?(response_type) body = response.body_with_limit json = body_to_json(body) if supported_context?(json) && equals_or_includes_any?(json['type'], ActivityPub::FetchRemoteAccountService::SUPPORTED_TYPES) && json['inbox'].present? @@ -55,7 +57,7 @@ class FetchAtomService < BaseService if link_header&.find_link(%w(rel alternate)) process_link_headers(link_header) - elsif response.mime_type == 'text/html' + elsif response_type == 'text/html' process_html(response) end end diff --git a/spec/services/fetch_atom_service_spec.rb b/spec/services/fetch_atom_service_spec.rb index 30e5b0935..0cdcda892 100644 --- a/spec/services/fetch_atom_service_spec.rb +++ b/spec/services/fetch_atom_service_spec.rb @@ -60,13 +60,20 @@ RSpec.describe FetchAtomService, type: :service do it { is_expected.to eq [url, { :prefetched_body => "" }, :ostatus] } end - context 'content_type is json' do + context 'content_type is activity+json' do let(:content_type) { 'application/activity+json' } let(:body) { json } it { is_expected.to eq [1, { prefetched_body: body, id: true }, :activitypub] } end + context 'content_type is ld+json with profile' do + let(:content_type) { 'application/ld+json; profile="https://www.w3.org/ns/activitystreams"' } + let(:body) { json } + + it { is_expected.to eq [1, { prefetched_body: body, id: true }, :activitypub] } + end + before do WebMock.stub_request(:get, url).to_return(status: 200, body: body, headers: headers) WebMock.stub_request(:get, 'http://example.com/foo').to_return(status: 200, body: json, headers: { 'Content-Type' => 'application/activity+json' }) -- cgit