Change: #82 フレンド申請時、自分のサーバーのInbox URLを伝える
This commit is contained in:
parent
eea84d476e
commit
6b4fc4a9dc
4 changed files with 27 additions and 7 deletions
|
@ -53,7 +53,7 @@ class ActivityPub::Activity::Follow < ActivityPub::Activity
|
|||
friend.update!(passive_state: :pending, active_state: :idle, passive_follow_activity_id: @json['id'])
|
||||
else
|
||||
@friend = FriendDomain.new(domain: @account.domain, passive_state: :pending, passive_follow_activity_id: @json['id'])
|
||||
@friend.initialize_inbox_url!
|
||||
@friend.inbox_url = @json['inboxUrl'].presence || @friend.default_inbox_url
|
||||
@friend.save!
|
||||
end
|
||||
|
||||
|
|
|
@ -93,16 +93,12 @@ class FriendDomain < ApplicationRecord
|
|||
destroy!
|
||||
end
|
||||
|
||||
def initialize_inbox_url!
|
||||
self.inbox_url = default_inbox_url
|
||||
end
|
||||
|
||||
private
|
||||
|
||||
def default_inbox_url
|
||||
"https://#{domain}/inbox"
|
||||
end
|
||||
|
||||
private
|
||||
|
||||
def delete_for_friend!
|
||||
activity_id = ActivityPub::TagManager.instance.generate_uri_for(nil)
|
||||
payload = Oj.dump(delete_follow_activity(activity_id))
|
||||
|
@ -118,6 +114,9 @@ class FriendDomain < ApplicationRecord
|
|||
type: 'Follow',
|
||||
actor: ActivityPub::TagManager.instance.uri_for(some_local_account),
|
||||
object: ActivityPub::TagManager::COLLECTIONS[:public],
|
||||
|
||||
# Cannot use inbox_url method because this model also has inbox_url column
|
||||
inboxUrl: "https://#{Rails.configuration.x.web_domain}/inbox",
|
||||
}
|
||||
end
|
||||
|
||||
|
|
|
@ -310,6 +310,7 @@ RSpec.describe ActivityPub::Activity::Follow do
|
|||
let!(:friend) { Fabricate(:friend_domain, domain: 'abc.com', passive_state: :idle) }
|
||||
let!(:owner_user) { Fabricate(:user, role: UserRole.find_by(name: 'Owner')) }
|
||||
let!(:patch_user) { Fabricate(:user, role: Fabricate(:user_role, name: 'OhagiOps', permissions: UserRole::FLAGS[:manage_federation])) }
|
||||
let(:inbox_url) { nil }
|
||||
|
||||
let(:json) do
|
||||
{
|
||||
|
@ -318,6 +319,7 @@ RSpec.describe ActivityPub::Activity::Follow do
|
|||
type: 'Follow',
|
||||
actor: ActivityPub::TagManager.instance.uri_for(sender),
|
||||
object: 'https://www.w3.org/ns/activitystreams#Public',
|
||||
inboxUrl: inbox_url,
|
||||
}.with_indifferent_access
|
||||
end
|
||||
|
||||
|
@ -343,6 +345,24 @@ RSpec.describe ActivityPub::Activity::Follow do
|
|||
end
|
||||
end
|
||||
|
||||
context 'when no record and inbox_url is specified' do
|
||||
let(:inbox_url) { 'https://ohagi.com/inbox' }
|
||||
|
||||
before do
|
||||
friend.update(domain: 'def.com')
|
||||
end
|
||||
|
||||
it 'marks the friend as pending' do
|
||||
subject.perform
|
||||
|
||||
friend = FriendDomain.find_by(domain: 'abc.com')
|
||||
expect(friend).to_not be_nil
|
||||
expect(friend.they_are_pending?).to be true
|
||||
expect(friend.passive_follow_activity_id).to eq 'foo'
|
||||
expect(friend.inbox_url).to eq 'https://ohagi.com/inbox'
|
||||
end
|
||||
end
|
||||
|
||||
context 'when my server is pending' do
|
||||
before do
|
||||
friend.update(active_state: :pending)
|
||||
|
|
|
@ -21,6 +21,7 @@ describe FriendDomain do
|
|||
type: 'Follow',
|
||||
actor: 'https://cb6e6126.ngrok.io/actor',
|
||||
object: 'https://www.w3.org/ns/activitystreams#Public',
|
||||
inboxUrl: 'https://cb6e6126.ngrok.io/inbox',
|
||||
}))).to have_been_made.once
|
||||
end
|
||||
end
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue