diff options
author | beatrix <beatrix.bitrot@gmail.com> | 2017-09-10 13:34:14 -0400 |
---|---|---|
committer | GitHub <noreply@github.com> | 2017-09-10 13:34:14 -0400 |
commit | c9df53044a333276853f7dc7ef2aed6d48df087f (patch) | |
tree | 011ea44fc94bcff6f8ec4e23c3edf887359243d2 /app/services | |
parent | 3dff74eecf5387b92b862893248710d2efb90eec (diff) | |
parent | 67ad4533732f2e5cfc8c7f7ad3abaf7a5eb2647b (diff) |
Merge pull request #142 from glitch-soc/sync/upstream-1.6.0rc4
Merge with 1.6.0rc4 STRAP IN BUCKAWOO HERE WE GO AGAIN
Diffstat (limited to 'app/services')
-rw-r--r-- | app/services/activitypub/process_account_service.rb | 47 | ||||
-rw-r--r-- | app/services/follow_service.rb | 2 | ||||
-rw-r--r-- | app/services/post_status_service.rb | 3 | ||||
-rw-r--r-- | app/services/unsubscribe_service.rb | 13 |
4 files changed, 50 insertions, 15 deletions
diff --git a/app/services/activitypub/process_account_service.rb b/app/services/activitypub/process_account_service.rb index 29eb1c2e1..b54e447ad 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? @@ -47,11 +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.save! + @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_with_optional_media! end def upgrade_account @@ -88,6 +92,33 @@ 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 skip_download? + @account.suspended? || domain_block&.reject_media? + end + def auto_suspend? domain_block && domain_block.suspend? end 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) diff --git a/app/services/post_status_service.rb b/app/services/post_status_service.rb index 56011a005..e5b0fe438 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 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 |