Merge tag 'v2.7.0rc1' into instance_only_statuses
This commit is contained in:
@ -50,6 +50,8 @@ class ActivityPub::Activity
|
||||
ActivityPub::Activity::Add
|
||||
when 'Remove'
|
||||
ActivityPub::Activity::Remove
|
||||
when 'Move'
|
||||
ActivityPub::Activity::Move
|
||||
end
|
||||
end
|
||||
end
|
||||
|
@ -4,9 +4,10 @@ class ActivityPub::Activity::Block < ActivityPub::Activity
|
||||
def perform
|
||||
target_account = account_from_uri(object_uri)
|
||||
|
||||
return if target_account.nil? || !target_account.local? || delete_arrived_first?(@json['id']) || @account.blocking?(target_account)
|
||||
return if target_account.nil? || !target_account.local? || @account.blocking?(target_account)
|
||||
|
||||
UnfollowService.new.call(target_account, @account) if target_account.following?(@account)
|
||||
@account.block!(target_account, uri: @json['id'])
|
||||
|
||||
@account.block!(target_account, uri: @json['id']) unless delete_arrived_first?(@json['id'])
|
||||
end
|
||||
end
|
||||
|
@ -210,7 +210,7 @@ class ActivityPub::Activity::Create < ActivityPub::Activity
|
||||
end
|
||||
|
||||
def resolve_thread(status)
|
||||
return unless status.reply? && status.thread.nil?
|
||||
return unless status.reply? && status.thread.nil? && Request.valid_url?(in_reply_to_uri)
|
||||
ThreadResolveWorker.perform_async(status.id, in_reply_to_uri)
|
||||
end
|
||||
|
||||
|
@ -8,8 +8,6 @@ class ActivityPub::Activity::Flag < ActivityPub::Activity
|
||||
target_statuses_by_account = object_uris.map { |uri| status_from_uri(uri) }.compact.select(&:local?).group_by(&:account_id)
|
||||
|
||||
target_accounts.each do |target_account|
|
||||
next if Report.where(account: @account, target_account: target_account).exists?
|
||||
|
||||
target_statuses = target_statuses_by_account[target_account.id]
|
||||
|
||||
ReportService.new.call(
|
||||
|
@ -6,7 +6,7 @@ class ActivityPub::Activity::Follow < ActivityPub::Activity
|
||||
|
||||
return if target_account.nil? || !target_account.local? || delete_arrived_first?(@json['id']) || @account.requested?(target_account)
|
||||
|
||||
if target_account.blocking?(@account) || target_account.domain_blocking?(@account.domain)
|
||||
if target_account.blocking?(@account) || target_account.domain_blocking?(@account.domain) || target_account.moved?
|
||||
reject_follow_request!(target_account)
|
||||
return
|
||||
end
|
||||
@ -28,7 +28,7 @@ class ActivityPub::Activity::Follow < ActivityPub::Activity
|
||||
end
|
||||
|
||||
def reject_follow_request!(target_account)
|
||||
json = Oj.dump(ActivityPub::LinkedDataSignature.new(ActiveModelSerializers::SerializableResource.new(FollowRequest.new(account: @account, target_account: target_account, uri: @json['id']), serializer: ActivityPub::RejectFollowSerializer, adapter: ActivityPub::Adapter).as_json).sign!(target_account))
|
||||
json = ActiveModelSerializers::SerializableResource.new(FollowRequest.new(account: @account, target_account: target_account, uri: @json['id']), serializer: ActivityPub::RejectFollowSerializer, adapter: ActivityPub::Adapter).to_json
|
||||
ActivityPub::DeliveryWorker.perform_async(json, target_account.id, @account.inbox_url)
|
||||
end
|
||||
end
|
||||
|
43
app/lib/activitypub/activity/move.rb
Normal file
43
app/lib/activitypub/activity/move.rb
Normal file
@ -0,0 +1,43 @@
|
||||
# frozen_string_literal: true
|
||||
|
||||
class ActivityPub::Activity::Move < ActivityPub::Activity
|
||||
PROCESSING_COOLDOWN = 7.days.seconds
|
||||
|
||||
def perform
|
||||
return if origin_account.uri != object_uri || processed?
|
||||
|
||||
mark_as_processing!
|
||||
|
||||
target_account = ActivityPub::FetchRemoteAccountService.new.call(target_uri)
|
||||
|
||||
return if target_account.nil? || !target_account.also_known_as.include?(origin_account.uri)
|
||||
|
||||
# In case for some reason we didn't have a redirect for the profile already, set it
|
||||
origin_account.update(moved_to_account: target_account) if origin_account.moved_to_account_id.nil?
|
||||
|
||||
# Initiate a re-follow for each follower
|
||||
origin_account.followers.local.select(:id).find_in_batches do |follower_accounts|
|
||||
UnfollowFollowWorker.push_bulk(follower_accounts.map(&:id)) do |follower_account_id|
|
||||
[follower_account_id, origin_account.id, target_account.id]
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
private
|
||||
|
||||
def origin_account
|
||||
@account
|
||||
end
|
||||
|
||||
def target_uri
|
||||
value_or_id(@json['target'])
|
||||
end
|
||||
|
||||
def processed?
|
||||
redis.exists("move_in_progress:#{@account.id}")
|
||||
end
|
||||
|
||||
def mark_as_processing!
|
||||
redis.setex("move_in_progress:#{@account.id}", PROCESSING_COOLDOWN, true)
|
||||
end
|
||||
end
|
@ -10,6 +10,7 @@ class ActivityPub::Adapter < ActiveModelSerializers::Adapter::Base
|
||||
'manuallyApprovesFollowers' => 'as:manuallyApprovesFollowers',
|
||||
'sensitive' => 'as:sensitive',
|
||||
'movedTo' => { '@id' => 'as:movedTo', '@type' => '@id' },
|
||||
'alsoKnownAs' => { '@id' => 'as:alsoKnownAs', '@type' => '@id' },
|
||||
'Hashtag' => 'as:Hashtag',
|
||||
'ostatus' => 'http://ostatus.org#',
|
||||
'atomUri' => 'ostatus:atomUri',
|
||||
|
@ -27,7 +27,7 @@ class FeedManager
|
||||
end
|
||||
|
||||
def push_to_home(account, status)
|
||||
return false unless add_to_feed(:home, account.id, status)
|
||||
return false unless add_to_feed(:home, account.id, status, account.user&.aggregates_reblogs?)
|
||||
trim(:home, account.id)
|
||||
PushUpdateWorker.perform_async(account.id, status.id, "timeline:#{account.id}") if push_update_required?("timeline:#{account.id}")
|
||||
true
|
||||
@ -45,7 +45,7 @@ class FeedManager
|
||||
should_filter &&= !ListAccount.where(list_id: list.id, account_id: status.in_reply_to_account_id).exists?
|
||||
return false if should_filter
|
||||
end
|
||||
return false unless add_to_feed(:list, list.id, status)
|
||||
return false unless add_to_feed(:list, list.id, status, list.account.user&.aggregates_reblogs?)
|
||||
trim(:list, list.id)
|
||||
PushUpdateWorker.perform_async(list.account_id, status.id, "timeline:list:#{list.id}") if push_update_required?("timeline:list:#{list.id}")
|
||||
true
|
||||
@ -93,7 +93,7 @@ class FeedManager
|
||||
|
||||
query.each do |status|
|
||||
next if status.direct_visibility? || status.limited_visibility? || filter?(:home, status, into_account)
|
||||
add_to_feed(:home, into_account.id, status)
|
||||
add_to_feed(:home, into_account.id, status, into_account.user&.aggregates_reblogs?)
|
||||
end
|
||||
|
||||
trim(:home, into_account.id)
|
||||
@ -131,7 +131,7 @@ class FeedManager
|
||||
|
||||
statuses.each do |status|
|
||||
next if filter_from_home?(status, account)
|
||||
added += 1 if add_to_feed(:home, account.id, status)
|
||||
added += 1 if add_to_feed(:home, account.id, status, account.user&.aggregates_reblogs?)
|
||||
end
|
||||
|
||||
break unless added.zero?
|
||||
@ -230,11 +230,11 @@ class FeedManager
|
||||
# added, and false if it was not added to the feed. Note that this is
|
||||
# an internal helper: callers must call trim or push updates if
|
||||
# either action is appropriate.
|
||||
def add_to_feed(timeline_type, account_id, status)
|
||||
def add_to_feed(timeline_type, account_id, status, aggregate_reblogs = true)
|
||||
timeline_key = key(timeline_type, account_id)
|
||||
reblog_key = key(timeline_type, account_id, 'reblogs')
|
||||
|
||||
if status.reblog?
|
||||
if status.reblog? && (aggregate_reblogs.nil? || aggregate_reblogs)
|
||||
# If the original status or a reblog of it is within
|
||||
# REBLOG_FALLOFF statuses from the top, do not re-insert it into
|
||||
# the feed
|
||||
|
@ -57,7 +57,7 @@ class OStatus::Activity::Creation < OStatus::Activity::Base
|
||||
save_emojis(status)
|
||||
end
|
||||
|
||||
if thread? && status.thread.nil?
|
||||
if thread? && status.thread.nil? && Request.valid_url?(thread.second)
|
||||
Rails.logger.debug "Trying to attach #{status.id} (#{id}) to #{thread.first}"
|
||||
ThreadResolveWorker.perform_async(status.id, thread.second)
|
||||
end
|
||||
|
@ -66,6 +66,18 @@ class Request
|
||||
(@account ? @headers.merge('Signature' => signature) : @headers).without(REQUEST_TARGET)
|
||||
end
|
||||
|
||||
class << self
|
||||
def valid_url?(url)
|
||||
begin
|
||||
parsed_url = Addressable::URI.parse(url)
|
||||
rescue Addressable::URI::InvalidURIError
|
||||
return false
|
||||
end
|
||||
|
||||
%w(http https).include?(parsed_url.scheme) && parsed_url.host.present?
|
||||
end
|
||||
end
|
||||
|
||||
private
|
||||
|
||||
def set_common_headers!
|
||||
|
@ -32,6 +32,7 @@ class UserSettingsDecorator
|
||||
user.settings['noindex'] = noindex_preference if change?('setting_noindex')
|
||||
user.settings['theme'] = theme_preference if change?('setting_theme')
|
||||
user.settings['hide_network'] = hide_network_preference if change?('setting_hide_network')
|
||||
user.settings['aggregate_reblogs'] = aggregate_reblogs_preference if change?('setting_aggregate_reblogs')
|
||||
end
|
||||
|
||||
def merged_notification_emails
|
||||
@ -102,6 +103,10 @@ class UserSettingsDecorator
|
||||
settings['setting_default_language']
|
||||
end
|
||||
|
||||
def aggregate_reblogs_preference
|
||||
boolean_cast_setting 'setting_aggregate_reblogs'
|
||||
end
|
||||
|
||||
def boolean_cast_setting(key)
|
||||
ActiveModel::Type::Boolean.new.cast(settings[key])
|
||||
end
|
||||
|
Reference in New Issue
Block a user