diff --git a/TODO.txt b/TODO.txt
index 304e95e77..3138d0848 100644
--- a/TODO.txt
+++ b/TODO.txt
@@ -5,5 +5,8 @@ Unliking:
WEBSUB:
- Add unsubscription
-- Add periodical renewal
+
+OSTATUS:
+
+- Save and output 'updated'
diff --git a/lib/pleroma/web/ostatus/activity_representer.ex b/lib/pleroma/web/ostatus/activity_representer.ex
index 85140282c..e91ff0769 100644
--- a/lib/pleroma/web/ostatus/activity_representer.ex
+++ b/lib/pleroma/web/ostatus/activity_representer.ex
@@ -28,10 +28,8 @@ def to_simple_form(activity, user, with_author \\ false)
def to_simple_form(%{data: %{"object" => %{"type" => "Note"}}} = activity, user, with_author) do
h = fn(str) -> [to_charlist(str)] end
- updated_at = activity.updated_at
- |> NaiveDateTime.to_iso8601
- inserted_at = activity.inserted_at
- |> NaiveDateTime.to_iso8601
+ updated_at = activity.data["published"]
+ inserted_at = activity.data["published"]
attachments = Enum.map(activity.data["object"]["attachment"] || [], fn(attachment) ->
url = hd(attachment["url"])
@@ -62,10 +60,8 @@ def to_simple_form(%{data: %{"object" => %{"type" => "Note"}}} = activity, user,
def to_simple_form(%{data: %{"type" => "Like"}} = activity, user, with_author) do
h = fn(str) -> [to_charlist(str)] end
- updated_at = activity.updated_at
- |> NaiveDateTime.to_iso8601
- inserted_at = activity.inserted_at
- |> NaiveDateTime.to_iso8601
+ updated_at = activity.data["published"]
+ inserted_at = activity.data["published"]
in_reply_to = get_in_reply_to(activity.data)
author = if with_author, do: [{:author, UserRepresenter.to_simple_form(user)}], else: []
@@ -92,10 +88,8 @@ def to_simple_form(%{data: %{"type" => "Like"}} = activity, user, with_author) d
def to_simple_form(%{data: %{"type" => "Announce"}} = activity, user, with_author) do
h = fn(str) -> [to_charlist(str)] end
- updated_at = activity.updated_at
- |> NaiveDateTime.to_iso8601
- inserted_at = activity.inserted_at
- |> NaiveDateTime.to_iso8601
+ updated_at = activity.data["published"]
+ inserted_at = activity.data["published"]
in_reply_to = get_in_reply_to(activity.data)
author = if with_author, do: [{:author, UserRepresenter.to_simple_form(user)}], else: []
@@ -124,10 +118,8 @@ def to_simple_form(%{data: %{"type" => "Announce"}} = activity, user, with_autho
def to_simple_form(%{data: %{"type" => "Follow"}} = activity, user, with_author) do
h = fn(str) -> [to_charlist(str)] end
- updated_at = activity.updated_at
- |> NaiveDateTime.to_iso8601
- inserted_at = activity.inserted_at
- |> NaiveDateTime.to_iso8601
+ updated_at = activity.data["published"]
+ inserted_at = activity.data["published"]
author = if with_author, do: [{:author, UserRepresenter.to_simple_form(user)}], else: []
@@ -153,10 +145,8 @@ def to_simple_form(%{data: %{"type" => "Follow"}} = activity, user, with_author)
def to_simple_form(%{data: %{"type" => "Undo"}} = activity, user, with_author) do
h = fn(str) -> [to_charlist(str)] end
- updated_at = activity.updated_at
- |> NaiveDateTime.to_iso8601
- inserted_at = activity.inserted_at
- |> NaiveDateTime.to_iso8601
+ updated_at = activity.data["published"]
+ inserted_at = activity.data["published"]
author = if with_author, do: [{:author, UserRepresenter.to_simple_form(user)}], else: []
follow_activity = Activity.get_by_ap_id(activity.data["object"])
diff --git a/lib/pleroma/web/ostatus/ostatus.ex b/lib/pleroma/web/ostatus/ostatus.ex
index f8bcf4718..df80d137a 100644
--- a/lib/pleroma/web/ostatus/ostatus.ex
+++ b/lib/pleroma/web/ostatus/ostatus.ex
@@ -152,16 +152,30 @@ def get_tags(entry) do
|> Enum.map(fn (category) -> string_from_xpath("/category/@term", category) end)
end
+ def maybe_update(doc, user) do
+ old_data = %{
+ avatar: user.avatar,
+ bio: user.bio,
+ name: user.name
+ }
+
+ with false <- user.local,
+ avatar <- make_avatar_object(doc),
+ bio when not is_nil(bio) <- string_from_xpath("//author[1]/summary", doc),
+ name when not is_nil(name) <- string_from_xpath("//author[1]/poco:displayName", doc),
+ new_data <- %{avatar: avatar, name: name, bio: bio},
+ false <- new_data == old_data do
+ change = Ecto.Changeset.change(user, new_data)
+ Repo.update(change)
+ else e ->
+ {:ok, user}
+ end
+ end
+
def find_make_or_update_user(doc) do
uri = string_from_xpath("//author/uri[1]", doc)
with {:ok, user} <- find_or_make_user(uri) do
- avatar = make_avatar_object(doc)
- if !user.local && user.avatar != avatar do
- change = Ecto.Changeset.change(user, %{avatar: avatar})
- Repo.update(change)
- else
- {:ok, user}
- end
+ maybe_update(doc, user)
end
end
@@ -185,7 +199,8 @@ def make_user(uri) do
nickname: info["nickname"] <> "@" <> info["host"],
ap_id: info["uri"],
info: info,
- avatar: info["avatar"]
+ avatar: info["avatar"],
+ bio: info["bio"]
}
with %User{} = user <- User.get_by_ap_id(data.ap_id) do
{:ok, user}
@@ -250,9 +265,9 @@ def get_atom_url(body) do
def fetch_activity_from_html_url(url) do
Logger.debug("Trying to fetch #{url}")
- with {:ok, %{body: body}} <- @httpoison.get(url, [], follow_redirect: true),
+ with {:ok, %{body: body}} <- @httpoison.get(url, [], follow_redirect: true, timeout: 10000, recv_timeout: 20000),
{:ok, atom_url} <- get_atom_url(body),
- {:ok, %{status_code: code, body: body}} when code in 200..299 <- @httpoison.get(atom_url, [], follow_redirect: true) do
+ {:ok, %{status_code: code, body: body}} when code in 200..299 <- @httpoison.get(atom_url, [], follow_redirect: true, timeout: 10000, recv_timeout: 20000) do
Logger.debug("Got document from #{url}, handling...")
handle_incoming(body)
else e -> Logger.debug("Couldn't get #{url}: #{inspect(e)}")
diff --git a/lib/pleroma/web/ostatus/ostatus_controller.ex b/lib/pleroma/web/ostatus/ostatus_controller.ex
index fd8dcdf52..948996d01 100644
--- a/lib/pleroma/web/ostatus/ostatus_controller.ex
+++ b/lib/pleroma/web/ostatus/ostatus_controller.ex
@@ -47,7 +47,10 @@ def object(conn, %{"uuid" => uuid}) do
with id <- o_status_url(conn, :object, uuid),
%Activity{} = activity <- Activity.get_create_activity_by_object_ap_id(id),
%User{} = user <- User.get_cached_by_ap_id(activity.data["actor"]) do
- represent_activity(conn, activity, user)
+ case get_format(conn) do
+ "html" -> redirect(conn, to: "/notice/#{activity.id}")
+ _ -> represent_activity(conn, activity, user)
+ end
end
end
@@ -55,7 +58,10 @@ def activity(conn, %{"uuid" => uuid}) do
with id <- o_status_url(conn, :activity, uuid),
%Activity{} = activity <- Activity.get_by_ap_id(id),
%User{} = user <- User.get_cached_by_ap_id(activity.data["actor"]) do
- represent_activity(conn, activity, user)
+ case get_format(conn) do
+ "html" -> redirect(conn, to: "/notice/#{activity.id}")
+ _ -> represent_activity(conn, activity, user)
+ end
end
end
diff --git a/lib/pleroma/web/router.ex b/lib/pleroma/web/router.ex
index 12159cffc..07c1f8028 100644
--- a/lib/pleroma/web/router.ex
+++ b/lib/pleroma/web/router.ex
@@ -70,7 +70,7 @@ def user_fetcher(username) do
end
pipeline :ostatus do
- plug :accepts, ["xml", "atom"]
+ plug :accepts, ["xml", "atom", "html"]
end
scope "/", Pleroma.Web do
@@ -97,7 +97,6 @@ def user_fetcher(username) do
scope "/", Fallback do
get "/*path", RedirectController, :redirector
end
-
end
defmodule Fallback.RedirectController do
diff --git a/lib/pleroma/web/twitter_api/utils.ex b/lib/pleroma/web/twitter_api/utils.ex
index 32b9eab44..65d893869 100644
--- a/lib/pleroma/web/twitter_api/utils.ex
+++ b/lib/pleroma/web/twitter_api/utils.ex
@@ -38,7 +38,8 @@ def add_user_links(text, mentions) do
end)
Enum.reduce(mentions, step_one, fn ({match, %User{ap_id: ap_id}, uuid}, text) ->
- String.replace(text, uuid, "#{match}")
+ short_match = String.split(match, "@") |> tl() |> hd()
+ String.replace(text, uuid, "@#{short_match}")
end)
end
diff --git a/lib/pleroma/web/websub/websub.ex b/lib/pleroma/web/websub/websub.ex
index e46e0a2ce..a683f6da4 100644
--- a/lib/pleroma/web/websub/websub.ex
+++ b/lib/pleroma/web/websub/websub.ex
@@ -156,6 +156,7 @@ def gather_feed_data(topic, getter \\ &@httpoison.get/1) do
preferredUsername = XML.string_from_xpath("/feed/author[1]/poco:preferredUsername", doc)
displayName = XML.string_from_xpath("/feed/author[1]/poco:displayName", doc)
avatar = OStatus.make_avatar_object(doc)
+ bio = XML.string_from_xpath("/feed/author[1]/summary", doc)
{:ok, %{
"uri" => uri,
@@ -163,7 +164,8 @@ def gather_feed_data(topic, getter \\ &@httpoison.get/1) do
"nickname" => preferredUsername || name,
"name" => displayName || name,
"host" => URI.parse(uri).host,
- "avatar" => avatar
+ "avatar" => avatar,
+ "bio" => bio
}}
else e ->
{:error, e}
diff --git a/priv/repo/migrations/20170529093232_longer_bios.exs b/priv/repo/migrations/20170529093232_longer_bios.exs
new file mode 100644
index 000000000..f8c14b117
--- /dev/null
+++ b/priv/repo/migrations/20170529093232_longer_bios.exs
@@ -0,0 +1,9 @@
+defmodule Pleroma.Repo.Migrations.LongerBios do
+ use Ecto.Migration
+
+ def change do
+ alter table(:users) do
+ modify :bio, :text
+ end
+ end
+end
diff --git a/test/fixtures/lambadalambda.atom b/test/fixtures/lambadalambda.atom
index 35e506420..964a416f7 100644
--- a/test/fixtures/lambadalambda.atom
+++ b/test/fixtures/lambadalambda.atom
@@ -11,7 +11,7 @@