Skip to content

Commit

Permalink
Merge pull request #110 from kmycode/kbtopic-82-friend-server-inbox-url
Browse files Browse the repository at this point in the history
Change: #82 フレンド申請時、自分のサーバーのInbox URLを伝える
  • Loading branch information
kmycode authored Oct 13, 2023
2 parents 8549f78 + 6451b85 commit 369f3c6
Show file tree
Hide file tree
Showing 4 changed files with 27 additions and 7 deletions.
2 changes: 1 addition & 1 deletion app/lib/activitypub/activity/follow.rb
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ def request_follow_for_friend
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

Expand Down
11 changes: 5 additions & 6 deletions app/models/friend_domain.rb
Original file line number Diff line number Diff line change
Expand Up @@ -93,16 +93,12 @@ def destroy_without_signal!
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))
Expand All @@ -118,6 +114,9 @@ def follow_activity(activity_id)
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

Expand Down
20 changes: 20 additions & 0 deletions spec/lib/activitypub/activity/follow_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -310,6 +310,7 @@
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
{
Expand All @@ -318,6 +319,7 @@
type: 'Follow',
actor: ActivityPub::TagManager.instance.uri_for(sender),
object: 'https://www.w3.org/ns/activitystreams#Public',
inboxUrl: inbox_url,
}.with_indifferent_access
end

Expand All @@ -343,6 +345,24 @@
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)
Expand Down
1 change: 1 addition & 0 deletions spec/models/friend_domain_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@
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
Expand Down

0 comments on commit 369f3c6

Please sign in to comment.