From a4caa7eb6258ff7f8eea8e6791b86b1c7f4d172e Mon Sep 17 00:00:00 2001 From: Eugen Rochko Date: Fri, 8 Sep 2017 12:00:17 +0200 Subject: Fetch statuses/following/followers numbers from ActivityPub collections (#4840) --- .../activitypub/process_account_service.rb | 37 +++++++++++++++++++--- 1 file changed, 32 insertions(+), 5 deletions(-) (limited to 'app/services') diff --git a/app/services/activitypub/process_account_service.rb b/app/services/activitypub/process_account_service.rb index 29eb1c2e1..c63577fe5 100644 --- a/app/services/activitypub/process_account_service.rb +++ b/app/services/activitypub/process_account_service.rb @@ -8,11 +8,12 @@ class ActivityPub::ProcessAccountService < BaseService def call(username, domain, json) return if json['inbox'].blank? - @json = json - @uri = @json['id'] - @username = username - @domain = domain - @account = Account.find_by(uri: @uri) + @json = json + @uri = @json['id'] + @username = username + @domain = domain + @account = Account.find_by(uri: @uri) + @collections = {} create_account if @account.nil? upgrade_account if @account.ostatus? @@ -51,6 +52,9 @@ class ActivityPub::ProcessAccountService < BaseService @account.header_remote_url = image_url('image') @account.public_key = public_key || '' @account.locked = @json['manuallyApprovesFollowers'] || false + @account.statuses_count = outbox_total_items if outbox_total_items.present? + @account.following_count = following_total_items if following_total_items.present? + @account.followers_count = followers_total_items if followers_total_items.present? @account.save! end @@ -88,6 +92,29 @@ class ActivityPub::ProcessAccountService < BaseService value['href'] end + def outbox_total_items + collection_total_items('outbox') + end + + def following_total_items + collection_total_items('following') + end + + def followers_total_items + collection_total_items('followers') + end + + def collection_total_items(type) + return if @json[type].blank? + return @collections[type] if @collections.key?(type) + + collection = fetch_resource(@json[type]) + + @collections[type] = collection.is_a?(Hash) && collection['totalItems'].present? && collection['totalItems'].is_a?(Numeric) ? collection['totalItems'] : nil + rescue HTTP::Error, OpenSSL::SSL::SSLError + @collections[type] = nil + end + def auto_suspend? domain_block && domain_block.suspend? end -- cgit From 7ca173be47c8aa5e8bd2b33aac642193ebb673a0 Mon Sep 17 00:00:00 2001 From: Eugen Rochko Date: Sat, 9 Sep 2017 02:02:29 +0200 Subject: Fix #4850 - When visibility missing from API call to toot, fallback to user preference (#4861) --- app/services/post_status_service.rb | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) (limited to 'app/services') diff --git a/app/services/post_status_service.rb b/app/services/post_status_service.rb index 568f5a9e7..97c55c4b2 100644 --- a/app/services/post_status_service.rb +++ b/app/services/post_status_service.rb @@ -27,9 +27,10 @@ class PostStatusService < BaseService thread: in_reply_to, sensitive: options[:sensitive], spoiler_text: options[:spoiler_text] || '', - visibility: options[:visibility], + visibility: options[:visibility] || account.user&.setting_default_privacy, language: detect_language_for(text, account), application: options[:application]) + attach_media(status, media) end -- cgit From 4b460bc57188c5dab31a921daed3c0012df28761 Mon Sep 17 00:00:00 2001 From: Eugen Rochko Date: Sat, 9 Sep 2017 02:02:44 +0200 Subject: Fix #4852 - Check if already requested from FollowService (#4855) --- app/services/follow_service.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'app/services') diff --git a/app/services/follow_service.rb b/app/services/follow_service.rb index a92eb6b88..941556b60 100644 --- a/app/services/follow_service.rb +++ b/app/services/follow_service.rb @@ -12,7 +12,7 @@ class FollowService < BaseService raise ActiveRecord::RecordNotFound if target_account.nil? || target_account.id == source_account.id || target_account.suspended? raise Mastodon::NotPermittedError if target_account.blocking?(source_account) || source_account.blocking?(target_account) - return if source_account.following?(target_account) + return if source_account.following?(target_account) || source_account.requested?(target_account) if target_account.locked? || target_account.activitypub? request_follow(source_account, target_account) -- cgit From 9e15eeec63b36f147700303961ad5ef207b81986 Mon Sep 17 00:00:00 2001 From: Eugen Rochko Date: Sat, 9 Sep 2017 13:41:45 +0200 Subject: Add missing reject_media check before avatar download via ActivityPub (#4862) --- app/services/activitypub/process_account_service.rb | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) (limited to 'app/services') diff --git a/app/services/activitypub/process_account_service.rb b/app/services/activitypub/process_account_service.rb index c63577fe5..b54e447ad 100644 --- a/app/services/activitypub/process_account_service.rb +++ b/app/services/activitypub/process_account_service.rb @@ -48,14 +48,14 @@ class ActivityPub::ProcessAccountService < BaseService @account.url = url || @uri @account.display_name = @json['name'] || '' @account.note = @json['summary'] || '' - @account.avatar_remote_url = image_url('icon') - @account.header_remote_url = image_url('image') + @account.avatar_remote_url = image_url('icon') unless skip_download? + @account.header_remote_url = image_url('image') unless skip_download? @account.public_key = public_key || '' @account.locked = @json['manuallyApprovesFollowers'] || false @account.statuses_count = outbox_total_items if outbox_total_items.present? @account.following_count = following_total_items if following_total_items.present? @account.followers_count = followers_total_items if followers_total_items.present? - @account.save! + @account.save_with_optional_media! end def upgrade_account @@ -115,6 +115,10 @@ class ActivityPub::ProcessAccountService < BaseService @collections[type] = nil end + def skip_download? + @account.suspended? || domain_block&.reject_media? + end + def auto_suspend? domain_block && domain_block.suspend? end -- cgit From 90712d42933efd9978e4bbae82f81a4650aa4d84 Mon Sep 17 00:00:00 2001 From: Eugen Rochko Date: Sat, 9 Sep 2017 17:36:27 +0200 Subject: Fix errors preventing UnsubscribeService from working (#4866) --- app/services/unsubscribe_service.rb | 13 ++++++++----- spec/services/unsubscribe_service_spec.rb | 2 +- 2 files changed, 9 insertions(+), 6 deletions(-) (limited to 'app/services') diff --git a/app/services/unsubscribe_service.rb b/app/services/unsubscribe_service.rb index 865f783bc..b99046712 100644 --- a/app/services/unsubscribe_service.rb +++ b/app/services/unsubscribe_service.rb @@ -4,16 +4,19 @@ class UnsubscribeService < BaseService def call(account) return if account.hub_url.blank? - @account = account - @response = build_request.perform + @account = account - Rails.logger.debug "PuSH unsubscribe for #{@account.acct} failed: #{@response.status}" unless @response.status.success? + begin + @response = build_request.perform + + Rails.logger.debug "PuSH unsubscribe for #{@account.acct} failed: #{@response.status}" unless @response.status.success? + rescue HTTP::Error, OpenSSL::SSL::SSLError => e + Rails.logger.debug "PuSH unsubscribe for #{@account.acct} failed: #{e}" + end @account.secret = '' @account.subscription_expires_at = nil @account.save! - rescue HTTP::Error, OpenSSL::SSL::SSLError - Rails.logger.debug "PuSH subscription request for #{@account.acct} could not be made due to HTTP or SSL error" end private diff --git a/spec/services/unsubscribe_service_spec.rb b/spec/services/unsubscribe_service_spec.rb index c81772037..2a02f4c75 100644 --- a/spec/services/unsubscribe_service_spec.rb +++ b/spec/services/unsubscribe_service_spec.rb @@ -26,7 +26,7 @@ RSpec.describe UnsubscribeService do stub_request(:post, 'http://hub.example.com/').to_raise(HTTP::Error) subject.call(account) - expect(logger).to have_received(:debug).with(/PuSH subscription request for bob@example.com could not be made due to HTTP or SSL error/) + expect(logger).to have_received(:debug).with(/unsubscribe for bob@example.com failed/) end def stub_logger -- cgit