Add webfinger and basic feed support.
This commit is contained in:
parent
36e883cd4b
commit
d23f3e3cf3
9 changed files with 160 additions and 17 deletions
26
lib/pleroma/web/ostatus/feed_representer.ex
Normal file
26
lib/pleroma/web/ostatus/feed_representer.ex
Normal file
|
|
@ -0,0 +1,26 @@
|
|||
defmodule Pleroma.Web.OStatus.FeedRepresenter do
|
||||
alias Pleroma.Web.OStatus
|
||||
alias Pleroma.Web.OStatus.UserRepresenter
|
||||
|
||||
def to_simple_form(user, activities, users) do
|
||||
most_recent_update = List.first(activities).updated_at
|
||||
|> NaiveDateTime.to_iso8601
|
||||
|
||||
h = fn(str) -> [to_charlist(str)] end
|
||||
|
||||
entries = []
|
||||
[{
|
||||
:feed, [
|
||||
xmlns: 'http://www.w3.org/2005/Atom',
|
||||
"xmlns:activity": 'http://activitystrea.ms/spec/1.0/'
|
||||
], [
|
||||
{:id, h.(OStatus.feed_path(user))},
|
||||
{:title, ['#{user.nickname}\'s timeline']},
|
||||
{:updated, h.(most_recent_update)},
|
||||
{:entries, []},
|
||||
{:link, [rel: 'hub', href: h.(OStatus.pubsub_path)], []},
|
||||
{:author, UserRepresenter.to_simple_form(user)}
|
||||
]
|
||||
}]
|
||||
end
|
||||
end
|
||||
14
lib/pleroma/web/ostatus/ostatus.ex
Normal file
14
lib/pleroma/web/ostatus/ostatus.ex
Normal file
|
|
@ -0,0 +1,14 @@
|
|||
defmodule Pleroma.Web.OStatus do
|
||||
alias Pleroma.Web
|
||||
|
||||
def feed_path(user) do
|
||||
"#{user.ap_id}/feed.atom"
|
||||
end
|
||||
|
||||
def pubsub_path() do
|
||||
"#{Web.base_url}/push/hub"
|
||||
end
|
||||
|
||||
def user_path(user) do
|
||||
end
|
||||
end
|
||||
26
lib/pleroma/web/ostatus/ostatus_controller.ex
Normal file
26
lib/pleroma/web/ostatus/ostatus_controller.ex
Normal file
|
|
@ -0,0 +1,26 @@
|
|||
defmodule Pleroma.Web.OStatus.OStatusController do
|
||||
use Pleroma.Web, :controller
|
||||
|
||||
alias Pleroma.{User, Activity}
|
||||
alias Pleroma.Web.OStatus.FeedRepresenter
|
||||
alias Pleroma.Repo
|
||||
import Ecto.Query
|
||||
|
||||
def feed(conn, %{"nickname" => nickname}) do
|
||||
user = User.get_cached_by_nickname(nickname)
|
||||
query = from activity in Activity,
|
||||
where: fragment("? @> ?", activity.data, ^%{actor: user.ap_id}),
|
||||
limit: 20,
|
||||
order_by: [desc: :inserted_at]
|
||||
|
||||
activities = query
|
||||
|> Repo.all
|
||||
|
||||
response = FeedRepresenter.to_simple_form(user, activities, [user])
|
||||
|> :xmerl.export_simple(:xmerl_xml)
|
||||
|
||||
conn
|
||||
|> put_resp_content_type("application/atom+xml")
|
||||
|> send_resp(200, response)
|
||||
end
|
||||
end
|
||||
|
|
@ -1,14 +1,15 @@
|
|||
defmodule Pleroma.Web.OStatus.UserRepresenter do
|
||||
alias Pleroma.User
|
||||
def to_tuple(user, wrapper \\ :author) do
|
||||
{
|
||||
wrapper, [
|
||||
{ :id, user.ap_id },
|
||||
{ :"activity:object", "http://activitystrea.ms/schema/1.0/person" },
|
||||
{ :uri, user.ap_id },
|
||||
{ :name, user.nickname },
|
||||
{ :link, %{rel: "avatar", href: User.avatar_url(user)}}
|
||||
]
|
||||
}
|
||||
def to_simple_form(user) do
|
||||
ap_id = to_charlist(user.ap_id)
|
||||
nickname = to_charlist(user.nickname)
|
||||
avatar_url = to_charlist(User.avatar_url(user))
|
||||
[
|
||||
{ :id, [ap_id] },
|
||||
{ :"activity:object", ['http://activitystrea.ms/schema/1.0/person'] },
|
||||
{ :uri, [ap_id] },
|
||||
{ :name, [nickname] },
|
||||
{ :link, [rel: 'avatar', href: avatar_url], []}
|
||||
]
|
||||
end
|
||||
end
|
||||
|
|
|
|||
|
|
@ -54,6 +54,16 @@ defmodule Pleroma.Web.Router do
|
|||
post "/qvitter/update_avatar", TwitterAPI.Controller, :update_avatar
|
||||
end
|
||||
|
||||
pipeline :ostatus do
|
||||
plug :accepts, ["xml", "atom"]
|
||||
end
|
||||
|
||||
scope "/users", Pleroma.Web do
|
||||
pipe_through :ostatus
|
||||
|
||||
get "/:nickname/feed", OStatus.OStatusController, :feed
|
||||
end
|
||||
|
||||
scope "/.well-known", Pleroma.Web do
|
||||
pipe_through :well_known
|
||||
|
||||
|
|
|
|||
|
|
@ -1,6 +1,7 @@
|
|||
defmodule Pleroma.Web.WebFinger do
|
||||
alias Pleroma.XmlBuilder
|
||||
alias Pleroma.User
|
||||
alias Pleroma.Web.OStatus
|
||||
|
||||
def host_meta() do
|
||||
base_url = Pleroma.Web.base_url
|
||||
|
|
@ -30,7 +31,7 @@ defmodule Pleroma.Web.WebFinger do
|
|||
[
|
||||
{:Subject, "acct:#{user.nickname}@#{Pleroma.Web.host}"},
|
||||
{:Alias, user.ap_id},
|
||||
{:Link, %{rel: "http://schemas.google.com/g/2010#updates-from", type: "application/atom+xml", href: "#{user.ap_id}.atom"}}
|
||||
{:Link, %{rel: "http://schemas.google.com/g/2010#updates-from", type: "application/atom+xml", href: OStatus.feed_path(user)}}
|
||||
]
|
||||
}
|
||||
|> XmlBuilder.to_doc
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue