From beb940a57e771b44b8a9b450efe46cd064f17e51 Mon Sep 17 00:00:00 2001
From: "Haelwenn (lanodan) Monnier"
Date: Tue, 26 Jun 2018 20:48:35 +0200
Subject: [PATCH 01/34] [Pleroma.Web.MastodonAPI.MastodonAPIController]: Add
rights to initial_state
Related to https://git.pleroma.social/pleroma/mastofe/issues/20
---
lib/pleroma/web/mastodon_api/mastodon_api_controller.ex | 3 +++
1 file changed, 3 insertions(+)
diff --git a/lib/pleroma/web/mastodon_api/mastodon_api_controller.ex b/lib/pleroma/web/mastodon_api/mastodon_api_controller.ex
index dab255ee2..9d3f526c9 100644
--- a/lib/pleroma/web/mastodon_api/mastodon_api_controller.ex
+++ b/lib/pleroma/web/mastodon_api/mastodon_api_controller.ex
@@ -868,6 +868,9 @@ defmodule Pleroma.Web.MastodonAPI.MastodonAPIController do
reduce_motion: false,
max_toot_chars: Keyword.get(@instance, :limit)
},
+ rights: %{
+ delete_others_notice: !!user.info["is_moderator"]
+ },
compose: %{
me: "#{user.id}",
default_privacy: "public",
From a2009432408dd0e93c3eb9506ff37da788b50895 Mon Sep 17 00:00:00 2001
From: William Pitcock
Date: Mon, 18 Jun 2018 05:23:54 +0000
Subject: [PATCH 02/34] object: add helper functions to handle various forms of
a given object and return a normalized one
---
lib/pleroma/object.ex | 4 ++++
1 file changed, 4 insertions(+)
diff --git a/lib/pleroma/object.ex b/lib/pleroma/object.ex
index ff2af4a6f..1bcff5a7b 100644
--- a/lib/pleroma/object.ex
+++ b/lib/pleroma/object.ex
@@ -27,6 +27,10 @@ defmodule Pleroma.Object do
Repo.one(from(object in Object, where: fragment("(?)->>'id' = ?", object.data, ^ap_id)))
end
+ def normalize(obj) when is_map(obj), do: Object.get_by_ap_id(obj["id"])
+ def normalize(ap_id) when is_binary(ap_id), do: Object.get_by_ap_id(ap_id)
+ def normalize(_), do: nil
+
def get_cached_by_ap_id(ap_id) do
if Mix.env() == :test do
get_by_ap_id(ap_id)
From b036a19c213c2b3cc08c64a0d887d36b9386609d Mon Sep 17 00:00:00 2001
From: William Pitcock
Date: Mon, 18 Jun 2018 20:54:59 +0000
Subject: [PATCH 03/34] activity: add normalize() to find a complete activity
given either URI or partial structure
---
lib/pleroma/activity.ex | 4 ++++
1 file changed, 4 insertions(+)
diff --git a/lib/pleroma/activity.ex b/lib/pleroma/activity.ex
index dd6805125..bed96861f 100644
--- a/lib/pleroma/activity.ex
+++ b/lib/pleroma/activity.ex
@@ -78,4 +78,8 @@ defmodule Pleroma.Activity do
end
def get_create_activity_by_object_ap_id(_), do: nil
+
+ def normalize(obj) when is_map(obj), do: Activity.get_by_ap_id(obj["id"])
+ def normalize(ap_id) when is_binary(ap_id), do: Activity.get_by_ap_id(ap_id)
+ def normalize(_), do: nil
end
From 47189531c55ac0c3f671298e6efa8c020ce5853a Mon Sep 17 00:00:00 2001
From: William Pitcock
Date: Mon, 18 Jun 2018 20:57:38 +0000
Subject: [PATCH 04/34] user: use Object.normalize() instead of
Object.get_by_ap_id() directly.
---
lib/pleroma/user.ex | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/lib/pleroma/user.ex b/lib/pleroma/user.ex
index 94f16c3c0..df22d29a8 100644
--- a/lib/pleroma/user.ex
+++ b/lib/pleroma/user.ex
@@ -607,7 +607,7 @@ defmodule Pleroma.User do
|> Enum.each(fn activity ->
case activity.data["type"] do
"Create" ->
- ActivityPub.delete(Object.get_by_ap_id(activity.data["object"]["id"]))
+ ActivityPub.delete(Object.normalize(activity.data["object"]))
# TODO: Do something with likes, follows, repeats.
_ ->
From fb04fecfb4791639369414a685be79bdd9d03309 Mon Sep 17 00:00:00 2001
From: William Pitcock
Date: Mon, 18 Jun 2018 20:58:09 +0000
Subject: [PATCH 05/34] streamer: use Object.normalize() instead of
Object.get_by_ap_id() directly.
---
lib/pleroma/web/streamer.ex | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/lib/pleroma/web/streamer.ex b/lib/pleroma/web/streamer.ex
index ce38f3cc3..c61bad830 100644
--- a/lib/pleroma/web/streamer.ex
+++ b/lib/pleroma/web/streamer.ex
@@ -158,7 +158,7 @@ defmodule Pleroma.Web.Streamer do
user = User.get_cached_by_ap_id(socket.assigns[:user].ap_id)
blocks = user.info["blocks"] || []
- parent = Object.get_by_ap_id(item.data["object"])
+ parent = Object.normalize(item.data["object"])
unless is_nil(parent) or item.actor in blocks or parent.data["actor"] in blocks do
send(socket.transport_pid, {:text, represent_update(item, user)})
From 15d624e07797719e9ec1cf112b8beaa08dad2562 Mon Sep 17 00:00:00 2001
From: William Pitcock
Date: Mon, 18 Jun 2018 21:01:33 +0000
Subject: [PATCH 06/34] activitypub: use Object.normalize() instead of
Object.get_by_ap_id() directly.
---
lib/pleroma/web/activity_pub/activity_pub.ex | 6 +++---
lib/pleroma/web/activity_pub/transmogrifier.ex | 2 +-
2 files changed, 4 insertions(+), 4 deletions(-)
diff --git a/lib/pleroma/web/activity_pub/activity_pub.ex b/lib/pleroma/web/activity_pub/activity_pub.ex
index 195679fad..93219d76a 100644
--- a/lib/pleroma/web/activity_pub/activity_pub.ex
+++ b/lib/pleroma/web/activity_pub/activity_pub.ex
@@ -670,7 +670,7 @@ defmodule Pleroma.Web.ActivityPub.ActivityPub do
recv_timeout: 20000
),
{:ok, data} <- Jason.decode(body),
- nil <- Object.get_by_ap_id(data["id"]),
+ nil <- Object.normalize(data),
params <- %{
"type" => "Create",
"to" => data["to"],
@@ -679,7 +679,7 @@ defmodule Pleroma.Web.ActivityPub.ActivityPub do
"object" => data
},
{:ok, activity} <- Transmogrifier.handle_incoming(params) do
- {:ok, Object.get_by_ap_id(activity.data["object"]["id"])}
+ {:ok, Object.normalize(activity.data["object"])}
else
object = %Object{} ->
{:ok, object}
@@ -688,7 +688,7 @@ defmodule Pleroma.Web.ActivityPub.ActivityPub do
Logger.info("Couldn't get object via AP, trying out OStatus fetching...")
case OStatus.fetch_activity_from_url(id) do
- {:ok, [activity | _]} -> {:ok, Object.get_by_ap_id(activity.data["object"]["id"])}
+ {:ok, [activity | _]} -> {:ok, Object.normalize(activity.data["object"])}
e -> e
end
end
diff --git a/lib/pleroma/web/activity_pub/transmogrifier.ex b/lib/pleroma/web/activity_pub/transmogrifier.ex
index 30cd70fb6..8b5c85f42 100644
--- a/lib/pleroma/web/activity_pub/transmogrifier.ex
+++ b/lib/pleroma/web/activity_pub/transmogrifier.ex
@@ -412,7 +412,7 @@ defmodule Pleroma.Web.ActivityPub.Transmogrifier do
def handle_incoming(_), do: :error
def get_obj_helper(id) do
- if object = Object.get_by_ap_id(id), do: {:ok, object}, else: nil
+ if object = Object.normalize(id), do: {:ok, object}, else: nil
end
def set_reply_to_uri(%{"inReplyTo" => inReplyTo} = object) do
From 49da04c5094e698dca4dbf5788127177702f288b Mon Sep 17 00:00:00 2001
From: William Pitcock
Date: Mon, 18 Jun 2018 21:08:12 +0000
Subject: [PATCH 07/34] common api: use Object.normalize() instead of
Object.get_by_ap_id() directly.
---
lib/pleroma/web/common_api/common_api.ex | 10 +++++-----
1 file changed, 5 insertions(+), 5 deletions(-)
diff --git a/lib/pleroma/web/common_api/common_api.ex b/lib/pleroma/web/common_api/common_api.ex
index 8845419c2..3f18a68e8 100644
--- a/lib/pleroma/web/common_api/common_api.ex
+++ b/lib/pleroma/web/common_api/common_api.ex
@@ -7,7 +7,7 @@ defmodule Pleroma.Web.CommonAPI do
def delete(activity_id, user) do
with %Activity{data: %{"object" => %{"id" => object_id}}} <- Repo.get(Activity, activity_id),
- %Object{} = object <- Object.get_by_ap_id(object_id),
+ %Object{} = object <- Object.normalize(object_id),
true <- user.info["is_moderator"] || user.ap_id == object.data["actor"],
{:ok, delete} <- ActivityPub.delete(object) do
{:ok, delete}
@@ -16,7 +16,7 @@ defmodule Pleroma.Web.CommonAPI do
def repeat(id_or_ap_id, user) do
with %Activity{} = activity <- get_by_id_or_ap_id(id_or_ap_id),
- object <- Object.get_by_ap_id(activity.data["object"]["id"]) do
+ object <- Object.normalize(activity.data["object"]["id"]) do
ActivityPub.announce(user, object)
else
_ ->
@@ -26,7 +26,7 @@ defmodule Pleroma.Web.CommonAPI do
def unrepeat(id_or_ap_id, user) do
with %Activity{} = activity <- get_by_id_or_ap_id(id_or_ap_id),
- object <- Object.get_by_ap_id(activity.data["object"]["id"]) do
+ object <- Object.normalize(activity.data["object"]["id"]) do
ActivityPub.unannounce(user, object)
else
_ ->
@@ -37,7 +37,7 @@ defmodule Pleroma.Web.CommonAPI do
def favorite(id_or_ap_id, user) do
with %Activity{} = activity <- get_by_id_or_ap_id(id_or_ap_id),
false <- activity.data["actor"] == user.ap_id,
- object <- Object.get_by_ap_id(activity.data["object"]["id"]) do
+ object <- Object.normalize(activity.data["object"]["id"]) do
ActivityPub.like(user, object)
else
_ ->
@@ -48,7 +48,7 @@ defmodule Pleroma.Web.CommonAPI do
def unfavorite(id_or_ap_id, user) do
with %Activity{} = activity <- get_by_id_or_ap_id(id_or_ap_id),
false <- activity.data["actor"] == user.ap_id,
- object <- Object.get_by_ap_id(activity.data["object"]["id"]) do
+ object <- Object.normalize(activity.data["object"]["id"]) do
ActivityPub.unlike(user, object)
else
_ ->
From bc05548370862a2a5daba20d4577b56fabc169ea Mon Sep 17 00:00:00 2001
From: William Pitcock
Date: Mon, 18 Jun 2018 21:08:37 +0000
Subject: [PATCH 08/34] ostatus: use Object.normalize() instead of
Object.get_by_ap_id() directly.
---
lib/pleroma/web/ostatus/handlers/delete_handler.ex | 2 +-
lib/pleroma/web/ostatus/ostatus.ex | 4 ++--
2 files changed, 3 insertions(+), 3 deletions(-)
diff --git a/lib/pleroma/web/ostatus/handlers/delete_handler.ex b/lib/pleroma/web/ostatus/handlers/delete_handler.ex
index 4f3016b65..6330d7f64 100644
--- a/lib/pleroma/web/ostatus/handlers/delete_handler.ex
+++ b/lib/pleroma/web/ostatus/handlers/delete_handler.ex
@@ -6,7 +6,7 @@ defmodule Pleroma.Web.OStatus.DeleteHandler do
def handle_delete(entry, _doc \\ nil) do
with id <- XML.string_from_xpath("//id", entry),
- object when not is_nil(object) <- Object.get_by_ap_id(id),
+ %Object{} = object <- Object.normalize(id),
{:ok, delete} <- ActivityPub.delete(object, false) do
delete
end
diff --git a/lib/pleroma/web/ostatus/ostatus.ex b/lib/pleroma/web/ostatus/ostatus.ex
index f0ff0624f..916c894eb 100644
--- a/lib/pleroma/web/ostatus/ostatus.ex
+++ b/lib/pleroma/web/ostatus/ostatus.ex
@@ -89,7 +89,7 @@ defmodule Pleroma.Web.OStatus do
def make_share(entry, doc, retweeted_activity) do
with {:ok, actor} <- find_make_or_update_user(doc),
- %Object{} = object <- Object.get_by_ap_id(retweeted_activity.data["object"]["id"]),
+ %Object{} = object <- Object.normalize(retweeted_activity.data["object"]),
id when not is_nil(id) <- string_from_xpath("/entry/id", entry),
{:ok, activity, _object} = ActivityPub.announce(actor, object, id, false) do
{:ok, activity}
@@ -107,7 +107,7 @@ defmodule Pleroma.Web.OStatus do
def make_favorite(entry, doc, favorited_activity) do
with {:ok, actor} <- find_make_or_update_user(doc),
- %Object{} = object <- Object.get_by_ap_id(favorited_activity.data["object"]["id"]),
+ %Object{} = object <- Object.normalize(favorited_activity.data["object"]),
id when not is_nil(id) <- string_from_xpath("/entry/id", entry),
{:ok, activity, _object} = ActivityPub.like(actor, object, id, false) do
{:ok, activity}
From 5b240c3b187260498cbebbd540872975fb30bafe Mon Sep 17 00:00:00 2001
From: William Pitcock
Date: Mon, 18 Jun 2018 21:20:18 +0000
Subject: [PATCH 09/34] federator: use Activity.normalize() instead of directly
using Activity.get_by_ap_id().
---
lib/pleroma/web/federator/federator.ex | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/lib/pleroma/web/federator/federator.ex b/lib/pleroma/web/federator/federator.ex
index 8ca530031..ccefb0bdf 100644
--- a/lib/pleroma/web/federator/federator.ex
+++ b/lib/pleroma/web/federator/federator.ex
@@ -95,7 +95,7 @@ defmodule Pleroma.Web.Federator do
params = Utils.normalize_params(params)
with {:ok, _user} <- ap_enabled_actor(params["actor"]),
- nil <- Activity.get_by_ap_id(params["id"]),
+ nil <- Activity.normalize(params["id"]),
{:ok, _activity} <- Transmogrifier.handle_incoming(params) do
else
%Activity{} ->
From 6f4ca7ddf7f70b219ef1223f6343707ff6910f90 Mon Sep 17 00:00:00 2001
From: William Pitcock
Date: Mon, 18 Jun 2018 21:20:44 +0000
Subject: [PATCH 10/34] ostatus: use Activity.normalize() instead of directly
using Activity.get_by_ap_id().
---
lib/pleroma/web/ostatus/activity_representer.ex | 2 +-
lib/pleroma/web/ostatus/ostatus_controller.ex | 2 +-
2 files changed, 2 insertions(+), 2 deletions(-)
diff --git a/lib/pleroma/web/ostatus/activity_representer.ex b/lib/pleroma/web/ostatus/activity_representer.ex
index 4179d86c9..5d831459b 100644
--- a/lib/pleroma/web/ostatus/activity_representer.ex
+++ b/lib/pleroma/web/ostatus/activity_representer.ex
@@ -246,7 +246,7 @@ defmodule Pleroma.Web.OStatus.ActivityRepresenter do
author = if with_author, do: [{:author, UserRepresenter.to_simple_form(user)}], else: []
mentions = (activity.recipients || []) |> get_mentions
- follow_activity = Activity.get_by_ap_id(follow_activity["id"])
+ follow_activity = Activity.normalize(follow_activity)
[
{:"activity:object-type", ['http://activitystrea.ms/schema/1.0/activity']},
diff --git a/lib/pleroma/web/ostatus/ostatus_controller.ex b/lib/pleroma/web/ostatus/ostatus_controller.ex
index 2f72fdb16..00bffbd5d 100644
--- a/lib/pleroma/web/ostatus/ostatus_controller.ex
+++ b/lib/pleroma/web/ostatus/ostatus_controller.ex
@@ -107,7 +107,7 @@ defmodule Pleroma.Web.OStatus.OStatusController do
def activity(conn, %{"uuid" => uuid}) do
with id <- o_status_url(conn, :activity, uuid),
- {_, %Activity{} = activity} <- {:activity, Activity.get_by_ap_id(id)},
+ {_, %Activity{} = activity} <- {:activity, Activity.normalize(id)},
{_, true} <- {:public?, ActivityPub.is_public?(activity)},
%User{} = user <- User.get_cached_by_ap_id(activity.data["actor"]) do
case get_format(conn) do
From 7c63e70de1b92ab8119732fe92040dea7f545b3d Mon Sep 17 00:00:00 2001
From: William Pitcock
Date: Mon, 18 Jun 2018 21:21:03 +0000
Subject: [PATCH 11/34] activitypub: use Activity.normalize() in several places
instead of using Activity.get_by_ap_id() directly.
---
lib/pleroma/web/activity_pub/activity_pub.ex | 2 +-
lib/pleroma/web/activity_pub/transmogrifier.ex | 18 ++----------------
2 files changed, 3 insertions(+), 17 deletions(-)
diff --git a/lib/pleroma/web/activity_pub/activity_pub.ex b/lib/pleroma/web/activity_pub/activity_pub.ex
index 93219d76a..464832a1e 100644
--- a/lib/pleroma/web/activity_pub/activity_pub.ex
+++ b/lib/pleroma/web/activity_pub/activity_pub.ex
@@ -30,7 +30,7 @@ defmodule Pleroma.Web.ActivityPub.ActivityPub do
end
def insert(map, local \\ true) when is_map(map) do
- with nil <- Activity.get_by_ap_id(map["id"]),
+ with nil <- Activity.normalize(map),
map <- lazy_put_activity_defaults(map),
:ok <- check_actor_is_active(map["actor"]),
{:ok, map} <- MRF.filter(map),
diff --git a/lib/pleroma/web/activity_pub/transmogrifier.ex b/lib/pleroma/web/activity_pub/transmogrifier.ex
index 8b5c85f42..9d7c64743 100644
--- a/lib/pleroma/web/activity_pub/transmogrifier.ex
+++ b/lib/pleroma/web/activity_pub/transmogrifier.ex
@@ -460,14 +460,7 @@ defmodule Pleroma.Web.ActivityPub.Transmogrifier do
# Mastodon Accept/Reject requires a non-normalized object containing the actor URIs,
# because of course it does.
def prepare_outgoing(%{"type" => "Accept"} = data) do
- follow_activity_id =
- if is_binary(data["object"]) do
- data["object"]
- else
- data["object"]["id"]
- end
-
- with follow_activity <- Activity.get_by_ap_id(follow_activity_id) do
+ with follow_activity <- Activity.normalize(data["object"]) do
object = %{
"actor" => follow_activity.actor,
"object" => follow_activity.data["object"],
@@ -485,14 +478,7 @@ defmodule Pleroma.Web.ActivityPub.Transmogrifier do
end
def prepare_outgoing(%{"type" => "Reject"} = data) do
- follow_activity_id =
- if is_binary(data["object"]) do
- data["object"]
- else
- data["object"]["id"]
- end
-
- with follow_activity <- Activity.get_by_ap_id(follow_activity_id) do
+ with follow_activity <- Activity.normalize(data["object"]) do
object = %{
"actor" => follow_activity.actor,
"object" => follow_activity.data["object"],
From 4f6de34f4f40d408fb9200a5c4c908aec3ed9e91 Mon Sep 17 00:00:00 2001
From: William Pitcock
Date: Sat, 23 Jun 2018 06:53:29 +0000
Subject: [PATCH 12/34] mastodon api: use info["default_scope"] if available
for post scope
---
lib/pleroma/web/mastodon_api/mastodon_api_controller.ex | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/lib/pleroma/web/mastodon_api/mastodon_api_controller.ex b/lib/pleroma/web/mastodon_api/mastodon_api_controller.ex
index 9d3f526c9..09e6b0b59 100644
--- a/lib/pleroma/web/mastodon_api/mastodon_api_controller.ex
+++ b/lib/pleroma/web/mastodon_api/mastodon_api_controller.ex
@@ -873,7 +873,7 @@ defmodule Pleroma.Web.MastodonAPI.MastodonAPIController do
},
compose: %{
me: "#{user.id}",
- default_privacy: "public",
+ default_privacy: user.info["default_scope"] || "public",
default_sensitive: false
},
media_attachments: %{
From dcdf7b6686fe3732ac8f9a93570dfa8a1412783a Mon Sep 17 00:00:00 2001
From: William Pitcock
Date: Sat, 23 Jun 2018 06:55:32 +0000
Subject: [PATCH 13/34] twitter api: user view: show default message scope if
known
---
lib/pleroma/web/twitter_api/views/user_view.ex | 3 ++-
1 file changed, 2 insertions(+), 1 deletion(-)
diff --git a/lib/pleroma/web/twitter_api/views/user_view.ex b/lib/pleroma/web/twitter_api/views/user_view.ex
index 711008973..9c8460378 100644
--- a/lib/pleroma/web/twitter_api/views/user_view.ex
+++ b/lib/pleroma/web/twitter_api/views/user_view.ex
@@ -52,7 +52,8 @@ defmodule Pleroma.Web.TwitterAPI.UserView do
"cover_photo" => User.banner_url(user) |> MediaProxy.url(),
"background_image" => image_url(user.info["background"]) |> MediaProxy.url(),
"is_local" => user.local,
- "locked" => !!user.info["locked"]
+ "locked" => !!user.info["locked"],
+ "default_scope" => user.info["default_scope"] || "public"
}
if assigns[:token] do
From 2f14996d9afedbc4dbd75a518cf191636f926f74 Mon Sep 17 00:00:00 2001
From: William Pitcock
Date: Sat, 23 Jun 2018 07:02:49 +0000
Subject: [PATCH 14/34] twitter api: allow setting default_scope
---
lib/pleroma/web/twitter_api/twitter_api_controller.ex | 13 +++++++++++++
1 file changed, 13 insertions(+)
diff --git a/lib/pleroma/web/twitter_api/twitter_api_controller.ex b/lib/pleroma/web/twitter_api/twitter_api_controller.ex
index 8f5b3c786..65e67396b 100644
--- a/lib/pleroma/web/twitter_api/twitter_api_controller.ex
+++ b/lib/pleroma/web/twitter_api/twitter_api_controller.ex
@@ -431,6 +431,19 @@ defmodule Pleroma.Web.TwitterAPI.Controller do
user
end
+ user =
+ if default_scope = params["default_scope"] do
+ with new_info <- Map.put(user.info, "default_scope", default_scope),
+ change <- User.info_changeset(user, %{info: new_info}),
+ {:ok, user} <- User.update_and_set_cache(change) do
+ user
+ else
+ _e -> user
+ end
+ else
+ user
+ end
+
with changeset <- User.update_changeset(user, params),
{:ok, user} <- User.update_and_set_cache(changeset) do
CommonAPI.update(user)
From 32211c4ada3ea113fb4041ae28b884130b2f4342 Mon Sep 17 00:00:00 2001
From: William Pitcock
Date: Sun, 24 Jun 2018 06:31:09 +0000
Subject: [PATCH 15/34] tests: add default_scope where appropriate
---
test/web/twitter_api/views/user_view_test.exs | 12 ++++++++----
1 file changed, 8 insertions(+), 4 deletions(-)
diff --git a/test/web/twitter_api/views/user_view_test.exs b/test/web/twitter_api/views/user_view_test.exs
index eea743b32..49f73c2fe 100644
--- a/test/web/twitter_api/views/user_view_test.exs
+++ b/test/web/twitter_api/views/user_view_test.exs
@@ -60,7 +60,8 @@ defmodule Pleroma.Web.TwitterAPI.UserViewTest do
"cover_photo" => banner,
"background_image" => nil,
"is_local" => true,
- "locked" => false
+ "locked" => false,
+ "default_scope" => "public"
}
assert represented == UserView.render("show.json", %{user: user})
@@ -96,7 +97,8 @@ defmodule Pleroma.Web.TwitterAPI.UserViewTest do
"cover_photo" => banner,
"background_image" => nil,
"is_local" => true,
- "locked" => false
+ "locked" => false,
+ "default_scope" => "public"
}
assert represented == UserView.render("show.json", %{user: user, for: follower})
@@ -133,7 +135,8 @@ defmodule Pleroma.Web.TwitterAPI.UserViewTest do
"cover_photo" => banner,
"background_image" => nil,
"is_local" => true,
- "locked" => false
+ "locked" => false,
+ "default_scope" => "public"
}
assert represented == UserView.render("show.json", %{user: follower, for: user})
@@ -177,7 +180,8 @@ defmodule Pleroma.Web.TwitterAPI.UserViewTest do
"cover_photo" => banner,
"background_image" => nil,
"is_local" => true,
- "locked" => false
+ "locked" => false,
+ "default_scope" => "public"
}
blocker = Repo.get(User, blocker.id)
From c42f28b82c01423d05b85514797bf3bce692628d Mon Sep 17 00:00:00 2001
From: William Pitcock
Date: Sun, 24 Jun 2018 05:33:22 +0000
Subject: [PATCH 16/34] transmogrifier: accept Article activities
---
lib/pleroma/web/activity_pub/transmogrifier.ex | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/lib/pleroma/web/activity_pub/transmogrifier.ex b/lib/pleroma/web/activity_pub/transmogrifier.ex
index 30cd70fb6..1b60170d9 100644
--- a/lib/pleroma/web/activity_pub/transmogrifier.ex
+++ b/lib/pleroma/web/activity_pub/transmogrifier.ex
@@ -122,7 +122,7 @@ defmodule Pleroma.Web.ActivityPub.Transmogrifier do
# TODO: validate those with a Ecto scheme
# - tags
# - emoji
- def handle_incoming(%{"type" => "Create", "object" => %{"type" => "Note"} = object} = data) do
+ def handle_incoming(%{"type" => "Create", "object" => %{"type" => objtype} = object} = data) when objtype in ["Article", "Note"] do
with nil <- Activity.get_create_activity_by_object_ap_id(object["id"]),
%User{} = user <- User.get_or_fetch_by_ap_id(data["actor"]) do
object = fix_object(data["object"])
From bd479606ba2b645db46ef5312f06323534cfd9c9 Mon Sep 17 00:00:00 2001
From: William Pitcock
Date: Sun, 24 Jun 2018 06:52:17 +0000
Subject: [PATCH 17/34] utils: make_create_data: add support for Article
objects
---
lib/pleroma/web/activity_pub/utils.ex | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/lib/pleroma/web/activity_pub/utils.ex b/lib/pleroma/web/activity_pub/utils.ex
index 64329b710..8b41a3bec 100644
--- a/lib/pleroma/web/activity_pub/utils.ex
+++ b/lib/pleroma/web/activity_pub/utils.ex
@@ -128,7 +128,7 @@ defmodule Pleroma.Web.ActivityPub.Utils do
Inserts a full object if it is contained in an activity.
"""
def insert_full_object(%{"object" => %{"type" => type} = object_data})
- when is_map(object_data) and type in ["Note"] do
+ when is_map(object_data) and type in ["Article", "Note"] do
with {:ok, _} <- Object.create(object_data) do
:ok
end
From 121c1f62306e416f1f6106d1751b55a5eb9f9075 Mon Sep 17 00:00:00 2001
From: William Pitcock
Date: Sun, 24 Jun 2018 05:33:34 +0000
Subject: [PATCH 18/34] twitter api: refactor activity html generation, add
support for Articles
---
lib/pleroma/web/twitter_api/views/activity_view.ex | 41 +++++++++++++++++-----
1 file changed, 32 insertions(+), 9 deletions(-)
diff --git a/lib/pleroma/web/twitter_api/views/activity_view.ex b/lib/pleroma/web/twitter_api/views/activity_view.ex
index 62ce3b7b5..0779872fe 100644
--- a/lib/pleroma/web/twitter_api/views/activity_view.ex
+++ b/lib/pleroma/web/twitter_api/views/activity_view.ex
@@ -228,15 +228,7 @@ defmodule Pleroma.Web.TwitterAPI.ActivityView do
tags = if possibly_sensitive, do: Enum.uniq(["nsfw" | tags]), else: tags
- summary = activity.data["object"]["summary"]
- content = object["content"]
-
- content =
- if !!summary and summary != "" do
- "#{activity.data["object"]["summary"]}
#{content}"
- else
- content
- end
+ {summary, content} = render_content(object)
html =
HtmlSanitizeEx.basic_html(content)
@@ -266,4 +258,35 @@ defmodule Pleroma.Web.TwitterAPI.ActivityView do
"visibility" => Pleroma.Web.MastodonAPI.StatusView.get_visibility(object)
}
end
+
+ def render_content(%{"type" => "Note"} = object) do
+ summary = object["summary"]
+ content =
+ if !!summary and summary != "" do
+ "#{summary}
#{object["content"]}"
+ else
+ object["content"]
+ end
+
+ {summary, content}
+ end
+
+ def render_content(%{"type" => "Article"} = object) do
+ summary = object["name"] || object["summary"]
+ content =
+ if !!summary and summary != "" do
+ "#{summary}
#{object["content"]}"
+ else
+ object["content"]
+ end
+
+ {summary, content}
+ end
+
+ def render_content(object) do
+ summary = object["summary"] || "Unhandled activity type: #{object["type"]}"
+ content = "#{summary}
#{object["content"]}"
+
+ {summary, content}
+ end
end
From ea982e7503767f645dc26235e04c541ce976de71 Mon Sep 17 00:00:00 2001
From: William Pitcock
Date: Sun, 24 Jun 2018 06:14:17 +0000
Subject: [PATCH 19/34] mastodon api: add interpreter for Article activity
types
---
lib/pleroma/web/mastodon_api/views/status_view.ex | 18 +++++++++++++++++-
1 file changed, 17 insertions(+), 1 deletion(-)
diff --git a/lib/pleroma/web/mastodon_api/views/status_view.ex b/lib/pleroma/web/mastodon_api/views/status_view.ex
index 59898457b..f7ad87bad 100644
--- a/lib/pleroma/web/mastodon_api/views/status_view.ex
+++ b/lib/pleroma/web/mastodon_api/views/status_view.ex
@@ -128,7 +128,7 @@ defmodule Pleroma.Web.MastodonAPI.StatusView do
in_reply_to_id: reply_to && to_string(reply_to.id),
in_reply_to_account_id: reply_to_user && to_string(reply_to_user.id),
reblog: nil,
- content: HtmlSanitizeEx.basic_html(object["content"]),
+ content: render_content(object),
created_at: created_at,
reblogs_count: announcement_count,
favourites_count: like_count,
@@ -207,4 +207,20 @@ defmodule Pleroma.Web.MastodonAPI.StatusView do
"direct"
end
end
+
+ def render_content(%{"type" => "Article"} = object) do
+ summary = object["name"]
+ content =
+ if !!summary and summary != "" do
+ "#{summary}
#{object["content"]}"
+ else
+ object["content"]
+ end
+
+ HtmlSanitizeEx.basic_html(content)
+ end
+
+ def render_content(object) do
+ HtmlSanitizeEx.basic_html(object["content"])
+ end
end
From 66819ea784509fbed3f7db8056ececf150339b35 Mon Sep 17 00:00:00 2001
From: William Pitcock
Date: Sun, 24 Jun 2018 06:30:23 +0000
Subject: [PATCH 20/34] twitter api: use ActivityView.render_content() where
appropriate instead of duplicating the logic
---
.../web/twitter_api/representers/activity_representer.ex | 11 ++---------
.../twitter_api/representers/activity_representer_test.exs | 2 +-
2 files changed, 3 insertions(+), 10 deletions(-)
diff --git a/lib/pleroma/web/twitter_api/representers/activity_representer.ex b/lib/pleroma/web/twitter_api/representers/activity_representer.ex
index 57837205e..bb77e61f3 100644
--- a/lib/pleroma/web/twitter_api/representers/activity_representer.ex
+++ b/lib/pleroma/web/twitter_api/representers/activity_representer.ex
@@ -4,7 +4,7 @@ defmodule Pleroma.Web.TwitterAPI.Representers.ActivityRepresenter do
use Pleroma.Web.TwitterAPI.Representers.BaseRepresenter
alias Pleroma.Web.TwitterAPI.Representers.ObjectRepresenter
alias Pleroma.{Activity, User}
- alias Pleroma.Web.TwitterAPI.{TwitterAPI, UserView}
+ alias Pleroma.Web.TwitterAPI.{TwitterAPI, UserView, ActivityView}
alias Pleroma.Web.CommonAPI.Utils
alias Pleroma.Formatter
@@ -164,14 +164,7 @@ defmodule Pleroma.Web.TwitterAPI.Representers.ActivityRepresenter do
tags = if possibly_sensitive, do: Enum.uniq(["nsfw" | tags]), else: tags
- summary = activity.data["object"]["summary"]
-
- content =
- if !!summary and summary != "" do
- "#{activity.data["object"]["summary"]}
#{content}"
- else
- content
- end
+ {summary, content} = ActivityView.render_content(object)
html =
HtmlSanitizeEx.basic_html(content)
diff --git a/test/web/twitter_api/representers/activity_representer_test.exs b/test/web/twitter_api/representers/activity_representer_test.exs
index 16c6e7b0d..7505093dd 100644
--- a/test/web/twitter_api/representers/activity_representer_test.exs
+++ b/test/web/twitter_api/representers/activity_representer_test.exs
@@ -126,7 +126,7 @@ defmodule Pleroma.Web.TwitterAPI.Representers.ActivityRepresenterTest do
}
expected_html =
- "2hu
alert('YAY')Some content mentioning 2hu
alert('YAY')Some content mentioning @shp"
From 971bb4f2bde125c1f8397c244a6fbdec0d26716b Mon Sep 17 00:00:00 2001
From: William Pitcock
Date: Sun, 24 Jun 2018 06:34:44 +0000
Subject: [PATCH 21/34] activity interpretation: formatting
---
lib/pleroma/web/activity_pub/transmogrifier.ex | 3 ++-
lib/pleroma/web/mastodon_api/views/status_view.ex | 1 +
lib/pleroma/web/twitter_api/views/activity_view.ex | 2 ++
3 files changed, 5 insertions(+), 1 deletion(-)
diff --git a/lib/pleroma/web/activity_pub/transmogrifier.ex b/lib/pleroma/web/activity_pub/transmogrifier.ex
index 1b60170d9..59c4b90e7 100644
--- a/lib/pleroma/web/activity_pub/transmogrifier.ex
+++ b/lib/pleroma/web/activity_pub/transmogrifier.ex
@@ -122,7 +122,8 @@ defmodule Pleroma.Web.ActivityPub.Transmogrifier do
# TODO: validate those with a Ecto scheme
# - tags
# - emoji
- def handle_incoming(%{"type" => "Create", "object" => %{"type" => objtype} = object} = data) when objtype in ["Article", "Note"] do
+ def handle_incoming(%{"type" => "Create", "object" => %{"type" => objtype} = object} = data)
+ when objtype in ["Article", "Note"] do
with nil <- Activity.get_create_activity_by_object_ap_id(object["id"]),
%User{} = user <- User.get_or_fetch_by_ap_id(data["actor"]) do
object = fix_object(data["object"])
diff --git a/lib/pleroma/web/mastodon_api/views/status_view.ex b/lib/pleroma/web/mastodon_api/views/status_view.ex
index f7ad87bad..6b48c41c1 100644
--- a/lib/pleroma/web/mastodon_api/views/status_view.ex
+++ b/lib/pleroma/web/mastodon_api/views/status_view.ex
@@ -210,6 +210,7 @@ defmodule Pleroma.Web.MastodonAPI.StatusView do
def render_content(%{"type" => "Article"} = object) do
summary = object["name"]
+
content =
if !!summary and summary != "" do
"#{summary}
#{object["content"]}"
diff --git a/lib/pleroma/web/twitter_api/views/activity_view.ex b/lib/pleroma/web/twitter_api/views/activity_view.ex
index 0779872fe..f418249e2 100644
--- a/lib/pleroma/web/twitter_api/views/activity_view.ex
+++ b/lib/pleroma/web/twitter_api/views/activity_view.ex
@@ -261,6 +261,7 @@ defmodule Pleroma.Web.TwitterAPI.ActivityView do
def render_content(%{"type" => "Note"} = object) do
summary = object["summary"]
+
content =
if !!summary and summary != "" do
"#{summary}
#{object["content"]}"
@@ -273,6 +274,7 @@ defmodule Pleroma.Web.TwitterAPI.ActivityView do
def render_content(%{"type" => "Article"} = object) do
summary = object["name"] || object["summary"]
+
content =
if !!summary and summary != "" do
"#{summary}
#{object["content"]}"
From 0bfbf15b379a95e7fad50e8f611cf6c5e67cfa9c Mon Sep 17 00:00:00 2001
From: Jorty
Date: Sat, 30 Jun 2018 15:08:31 -0400
Subject: [PATCH 22/34] Allow emojis to be added automatically
---
.../web/twitter_api/controllers/util_controller.ex | 20 +++++++++++++++++++-
1 file changed, 19 insertions(+), 1 deletion(-)
diff --git a/lib/pleroma/web/twitter_api/controllers/util_controller.ex b/lib/pleroma/web/twitter_api/controllers/util_controller.ex
index 7a0c37ce9..db6142dc8 100644
--- a/lib/pleroma/web/twitter_api/controllers/util_controller.ex
+++ b/lib/pleroma/web/twitter_api/controllers/util_controller.ex
@@ -173,7 +173,25 @@ defmodule Pleroma.Web.TwitterAPI.UtilController do
end
def emoji(conn, _params) do
- json(conn, Enum.into(Formatter.get_custom_emoji(), %{}))
+ emoji_dir = Path.join(:code.priv_dir(:pleroma), "static/emoji")
+
+ shortcode_emoji_glob =
+ Path.join(
+ emoji_dir,
+ Application.get_env(:pleroma, :emoji, []) |>
+ Keyword.get(:glob, "by-shortcode/**/*.png")
+ )
+ shortcode_emoji =
+ Path.wildcard(shortcode_emoji_glob) |>
+ Enum.map(fn path ->
+ shortcode = Path.basename(path, ".png")
+ serve_path = Path.join("/emoji", Path.relative_to(path, emoji_dir))
+ {shortcode, serve_path}
+ end)
+
+ emoji = Enum.into(Formatter.get_custom_emoji(), shortcode_emoji) |> Enum.into(%{})
+
+ json(conn, emoji)
end
def follow_import(conn, %{"list" => %Plug.Upload{} = listfile}) do
From c171f9790bc2d6a1b215792ade1b1cfc7e458ac4 Mon Sep 17 00:00:00 2001
From: Jorty
Date: Sat, 30 Jun 2018 17:20:08 -0400
Subject: [PATCH 23/34] Move emoji glob setting to config.exs
Also, a bit of formatting, and the glob includes an "/emoji/" prefix to
make it more intuitive to users
---
config/config.exs | 2 ++
.../web/twitter_api/controllers/util_controller.ex | 35 +++++++++++++---------
2 files changed, 23 insertions(+), 14 deletions(-)
diff --git a/config/config.exs b/config/config.exs
index cf6cbaa9d..96350d064 100644
--- a/config/config.exs
+++ b/config/config.exs
@@ -12,6 +12,8 @@ config :pleroma, Pleroma.Repo, types: Pleroma.PostgresTypes
config :pleroma, Pleroma.Upload, uploads: "uploads"
+config :pleroma, :emoji, shortcode_glob: "/emoji/by-shortcode/**/*.png"
+
# Configures the endpoint
config :pleroma, Pleroma.Web.Endpoint,
url: [host: "localhost"],
diff --git a/lib/pleroma/web/twitter_api/controllers/util_controller.ex b/lib/pleroma/web/twitter_api/controllers/util_controller.ex
index db6142dc8..73a46bb5e 100644
--- a/lib/pleroma/web/twitter_api/controllers/util_controller.ex
+++ b/lib/pleroma/web/twitter_api/controllers/util_controller.ex
@@ -173,23 +173,30 @@ defmodule Pleroma.Web.TwitterAPI.UtilController do
end
def emoji(conn, _params) do
- emoji_dir = Path.join(:code.priv_dir(:pleroma), "static/emoji")
+ static_dir = Path.join(:code.priv_dir(:pleroma), "static")
+
+ emoji_shortcode_glob =
+ Application.get_env(:pleroma, :emoji, [])
+ |> Keyword.get(:shortcode_glob)
- shortcode_emoji_glob =
- Path.join(
- emoji_dir,
- Application.get_env(:pleroma, :emoji, []) |>
- Keyword.get(:glob, "by-shortcode/**/*.png")
- )
shortcode_emoji =
- Path.wildcard(shortcode_emoji_glob) |>
- Enum.map(fn path ->
- shortcode = Path.basename(path, ".png")
- serve_path = Path.join("/emoji", Path.relative_to(path, emoji_dir))
- {shortcode, serve_path}
- end)
+ case emoji_shortcode_glob do
+ nil ->
+ []
- emoji = Enum.into(Formatter.get_custom_emoji(), shortcode_emoji) |> Enum.into(%{})
+ glob ->
+ Path.join(static_dir, glob)
+ |> Path.wildcard()
+ |> Enum.map(fn path ->
+ shortcode = Path.basename(path, ".png")
+ serve_path = Path.join("/", Path.relative_to(path, static_dir))
+ {shortcode, serve_path}
+ end)
+ end
+
+ emoji =
+ Enum.into(Formatter.get_custom_emoji(), shortcode_emoji)
+ |> Enum.into(%{})
json(conn, emoji)
end
From 748fff6544cc70476bb0892a661d4d8c7f6ee295 Mon Sep 17 00:00:00 2001
From: Jorty
Date: Sat, 30 Jun 2018 20:35:34 -0400
Subject: [PATCH 24/34] Fix auto-shortcode emoji
Emoji were broken due to `Pleroma.Formatter` not knowing about the
auto-shortcode emoji. This moves that logic from
`Pleroma.Web.TwitterAPI.UtilController` to `Pleroma.Formatter`.
Additionally, it's now possible to specify multiple shortcode globs, and
the default globs were changed to `["/emoji/custom/**/*.png"]`, since
that's in the .gitignore and the files there would have to be shortcode
emoji anyway.
---
config/config.exs | 2 +-
lib/pleroma/formatter.ex | 23 +++++++++++++++++-
.../web/twitter_api/controllers/util_controller.ex | 27 +---------------------
3 files changed, 24 insertions(+), 28 deletions(-)
diff --git a/config/config.exs b/config/config.exs
index 96350d064..0616fe4fb 100644
--- a/config/config.exs
+++ b/config/config.exs
@@ -12,7 +12,7 @@ config :pleroma, Pleroma.Repo, types: Pleroma.PostgresTypes
config :pleroma, Pleroma.Upload, uploads: "uploads"
-config :pleroma, :emoji, shortcode_glob: "/emoji/by-shortcode/**/*.png"
+config :pleroma, :emoji, shortcode_globs: ["/emoji/custom/**/*.png"]
# Configures the endpoint
config :pleroma, Pleroma.Web.Endpoint,
diff --git a/lib/pleroma/formatter.ex b/lib/pleroma/formatter.ex
index df7ffbc41..0aaf21538 100644
--- a/lib/pleroma/formatter.ex
+++ b/lib/pleroma/formatter.ex
@@ -116,7 +116,28 @@ defmodule Pleroma.Formatter do
_ -> []
end)
- @emoji @finmoji_with_filenames ++ @emoji_from_file
+ @emoji_from_globs (
+ static_path = Path.join(:code.priv_dir(:pleroma), "static")
+
+ globs =
+ Application.get_env(:pleroma, :emoji, [])
+ |> Keyword.get(:shortcode_globs, [])
+
+ paths =
+ Enum.map(globs, fn glob ->
+ Path.join(static_path, glob)
+ |> Path.wildcard()
+ end)
+ |> Enum.concat()
+
+ Enum.map(paths, fn path ->
+ shortcode = Path.basename(path, Path.extname(path))
+ external_path = Path.join("/", Path.relative_to(path, static_path))
+ {shortcode, external_path}
+ end)
+ )
+
+ @emoji @finmoji_with_filenames ++ @emoji_from_globs ++ @emoji_from_file
def emojify(text, emoji \\ @emoji)
def emojify(text, nil), do: text
diff --git a/lib/pleroma/web/twitter_api/controllers/util_controller.ex b/lib/pleroma/web/twitter_api/controllers/util_controller.ex
index 73a46bb5e..7a0c37ce9 100644
--- a/lib/pleroma/web/twitter_api/controllers/util_controller.ex
+++ b/lib/pleroma/web/twitter_api/controllers/util_controller.ex
@@ -173,32 +173,7 @@ defmodule Pleroma.Web.TwitterAPI.UtilController do
end
def emoji(conn, _params) do
- static_dir = Path.join(:code.priv_dir(:pleroma), "static")
-
- emoji_shortcode_glob =
- Application.get_env(:pleroma, :emoji, [])
- |> Keyword.get(:shortcode_glob)
-
- shortcode_emoji =
- case emoji_shortcode_glob do
- nil ->
- []
-
- glob ->
- Path.join(static_dir, glob)
- |> Path.wildcard()
- |> Enum.map(fn path ->
- shortcode = Path.basename(path, ".png")
- serve_path = Path.join("/", Path.relative_to(path, static_dir))
- {shortcode, serve_path}
- end)
- end
-
- emoji =
- Enum.into(Formatter.get_custom_emoji(), shortcode_emoji)
- |> Enum.into(%{})
-
- json(conn, emoji)
+ json(conn, Enum.into(Formatter.get_custom_emoji(), %{}))
end
def follow_import(conn, %{"list" => %Plug.Upload{} = listfile}) do
From 7a351cb36f64ae98fa3d28d5133fa0a49d376659 Mon Sep 17 00:00:00 2001
From: "Haelwenn (lanodan) Monnier"
Date: Mon, 2 Jul 2018 06:28:21 +0200
Subject: [PATCH 25/34] [Pleroma.Web.MastodonAPI.StatusView]: Fill the url
field for statuses
Closes: https://git.pleroma.social/pleroma/pleroma/issues/231
---
lib/pleroma/web/mastodon_api/views/status_view.ex | 3 +--
1 file changed, 1 insertion(+), 2 deletions(-)
diff --git a/lib/pleroma/web/mastodon_api/views/status_view.ex b/lib/pleroma/web/mastodon_api/views/status_view.ex
index 59898457b..39abb4c6b 100644
--- a/lib/pleroma/web/mastodon_api/views/status_view.ex
+++ b/lib/pleroma/web/mastodon_api/views/status_view.ex
@@ -54,8 +54,7 @@ defmodule Pleroma.Web.MastodonAPI.StatusView do
%{
id: to_string(activity.id),
uri: object,
- # TODO: This might be wrong, check with mastodon.
- url: nil,
+ url: object,
account: AccountView.render("account.json", %{user: user}),
in_reply_to_id: nil,
in_reply_to_account_id: nil,
From 4326cb992019f0a050cde3775a4d36219750dbbc Mon Sep 17 00:00:00 2001
From: "Haelwenn (lanodan) Monnier"
Date: Tue, 26 Jun 2018 13:51:35 +0200
Subject: [PATCH 26/34] [Pleroma.Web.Nodeinfo.NodeinfoController]: add
mediaProxy metadata
Closes: https://git.pleroma.social/pleroma/pleroma/issues/229
---
lib/pleroma/web/nodeinfo/nodeinfo_controller.ex | 7 ++++---
1 file changed, 4 insertions(+), 3 deletions(-)
diff --git a/lib/pleroma/web/nodeinfo/nodeinfo_controller.ex b/lib/pleroma/web/nodeinfo/nodeinfo_controller.ex
index aec77168a..e7e2794ae 100644
--- a/lib/pleroma/web/nodeinfo/nodeinfo_controller.ex
+++ b/lib/pleroma/web/nodeinfo/nodeinfo_controller.ex
@@ -4,8 +4,6 @@ defmodule Pleroma.Web.Nodeinfo.NodeinfoController do
alias Pleroma.Stats
alias Pleroma.Web
- @instance Application.get_env(:pleroma, :instance)
-
def schemas(conn, _params) do
response = %{
links: [
@@ -21,6 +19,8 @@ defmodule Pleroma.Web.Nodeinfo.NodeinfoController do
# Schema definition: https://github.com/jhass/nodeinfo/blob/master/schemas/2.0/schema.json
def nodeinfo(conn, %{"version" => "2.0"}) do
+ @instance = Application.get_env(:pleroma, :instance)
+ @media_proxy = Application.get_env(:pleroma, :media_proxy)
stats = Stats.get_stats()
response = %{
@@ -42,7 +42,8 @@ defmodule Pleroma.Web.Nodeinfo.NodeinfoController do
localPosts: stats.status_count || 0
},
metadata: %{
- nodeName: Keyword.get(@instance, :name)
+ nodeName: Keyword.get(@instance, :name),
+ mediaProxy: Keyword.get(@media_proxy, :enabled)
}
}
From 85465512578d8113366e71d9122d336b8fd49fa4 Mon Sep 17 00:00:00 2001
From: William Pitcock
Date: Thu, 12 Jul 2018 02:45:48 +0000
Subject: [PATCH 27/34] activitypub: switch to using x509 representation for
public keys instead of pkcs#1
---
lib/pleroma/web/activity_pub/views/user_view.ex | 2 +-
test/web/activity_pub/views/user_view_test.exs | 2 +-
2 files changed, 2 insertions(+), 2 deletions(-)
diff --git a/lib/pleroma/web/activity_pub/views/user_view.ex b/lib/pleroma/web/activity_pub/views/user_view.ex
index f4b2e0610..41bfe5048 100644
--- a/lib/pleroma/web/activity_pub/views/user_view.ex
+++ b/lib/pleroma/web/activity_pub/views/user_view.ex
@@ -12,7 +12,7 @@ defmodule Pleroma.Web.ActivityPub.UserView do
def render("user.json", %{user: user}) do
{:ok, user} = WebFinger.ensure_keys_present(user)
{:ok, _, public_key} = Salmon.keys_from_pem(user.info["keys"])
- public_key = :public_key.pem_entry_encode(:RSAPublicKey, public_key)
+ public_key = :public_key.pem_entry_encode(:SubjectPublicKeyInfo, public_key)
public_key = :public_key.pem_encode([public_key])
%{
diff --git a/test/web/activity_pub/views/user_view_test.exs b/test/web/activity_pub/views/user_view_test.exs
index 0c64e62c3..7fc870e96 100644
--- a/test/web/activity_pub/views/user_view_test.exs
+++ b/test/web/activity_pub/views/user_view_test.exs
@@ -13,6 +13,6 @@ defmodule Pleroma.Web.ActivityPub.UserViewTest do
assert result["id"] == user.ap_id
assert result["preferredUsername"] == user.nickname
- assert String.contains?(result["publicKey"]["publicKeyPem"], "BEGIN RSA PUBLIC KEY")
+ assert String.contains?(result["publicKey"]["publicKeyPem"], "BEGIN PUBLIC KEY")
end
end
From b806aa36c89f2f7359580c716f98d41b58cb87f9 Mon Sep 17 00:00:00 2001
From: lambda
Date: Thu, 12 Jul 2018 06:00:55 +0000
Subject: [PATCH 28/34] Update nodeinfo_controller.ex
---
lib/pleroma/web/nodeinfo/nodeinfo_controller.ex | 12 ++++++------
1 file changed, 6 insertions(+), 6 deletions(-)
diff --git a/lib/pleroma/web/nodeinfo/nodeinfo_controller.ex b/lib/pleroma/web/nodeinfo/nodeinfo_controller.ex
index e7e2794ae..12aca4a10 100644
--- a/lib/pleroma/web/nodeinfo/nodeinfo_controller.ex
+++ b/lib/pleroma/web/nodeinfo/nodeinfo_controller.ex
@@ -19,22 +19,22 @@ defmodule Pleroma.Web.Nodeinfo.NodeinfoController do
# Schema definition: https://github.com/jhass/nodeinfo/blob/master/schemas/2.0/schema.json
def nodeinfo(conn, %{"version" => "2.0"}) do
- @instance = Application.get_env(:pleroma, :instance)
- @media_proxy = Application.get_env(:pleroma, :media_proxy)
+ instance = Application.get_env(:pleroma, :instance)
+ media_proxy = Application.get_env(:pleroma, :media_proxy)
stats = Stats.get_stats()
response = %{
version: "2.0",
software: %{
name: "pleroma",
- version: Keyword.get(@instance, :version)
+ version: Keyword.get(instance, :version)
},
protocols: ["ostatus", "activitypub"],
services: %{
inbound: [],
outbound: []
},
- openRegistrations: Keyword.get(@instance, :registrations_open),
+ openRegistrations: Keyword.get(instance, :registrations_open),
usage: %{
users: %{
total: stats.user_count || 0
@@ -42,8 +42,8 @@ defmodule Pleroma.Web.Nodeinfo.NodeinfoController do
localPosts: stats.status_count || 0
},
metadata: %{
- nodeName: Keyword.get(@instance, :name),
- mediaProxy: Keyword.get(@media_proxy, :enabled)
+ nodeName: Keyword.get(instance, :name),
+ mediaProxy: Keyword.get(media_proxy, :enabled)
}
}
From 3b799f22b7cd6afd9fb8bc8c7800ec770585a957 Mon Sep 17 00:00:00 2001
From: William Pitcock
Date: Sat, 23 Jun 2018 06:08:09 +0000
Subject: [PATCH 29/34] twitterapi: activity view: expose message summary text
---
lib/pleroma/web/twitter_api/views/activity_view.ex | 3 ++-
1 file changed, 2 insertions(+), 1 deletion(-)
diff --git a/lib/pleroma/web/twitter_api/views/activity_view.ex b/lib/pleroma/web/twitter_api/views/activity_view.ex
index f418249e2..55b5287f5 100644
--- a/lib/pleroma/web/twitter_api/views/activity_view.ex
+++ b/lib/pleroma/web/twitter_api/views/activity_view.ex
@@ -255,7 +255,8 @@ defmodule Pleroma.Web.TwitterAPI.ActivityView do
"tags" => tags,
"activity_type" => "post",
"possibly_sensitive" => possibly_sensitive,
- "visibility" => Pleroma.Web.MastodonAPI.StatusView.get_visibility(object)
+ "visibility" => Pleroma.Web.MastodonAPI.StatusView.get_visibility(object),
+ "summary" => summary
}
end
From 152a526237abb846b96a3c7b4001c8bd0c7409f9 Mon Sep 17 00:00:00 2001
From: William Pitcock
Date: Sun, 24 Jun 2018 05:33:34 +0000
Subject: [PATCH 30/34] twitter api: refactor activity html generation, add
support for Articles
---
lib/pleroma/web/twitter_api/views/activity_view.ex | 2 --
1 file changed, 2 deletions(-)
diff --git a/lib/pleroma/web/twitter_api/views/activity_view.ex b/lib/pleroma/web/twitter_api/views/activity_view.ex
index 55b5287f5..cb7c4cb96 100644
--- a/lib/pleroma/web/twitter_api/views/activity_view.ex
+++ b/lib/pleroma/web/twitter_api/views/activity_view.ex
@@ -262,7 +262,6 @@ defmodule Pleroma.Web.TwitterAPI.ActivityView do
def render_content(%{"type" => "Note"} = object) do
summary = object["summary"]
-
content =
if !!summary and summary != "" do
"#{summary}
#{object["content"]}"
@@ -275,7 +274,6 @@ defmodule Pleroma.Web.TwitterAPI.ActivityView do
def render_content(%{"type" => "Article"} = object) do
summary = object["name"] || object["summary"]
-
content =
if !!summary and summary != "" do
"#{summary}
#{object["content"]}"
From f03e57f7647f4d302359680c7eb7fe48433c7beb Mon Sep 17 00:00:00 2001
From: William Pitcock
Date: Sun, 24 Jun 2018 06:22:53 +0000
Subject: [PATCH 31/34] twitter api: activity representer: add summary field
for testsuite
---
lib/pleroma/web/twitter_api/representers/activity_representer.ex | 3 ++-
1 file changed, 2 insertions(+), 1 deletion(-)
diff --git a/lib/pleroma/web/twitter_api/representers/activity_representer.ex b/lib/pleroma/web/twitter_api/representers/activity_representer.ex
index bb77e61f3..26bfb79af 100644
--- a/lib/pleroma/web/twitter_api/representers/activity_representer.ex
+++ b/lib/pleroma/web/twitter_api/representers/activity_representer.ex
@@ -191,7 +191,8 @@ defmodule Pleroma.Web.TwitterAPI.Representers.ActivityRepresenter do
"tags" => tags,
"activity_type" => "post",
"possibly_sensitive" => possibly_sensitive,
- "visibility" => Pleroma.Web.MastodonAPI.StatusView.get_visibility(object)
+ "visibility" => Pleroma.Web.MastodonAPI.StatusView.get_visibility(object),
+ "summary" => object["summary"]
}
end
From 4fb64c1d862692bb869dd735e9772195b7cf2705 Mon Sep 17 00:00:00 2001
From: William Pitcock
Date: Sun, 24 Jun 2018 06:23:19 +0000
Subject: [PATCH 32/34] testsuite: twitter api: add summary where necessary
---
test/web/twitter_api/representers/activity_representer_test.exs | 3 ++-
test/web/twitter_api/views/activity_view_test.exs | 3 ++-
2 files changed, 4 insertions(+), 2 deletions(-)
diff --git a/test/web/twitter_api/representers/activity_representer_test.exs b/test/web/twitter_api/representers/activity_representer_test.exs
index 7505093dd..3f85e028b 100644
--- a/test/web/twitter_api/representers/activity_representer_test.exs
+++ b/test/web/twitter_api/representers/activity_representer_test.exs
@@ -155,7 +155,8 @@ defmodule Pleroma.Web.TwitterAPI.Representers.ActivityRepresenterTest do
"activity_type" => "post",
"possibly_sensitive" => true,
"uri" => activity.data["object"]["id"],
- "visibility" => "direct"
+ "visibility" => "direct",
+ "summary" => "2hu"
}
assert ActivityRepresenter.to_map(activity, %{
diff --git a/test/web/twitter_api/views/activity_view_test.exs b/test/web/twitter_api/views/activity_view_test.exs
index 5b2a7466b..a101e4ae8 100644
--- a/test/web/twitter_api/views/activity_view_test.exs
+++ b/test/web/twitter_api/views/activity_view_test.exs
@@ -48,7 +48,8 @@ defmodule Pleroma.Web.TwitterAPI.ActivityViewTest do
"text" => "Hey @shp!",
"uri" => activity.data["object"]["id"],
"user" => UserView.render("show.json", %{user: user}),
- "visibility" => "direct"
+ "visibility" => "direct",
+ "summary" => nil
}
assert result == expected
From b832df1e158aa945a3c481804da0a839f18d46c5 Mon Sep 17 00:00:00 2001
From: William Pitcock
Date: Thu, 12 Jul 2018 16:12:54 +0000
Subject: [PATCH 33/34] formatting
---
lib/pleroma/web/twitter_api/views/activity_view.ex | 2 ++
1 file changed, 2 insertions(+)
diff --git a/lib/pleroma/web/twitter_api/views/activity_view.ex b/lib/pleroma/web/twitter_api/views/activity_view.ex
index cb7c4cb96..55b5287f5 100644
--- a/lib/pleroma/web/twitter_api/views/activity_view.ex
+++ b/lib/pleroma/web/twitter_api/views/activity_view.ex
@@ -262,6 +262,7 @@ defmodule Pleroma.Web.TwitterAPI.ActivityView do
def render_content(%{"type" => "Note"} = object) do
summary = object["summary"]
+
content =
if !!summary and summary != "" do
"#{summary}
#{object["content"]}"
@@ -274,6 +275,7 @@ defmodule Pleroma.Web.TwitterAPI.ActivityView do
def render_content(%{"type" => "Article"} = object) do
summary = object["name"] || object["summary"]
+
content =
if !!summary and summary != "" do
"#{summary}
#{object["content"]}"
From 590d4df77c5b6b17b12e9692e77bb24c87ecc4a2 Mon Sep 17 00:00:00 2001
From: William Pitcock
Date: Thu, 12 Jul 2018 16:37:42 +0000
Subject: [PATCH 34/34] activitypub: more robustly handle object-to-actor
associations
---
lib/pleroma/web/activity_pub/transmogrifier.ex | 20 ++++++++++++++++++--
1 file changed, 18 insertions(+), 2 deletions(-)
diff --git a/lib/pleroma/web/activity_pub/transmogrifier.ex b/lib/pleroma/web/activity_pub/transmogrifier.ex
index 59c4b90e7..3dd3df553 100644
--- a/lib/pleroma/web/activity_pub/transmogrifier.ex
+++ b/lib/pleroma/web/activity_pub/transmogrifier.ex
@@ -18,7 +18,7 @@ defmodule Pleroma.Web.ActivityPub.Transmogrifier do
"""
def fix_object(object) do
object
- |> Map.put("actor", object["attributedTo"])
+ |> fix_actor
|> fix_attachments
|> fix_context
|> fix_in_reply_to
@@ -27,6 +27,19 @@ defmodule Pleroma.Web.ActivityPub.Transmogrifier do
|> fix_content_map
end
+ def fix_actor(%{"attributedTo" => actor} = object) do
+ # attributedTo can be a list in the case of peertube or plume
+ actor =
+ if is_list(actor) do
+ Enum.at(actor, 0)
+ else
+ actor
+ end
+
+ object
+ |> Map.put("actor", actor)
+ end
+
def fix_in_reply_to(%{"inReplyTo" => in_reply_to_id} = object)
when not is_nil(in_reply_to_id) do
case ActivityPub.fetch_object_from_id(in_reply_to_id) do
@@ -126,7 +139,10 @@ defmodule Pleroma.Web.ActivityPub.Transmogrifier do
when objtype in ["Article", "Note"] do
with nil <- Activity.get_create_activity_by_object_ap_id(object["id"]),
%User{} = user <- User.get_or_fetch_by_ap_id(data["actor"]) do
- object = fix_object(data["object"])
+ # prefer the activity's actor instead of attributedTo
+ object =
+ fix_object(data["object"])
+ |> Map.put("actor", data["actor"])
params = %{
to: data["to"],