summaryrefslogtreecommitdiff
path: root/lib
diff options
context:
space:
mode:
Diffstat (limited to 'lib')
-rw-r--r--lib/pleroma/user.ex26
-rw-r--r--lib/pleroma/web/activity_pub/activity_pub.ex10
-rw-r--r--lib/pleroma/web/activity_pub/transmogrifier.ex12
3 files changed, 44 insertions, 4 deletions
diff --git a/lib/pleroma/user.ex b/lib/pleroma/user.ex
index b27397e13..aba8742a0 100644
--- a/lib/pleroma/user.ex
+++ b/lib/pleroma/user.ex
@@ -505,15 +505,33 @@ defmodule Pleroma.User do
Repo.all(q)
end
- def block(user, %{ap_id: ap_id}) do
- blocks = user.info["blocks"] || []
+ def block(blocker, %User{ap_id: ap_id} = blocked) do
+ # sever any follow relationships to prevent leaks per activitypub (Pleroma issue #213)
+ blocker =
+ if following?(blocker, blocked) do
+ {:ok, blocker, _} = unfollow(blocker, blocked)
+ blocker
+ else
+ blocker
+ end
+
+ if following?(blocked, blocker) do
+ unfollow(blocked, blocker)
+ end
+
+ blocks = blocker.info["blocks"] || []
new_blocks = Enum.uniq([ap_id | blocks])
- new_info = Map.put(user.info, "blocks", new_blocks)
+ new_info = Map.put(blocker.info, "blocks", new_blocks)
- cs = User.info_changeset(user, %{info: new_info})
+ cs = User.info_changeset(blocker, %{info: new_info})
update_and_set_cache(cs)
end
+ # helper to handle the block given only an actor's AP id
+ def block(blocker, %{ap_id: ap_id}) do
+ block(blocker, User.get_by_ap_id(ap_id))
+ end
+
def unblock(user, %{ap_id: ap_id}) do
blocks = user.info["blocks"] || []
new_blocks = List.delete(blocks, ap_id)
diff --git a/lib/pleroma/web/activity_pub/activity_pub.ex b/lib/pleroma/web/activity_pub/activity_pub.ex
index 554202f6b..dfcc5b9ed 100644
--- a/lib/pleroma/web/activity_pub/activity_pub.ex
+++ b/lib/pleroma/web/activity_pub/activity_pub.ex
@@ -438,6 +438,15 @@ defmodule Pleroma.Web.ActivityPub.ActivityPub do
defp restrict_media(query, _), do: query
+ defp restrict_replies(query, %{"exclude_replies" => val}) when val == "true" or val == "1" do
+ from(
+ activity in query,
+ where: fragment("?->'object'->>'inReplyTo' is null", activity.data)
+ )
+ end
+
+ defp restrict_replies(query, _), do: query
+
# Only search through last 100_000 activities by default
defp restrict_recent(query, %{"whole_db" => true}), do: query
@@ -495,6 +504,7 @@ defmodule Pleroma.Web.ActivityPub.ActivityPub do
|> restrict_blocked(opts)
|> restrict_media(opts)
|> restrict_visibility(opts)
+ |> restrict_replies(opts)
end
def fetch_activities(recipients, opts \\ %{}) do
diff --git a/lib/pleroma/web/activity_pub/transmogrifier.ex b/lib/pleroma/web/activity_pub/transmogrifier.ex
index 300e0fcdd..30cd70fb6 100644
--- a/lib/pleroma/web/activity_pub/transmogrifier.ex
+++ b/lib/pleroma/web/activity_pub/transmogrifier.ex
@@ -24,6 +24,7 @@ defmodule Pleroma.Web.ActivityPub.Transmogrifier do
|> fix_in_reply_to
|> fix_emoji
|> fix_tag
+ |> fix_content_map
end
def fix_in_reply_to(%{"inReplyTo" => in_reply_to_id} = object)
@@ -107,6 +108,17 @@ defmodule Pleroma.Web.ActivityPub.Transmogrifier do
|> Map.put("tag", combined)
end
+ # content map usually only has one language so this will do for now.
+ def fix_content_map(%{"contentMap" => content_map} = object) do
+ content_groups = Map.to_list(content_map)
+ {_, content} = Enum.at(content_groups, 0)
+
+ object
+ |> Map.put("content", content)
+ end
+
+ def fix_content_map(object), do: object
+
# TODO: validate those with a Ecto scheme
# - tags
# - emoji