Change: #82 フレンド申請時、自分のサーバーのInbox URLを伝える
This commit is contained in:
parent
5cb8ccad84
commit
6451b853e7
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'])
|
friend.update!(passive_state: :pending, active_state: :idle, passive_follow_activity_id: @json['id'])
|
||||||
else
|
else
|
||||||
@friend = FriendDomain.new(domain: @account.domain, passive_state: :pending, passive_follow_activity_id: @json['id'])
|
@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!
|
@friend.save!
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
|
@ -93,16 +93,12 @@ class FriendDomain < ApplicationRecord
|
||||||
destroy!
|
destroy!
|
||||||
end
|
end
|
||||||
|
|
||||||
def initialize_inbox_url!
|
|
||||||
self.inbox_url = default_inbox_url
|
|
||||||
end
|
|
||||||
|
|
||||||
private
|
|
||||||
|
|
||||||
def default_inbox_url
|
def default_inbox_url
|
||||||
"https://#{domain}/inbox"
|
"https://#{domain}/inbox"
|
||||||
end
|
end
|
||||||
|
|
||||||
|
private
|
||||||
|
|
||||||
def delete_for_friend!
|
def delete_for_friend!
|
||||||
activity_id = ActivityPub::TagManager.instance.generate_uri_for(nil)
|
activity_id = ActivityPub::TagManager.instance.generate_uri_for(nil)
|
||||||
payload = Oj.dump(delete_follow_activity(activity_id))
|
payload = Oj.dump(delete_follow_activity(activity_id))
|
||||||
|
@ -118,6 +114,9 @@ class FriendDomain < ApplicationRecord
|
||||||
type: 'Follow',
|
type: 'Follow',
|
||||||
actor: ActivityPub::TagManager.instance.uri_for(some_local_account),
|
actor: ActivityPub::TagManager.instance.uri_for(some_local_account),
|
||||||
object: ActivityPub::TagManager::COLLECTIONS[:public],
|
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
|
end
|
||||||
|
|
||||||
|
|
|
@ -310,6 +310,7 @@ RSpec.describe ActivityPub::Activity::Follow do
|
||||||
let!(:friend) { Fabricate(:friend_domain, domain: 'abc.com', passive_state: :idle) }
|
let!(:friend) { Fabricate(:friend_domain, domain: 'abc.com', passive_state: :idle) }
|
||||||
let!(:owner_user) { Fabricate(:user, role: UserRole.find_by(name: 'Owner')) }
|
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!(:patch_user) { Fabricate(:user, role: Fabricate(:user_role, name: 'OhagiOps', permissions: UserRole::FLAGS[:manage_federation])) }
|
||||||
|
let(:inbox_url) { nil }
|
||||||
|
|
||||||
let(:json) do
|
let(:json) do
|
||||||
{
|
{
|
||||||
|
@ -318,6 +319,7 @@ RSpec.describe ActivityPub::Activity::Follow do
|
||||||
type: 'Follow',
|
type: 'Follow',
|
||||||
actor: ActivityPub::TagManager.instance.uri_for(sender),
|
actor: ActivityPub::TagManager.instance.uri_for(sender),
|
||||||
object: 'https://www.w3.org/ns/activitystreams#Public',
|
object: 'https://www.w3.org/ns/activitystreams#Public',
|
||||||
|
inboxUrl: inbox_url,
|
||||||
}.with_indifferent_access
|
}.with_indifferent_access
|
||||||
end
|
end
|
||||||
|
|
||||||
|
@ -343,6 +345,24 @@ RSpec.describe ActivityPub::Activity::Follow do
|
||||||
end
|
end
|
||||||
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
|
context 'when my server is pending' do
|
||||||
before do
|
before do
|
||||||
friend.update(active_state: :pending)
|
friend.update(active_state: :pending)
|
||||||
|
|
|
@ -21,6 +21,7 @@ describe FriendDomain do
|
||||||
type: 'Follow',
|
type: 'Follow',
|
||||||
actor: 'https://cb6e6126.ngrok.io/actor',
|
actor: 'https://cb6e6126.ngrok.io/actor',
|
||||||
object: 'https://www.w3.org/ns/activitystreams#Public',
|
object: 'https://www.w3.org/ns/activitystreams#Public',
|
||||||
|
inboxUrl: 'https://cb6e6126.ngrok.io/inbox',
|
||||||
}))).to have_been_made.once
|
}))).to have_been_made.once
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue