Merge pull request #3373 from ClearlyClaire/glitch-soc/merge-4.5
Merge upstream changes up to 68a26ce7c6 into stable-4.5
This commit is contained in:
@@ -29,7 +29,7 @@ class StatusesController < ApplicationController
|
|||||||
end
|
end
|
||||||
|
|
||||||
format.json do
|
format.json do
|
||||||
expires_in 3.minutes, public: true if @status.distributable? && public_fetch_mode?
|
expires_in @status.quote&.pending? ? 5.seconds : 3.minutes, public: true if @status.distributable? && public_fetch_mode?
|
||||||
render_with_cache json: @status, content_type: 'application/activity+json', serializer: ActivityPub::NoteSerializer, adapter: ActivityPub::Adapter
|
render_with_cache json: @status, content_type: 'application/activity+json', serializer: ActivityPub::NoteSerializer, adapter: ActivityPub::Adapter
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|||||||
@@ -159,6 +159,7 @@ class Status extends ImmutablePureComponent {
|
|||||||
'expanded',
|
'expanded',
|
||||||
'unread',
|
'unread',
|
||||||
'pictureInPicture',
|
'pictureInPicture',
|
||||||
|
'onQuoteCancel',
|
||||||
'previousId',
|
'previousId',
|
||||||
'nextInReplyToId',
|
'nextInReplyToId',
|
||||||
'rootId',
|
'rootId',
|
||||||
|
|||||||
@@ -145,6 +145,7 @@ class Status extends ImmutablePureComponent {
|
|||||||
'hidden',
|
'hidden',
|
||||||
'unread',
|
'unread',
|
||||||
'pictureInPicture',
|
'pictureInPicture',
|
||||||
|
'onQuoteCancel',
|
||||||
];
|
];
|
||||||
|
|
||||||
state = {
|
state = {
|
||||||
|
|||||||
@@ -379,6 +379,7 @@ class ActivityPub::Activity::Create < ActivityPub::Activity
|
|||||||
def conversation_from_uri(uri)
|
def conversation_from_uri(uri)
|
||||||
return nil if uri.nil?
|
return nil if uri.nil?
|
||||||
return Conversation.find_by(id: OStatus::TagManager.instance.unique_tag_to_local_id(uri, 'Conversation')) if OStatus::TagManager.instance.local_id?(uri)
|
return Conversation.find_by(id: OStatus::TagManager.instance.unique_tag_to_local_id(uri, 'Conversation')) if OStatus::TagManager.instance.local_id?(uri)
|
||||||
|
return ActivityPub::TagManager.instance.uri_to_resource(uri, Conversation) if ActivityPub::TagManager.instance.local_uri?(uri)
|
||||||
|
|
||||||
begin
|
begin
|
||||||
Conversation.find_or_create_by!(uri: uri)
|
Conversation.find_or_create_by!(uri: uri)
|
||||||
|
|||||||
@@ -241,12 +241,6 @@ class ActivityPub::TagManager
|
|||||||
!host.nil? && (::TagManager.instance.local_domain?(host) || ::TagManager.instance.web_domain?(host))
|
!host.nil? && (::TagManager.instance.local_domain?(host) || ::TagManager.instance.web_domain?(host))
|
||||||
end
|
end
|
||||||
|
|
||||||
def uri_to_local_id(uri, param = :id)
|
|
||||||
path_params = Rails.application.routes.recognize_path(uri)
|
|
||||||
path_params[:username] = Rails.configuration.x.local_domain if path_params[:controller] == 'instance_actors'
|
|
||||||
path_params[param]
|
|
||||||
end
|
|
||||||
|
|
||||||
def uris_to_local_accounts(uris)
|
def uris_to_local_accounts(uris)
|
||||||
usernames = []
|
usernames = []
|
||||||
ids = []
|
ids = []
|
||||||
@@ -264,6 +258,14 @@ class ActivityPub::TagManager
|
|||||||
uri_to_resource(uri, Account)
|
uri_to_resource(uri, Account)
|
||||||
end
|
end
|
||||||
|
|
||||||
|
def uri_to_local_conversation(uri)
|
||||||
|
path_params = Rails.application.routes.recognize_path(uri)
|
||||||
|
return unless path_params[:controller] == 'activitypub/contexts'
|
||||||
|
|
||||||
|
account_id, conversation_id = path_params[:id].split('-')
|
||||||
|
Conversation.find_by(parent_account_id: account_id, id: conversation_id)
|
||||||
|
end
|
||||||
|
|
||||||
def uri_to_resource(uri, klass)
|
def uri_to_resource(uri, klass)
|
||||||
return if uri.nil?
|
return if uri.nil?
|
||||||
|
|
||||||
@@ -271,6 +273,8 @@ class ActivityPub::TagManager
|
|||||||
case klass.name
|
case klass.name
|
||||||
when 'Account'
|
when 'Account'
|
||||||
uris_to_local_accounts([uri]).first
|
uris_to_local_accounts([uri]).first
|
||||||
|
when 'Conversation'
|
||||||
|
uri_to_local_conversation(uri)
|
||||||
else
|
else
|
||||||
StatusFinder.new(uri).status
|
StatusFinder.new(uri).status
|
||||||
end
|
end
|
||||||
|
|||||||
@@ -70,6 +70,7 @@ class ConnectionPool::SharedTimedStack
|
|||||||
if @created == @max && !@queue.empty?
|
if @created == @max && !@queue.empty?
|
||||||
throw_away_connection = @queue.pop
|
throw_away_connection = @queue.pop
|
||||||
@tagged_queue[throw_away_connection.site].delete(throw_away_connection)
|
@tagged_queue[throw_away_connection.site].delete(throw_away_connection)
|
||||||
|
throw_away_connection.close
|
||||||
@create_block.call(preferred_tag)
|
@create_block.call(preferred_tag)
|
||||||
elsif @created != @max
|
elsif @created != @max
|
||||||
connection = @create_block.call(preferred_tag)
|
connection = @create_block.call(preferred_tag)
|
||||||
|
|||||||
@@ -11,16 +11,12 @@ class OStatus::TagManager
|
|||||||
def unique_tag_to_local_id(tag, expected_type)
|
def unique_tag_to_local_id(tag, expected_type)
|
||||||
return nil unless local_id?(tag)
|
return nil unless local_id?(tag)
|
||||||
|
|
||||||
if ActivityPub::TagManager.instance.local_uri?(tag)
|
matches = Regexp.new("objectId=([\\d]+):objectType=#{expected_type}").match(tag)
|
||||||
ActivityPub::TagManager.instance.uri_to_local_id(tag)
|
matches[1] unless matches.nil?
|
||||||
else
|
|
||||||
matches = Regexp.new("objectId=([\\d]+):objectType=#{expected_type}").match(tag)
|
|
||||||
matches[1] unless matches.nil?
|
|
||||||
end
|
|
||||||
end
|
end
|
||||||
|
|
||||||
def local_id?(id)
|
def local_id?(id)
|
||||||
id.start_with?("tag:#{Rails.configuration.x.local_domain}") || ActivityPub::TagManager.instance.local_uri?(id)
|
id.start_with?("tag:#{Rails.configuration.x.local_domain}")
|
||||||
end
|
end
|
||||||
|
|
||||||
def uri_for(target)
|
def uri_for(target)
|
||||||
|
|||||||
@@ -47,6 +47,8 @@ class Quote < ApplicationRecord
|
|||||||
|
|
||||||
def accept!
|
def accept!
|
||||||
update!(state: :accepted)
|
update!(state: :accepted)
|
||||||
|
|
||||||
|
reset_parent_cache! if attribute_previously_changed?(:state)
|
||||||
end
|
end
|
||||||
|
|
||||||
def reject!
|
def reject!
|
||||||
@@ -75,6 +77,15 @@ class Quote < ApplicationRecord
|
|||||||
|
|
||||||
private
|
private
|
||||||
|
|
||||||
|
def reset_parent_cache!
|
||||||
|
return if status_id.nil?
|
||||||
|
|
||||||
|
Rails.cache.delete("v3:statuses/#{status_id}")
|
||||||
|
|
||||||
|
# This clears the web cache for the ActivityPub representation
|
||||||
|
Rails.cache.delete("statuses/show:v3:statuses/#{status_id}")
|
||||||
|
end
|
||||||
|
|
||||||
def set_accounts
|
def set_accounts
|
||||||
self.account = status.account
|
self.account = status.account
|
||||||
self.quoted_account = quoted_status&.account
|
self.quoted_account = quoted_status&.account
|
||||||
|
|||||||
@@ -204,7 +204,11 @@ class ActivityPub::ProcessStatusUpdateService < BaseService
|
|||||||
|
|
||||||
def update_tags!
|
def update_tags!
|
||||||
previous_tags = @status.tags.to_a
|
previous_tags = @status.tags.to_a
|
||||||
current_tags = @status.tags = Tag.find_or_create_by_names(@raw_tags)
|
current_tags = @status.tags = @raw_tags.flat_map do |tag|
|
||||||
|
Tag.find_or_create_by_names([tag]).filter(&:valid?)
|
||||||
|
rescue ActiveRecord::RecordInvalid
|
||||||
|
[]
|
||||||
|
end
|
||||||
|
|
||||||
return unless @status.distributable?
|
return unless @status.distributable?
|
||||||
|
|
||||||
|
|||||||
@@ -57,7 +57,7 @@ class FeedInsertWorker
|
|||||||
|
|
||||||
def notify?(filter_result)
|
def notify?(filter_result)
|
||||||
return false if @type != :home || @status.reblog? || (@status.reply? && @status.in_reply_to_account_id != @status.account_id) ||
|
return false if @type != :home || @status.reblog? || (@status.reply? && @status.in_reply_to_account_id != @status.account_id) ||
|
||||||
filter_result == :filter
|
update? || filter_result == :filter
|
||||||
|
|
||||||
Follow.find_by(account: @follower, target_account: @status.account)&.notify?
|
Follow.find_by(account: @follower, target_account: @status.account)&.notify?
|
||||||
end
|
end
|
||||||
|
|||||||
@@ -64,6 +64,16 @@ class MoveWorker
|
|||||||
.in_batches do |follows|
|
.in_batches do |follows|
|
||||||
ListAccount.where(follow: follows).in_batches.update_all(account_id: @target_account.id)
|
ListAccount.where(follow: follows).in_batches.update_all(account_id: @target_account.id)
|
||||||
num_moved += follows.update_all(target_account_id: @target_account.id)
|
num_moved += follows.update_all(target_account_id: @target_account.id)
|
||||||
|
|
||||||
|
# Clear any relationship cache, since callbacks are not called
|
||||||
|
Rails.cache.delete_multi(follows.flat_map do |follow|
|
||||||
|
[
|
||||||
|
['relationship', follow.account_id, follow.target_account_id],
|
||||||
|
['relationship', follow.target_account_id, follow.account_id],
|
||||||
|
['relationship', follow.account_id, @target_account.id],
|
||||||
|
['relationship', @target_account.id, follow.account_id],
|
||||||
|
]
|
||||||
|
end)
|
||||||
end
|
end
|
||||||
|
|
||||||
num_moved
|
num_moved
|
||||||
|
|||||||
@@ -521,7 +521,7 @@ RSpec.describe ActivityPub::Activity::Create do
|
|||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
context 'with a reply' do
|
context 'with a reply without explicitly setting a conversation' do
|
||||||
let(:original_status) { Fabricate(:status) }
|
let(:original_status) { Fabricate(:status) }
|
||||||
|
|
||||||
let(:object_json) do
|
let(:object_json) do
|
||||||
@@ -543,6 +543,30 @@ RSpec.describe ActivityPub::Activity::Create do
|
|||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
context 'with a reply explicitly setting a conversation' do
|
||||||
|
let(:original_status) { Fabricate(:status) }
|
||||||
|
|
||||||
|
let(:object_json) do
|
||||||
|
build_object(
|
||||||
|
inReplyTo: ActivityPub::TagManager.instance.uri_for(original_status),
|
||||||
|
conversation: ActivityPub::TagManager.instance.uri_for(original_status.conversation),
|
||||||
|
context: ActivityPub::TagManager.instance.uri_for(original_status.conversation)
|
||||||
|
)
|
||||||
|
end
|
||||||
|
|
||||||
|
it 'creates status' do
|
||||||
|
expect { subject.perform }.to change(sender.statuses, :count).by(1)
|
||||||
|
|
||||||
|
status = sender.statuses.first
|
||||||
|
|
||||||
|
expect(status).to_not be_nil
|
||||||
|
expect(status.thread).to eq original_status
|
||||||
|
expect(status.reply?).to be true
|
||||||
|
expect(status.in_reply_to_account).to eq original_status.account
|
||||||
|
expect(status.conversation).to eq original_status.conversation
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
context 'with mentions' do
|
context 'with mentions' do
|
||||||
let(:recipient) { Fabricate(:account) }
|
let(:recipient) { Fabricate(:account) }
|
||||||
|
|
||||||
|
|||||||
@@ -612,14 +612,6 @@ RSpec.describe ActivityPub::TagManager do
|
|||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
describe '#uri_to_local_id' do
|
|
||||||
let(:account) { Fabricate(:account, id_scheme: :username_ap_id) }
|
|
||||||
|
|
||||||
it 'returns the local ID' do
|
|
||||||
expect(subject.uri_to_local_id(subject.uri_for(account), :username)).to eq account.username
|
|
||||||
end
|
|
||||||
end
|
|
||||||
|
|
||||||
describe '#uris_to_local_accounts' do
|
describe '#uris_to_local_accounts' do
|
||||||
it 'returns the expected local accounts' do
|
it 'returns the expected local accounts' do
|
||||||
account = Fabricate(:account)
|
account = Fabricate(:account)
|
||||||
|
|||||||
@@ -258,6 +258,7 @@ RSpec.describe ActivityPub::ProcessStatusUpdateService do
|
|||||||
tag: [
|
tag: [
|
||||||
{ type: 'Hashtag', name: 'foo' },
|
{ type: 'Hashtag', name: 'foo' },
|
||||||
{ type: 'Hashtag', name: 'bar' },
|
{ type: 'Hashtag', name: 'bar' },
|
||||||
|
{ type: 'Hashtag', name: '#2024' },
|
||||||
],
|
],
|
||||||
}
|
}
|
||||||
end
|
end
|
||||||
|
|||||||
Reference in New Issue
Block a user