diff --git a/lib/diaspora_federation/discovery/web_finger.rb b/lib/diaspora_federation/discovery/web_finger.rb
index 367b587..37ea36c 100644
--- a/lib/diaspora_federation/discovery/web_finger.rb
+++ b/lib/diaspora_federation/discovery/web_finger.rb
@@ -75,6 +75,10 @@ module DiasporaFederation
# Panzer draft for Salmon, paragraph 3.3
property :salmon_url
+ # @!attribute [r] subscribe_url
+ # This url is used to find another user on the home-pod of the user in the webfinger.
+ property :subscribe_url
+
# @!attribute [r] guid
# @deprecated Either convert these to +Property+ elements or move to the
# +hCard+, which actually has fields for an +UID+ defined in the +vCard+
@@ -121,6 +125,9 @@ module DiasporaFederation
# +salmon_url+ link relation
REL_SALMON = "salmon"
+ # +subscribe_url+ link relation
+ REL_SUBSCRIBE = "http://ostatus.org/schema/1.0/subscribe"
+
# @deprecated This should be a +Property+ or moved to the +hcard+, but +Link+
# is inappropriate according to the specification (will affect older
# Diaspora* installations).
@@ -152,17 +159,19 @@ module DiasporaFederation
public_key = parse_link(links, REL_PUBKEY)
new(
- acct_uri: data[:subject],
- alias_url: parse_alias(data[:aliases]),
- hcard_url: parse_link(links, REL_HCARD),
- seed_url: parse_link(links, REL_SEED),
- profile_url: parse_link(links, REL_PROFILE),
- atom_url: parse_link(links, REL_ATOM),
- salmon_url: parse_link(links, REL_SALMON),
+ acct_uri: data[:subject],
+ alias_url: parse_alias(data[:aliases]),
+ hcard_url: parse_link(links, REL_HCARD),
+ seed_url: parse_link(links, REL_SEED),
+ profile_url: parse_link(links, REL_PROFILE),
+ atom_url: parse_link(links, REL_ATOM),
+ salmon_url: parse_link(links, REL_SALMON),
+
+ subscribe_url: parse_link_template(links, REL_SUBSCRIBE),
# TODO: remove me! ##########
- guid: parse_link(links, REL_GUID),
- public_key: (Base64.strict_decode64(public_key) if public_key)
+ guid: parse_link(links, REL_GUID),
+ public_key: (Base64.strict_decode64(public_key) if public_key)
)
end
@@ -182,27 +191,18 @@ module DiasporaFederation
private_class_method :parse_xml_and_validate
def add_links_to(doc)
- doc.links << {rel: REL_HCARD,
- type: "text/html",
- href: @hcard_url}
- doc.links << {rel: REL_SEED,
- type: "text/html",
- href: @seed_url}
+ doc.links << {rel: REL_HCARD, type: "text/html", href: @hcard_url}
+ doc.links << {rel: REL_SEED, type: "text/html", href: @seed_url}
# TODO: remove me! ##############
- doc.links << {rel: REL_GUID,
- type: "text/html",
- href: @guid}
+ doc.links << {rel: REL_GUID, type: "text/html", href: @guid}
##################################
- doc.links << {rel: REL_PROFILE,
- type: "text/html",
- href: @profile_url}
- doc.links << {rel: REL_ATOM,
- type: "application/atom+xml",
- href: @atom_url}
- doc.links << {rel: REL_SALMON,
- href: @salmon_url}
+ doc.links << {rel: REL_PROFILE, type: "text/html", href: @profile_url}
+ doc.links << {rel: REL_ATOM, type: "application/atom+xml", href: @atom_url}
+ doc.links << {rel: REL_SALMON, href: @salmon_url}
+
+ doc.links << {rel: REL_SUBSCRIBE, template: @subscribe_url}
# TODO: remove me! ##############
doc.links << {rel: REL_PUBKEY,
@@ -211,12 +211,23 @@ module DiasporaFederation
##################################
end
+ def self.find_link(links, rel)
+ links.find {|l| l[:rel] == rel }
+ end
+ private_class_method :find_link
+
def self.parse_link(links, rel)
- element = links.find {|l| l[:rel] == rel }
+ element = find_link(links, rel)
element ? element[:href] : nil
end
private_class_method :parse_link
+ def self.parse_link_template(links, rel)
+ element = find_link(links, rel)
+ element ? element[:template] : nil
+ end
+ private_class_method :parse_link_template
+
# this method is used to parse the alias_url from the XML.
# * redmatrix has sometimes no alias, return nil
# * old pods had quotes around the alias url, this can be removed later
diff --git a/lib/diaspora_federation/test/factories.rb b/lib/diaspora_federation/test/factories.rb
index ed20207..39cc3cd 100644
--- a/lib/diaspora_federation/test/factories.rb
+++ b/lib/diaspora_federation/test/factories.rb
@@ -21,6 +21,7 @@ module DiasporaFederation
atom_url "http://localhost:3000/public/user.atom"
salmon_url "http://localhost:3000/receive/users/0123456789abcdef"
public_key
+ subscribe_url "http://localhost:3000/people?q={uri}"
end
factory :h_card, class: DiasporaFederation::Discovery::HCard do
diff --git a/spec/lib/diaspora_federation/discovery/web_finger_spec.rb b/spec/lib/diaspora_federation/discovery/web_finger_spec.rb
index 8e6eace..dc1e2ea 100644
--- a/spec/lib/diaspora_federation/discovery/web_finger_spec.rb
+++ b/spec/lib/diaspora_federation/discovery/web_finger_spec.rb
@@ -6,15 +6,16 @@ module DiasporaFederation
let(:data) {
{
- acct_uri: "acct:#{person.diaspora_id}",
- alias_url: person.alias_url,
- hcard_url: person.hcard_url,
- seed_url: person.url,
- profile_url: person.profile_url,
- atom_url: person.atom_url,
- salmon_url: person.salmon_url,
- guid: person.guid,
- public_key: person.serialized_public_key
+ acct_uri: "acct:#{person.diaspora_id}",
+ alias_url: person.alias_url,
+ hcard_url: person.hcard_url,
+ seed_url: person.url,
+ profile_url: person.profile_url,
+ atom_url: person.atom_url,
+ salmon_url: person.salmon_url,
+ guid: person.guid,
+ public_key: person.serialized_public_key,
+ subscribe_url: person.subscribe_url
}
}
@@ -30,6 +31,7 @@ module DiasporaFederation
+
XML
@@ -54,6 +56,7 @@ XML
expect(wf.profile_url).to eq(person.profile_url)
expect(wf.atom_url).to eq(person.atom_url)
expect(wf.salmon_url).to eq(person.salmon_url)
+ expect(wf.subscribe_url).to eq(person.subscribe_url)
expect(wf.guid).to eq(person.guid)
expect(wf.public_key).to eq(person.serialized_public_key)
@@ -150,6 +153,7 @@ XML
expect(wf.profile_url).to eq(person.profile_url)
expect(wf.atom_url).to eq(person.atom_url)
expect(wf.salmon_url).to eq(person.salmon_url)
+ expect(wf.subscribe_url).to eq("https://pod.example.tld/follow?url={uri}")
expect(wf.guid).to eq(person.guid)
expect(wf.public_key).to eq(person.serialized_public_key)
@@ -211,6 +215,7 @@ XML
+
XML
@@ -222,6 +227,7 @@ XML
expect(wf.profile_url).to eq(person.profile_url)
expect(wf.atom_url).to eq(person.atom_url)
expect(wf.salmon_url).to eq(person.salmon_url)
+ expect(wf.subscribe_url).to eq(person.subscribe_url)
expect(wf.guid).to be_nil
expect(wf.public_key).to be_nil
diff --git a/test/dummy/app/models/person.rb b/test/dummy/app/models/person.rb
index 26d517b..013979c 100644
--- a/test/dummy/app/models/person.rb
+++ b/test/dummy/app/models/person.rb
@@ -1,11 +1,12 @@
class Person < ActiveRecord::Base
include ::Diaspora::Guid
- def alias_url; "#{url}people/#{guid}" end
- def hcard_url; "#{url}hcard/users/#{guid}" end
- def profile_url; "#{url}u/#{nickname}" end
- def atom_url; "#{url}public/#{nickname}.atom" end
- def salmon_url; "#{url}receive/users/#{guid}" end
+ def alias_url; "#{url}people/#{guid}" end
+ def hcard_url; "#{url}hcard/users/#{guid}" end
+ def profile_url; "#{url}u/#{nickname}" end
+ def atom_url; "#{url}public/#{nickname}.atom" end
+ def salmon_url; "#{url}receive/users/#{guid}" end
+ def subscribe_url; "#{url}people?q={uri}" end
def nickname; diaspora_id.split("@")[0] end
diff --git a/test/dummy/config/initializers/diaspora_federation.rb b/test/dummy/config/initializers/diaspora_federation.rb
index cc48ce1..b0bd2d7 100644
--- a/test/dummy/config/initializers/diaspora_federation.rb
+++ b/test/dummy/config/initializers/diaspora_federation.rb
@@ -20,15 +20,16 @@ DiasporaFederation.configure do |config|
person = Person.find_by(diaspora_id: diaspora_id)
if person
DiasporaFederation::Discovery::WebFinger.new(
- acct_uri: "acct:#{person.diaspora_id}",
- alias_url: person.alias_url,
- hcard_url: person.hcard_url,
- seed_url: person.url,
- profile_url: person.profile_url,
- atom_url: person.atom_url,
- salmon_url: person.salmon_url,
- guid: person.guid,
- public_key: person.serialized_public_key
+ acct_uri: "acct:#{person.diaspora_id}",
+ alias_url: person.alias_url,
+ hcard_url: person.hcard_url,
+ seed_url: person.url,
+ profile_url: person.profile_url,
+ atom_url: person.atom_url,
+ salmon_url: person.salmon_url,
+ subscribe_url: person.subscribe_url,
+ guid: person.guid,
+ public_key: person.serialized_public_key
)
end
end