user: implement AS2 mention extraction + unify Announce handling

This commit is contained in:
William Pitcock 2018-11-08 20:01:42 +00:00
parent 6b4064fa5d
commit 81d6ca1783

View file

@ -482,20 +482,35 @@ defmodule Pleroma.User do
def get_notified_from_activity(activity, local_only \\ true) def get_notified_from_activity(activity, local_only \\ true)
def get_notified_from_activity( def get_notified_from_activity(%Activity{data: %{"to" => to} = data}, local_only) do
%Activity{data: %{"type" => "Announce", "to" => to} = data},
local_only
) do
object = Object.normalize(data["object"]) object = Object.normalize(data["object"])
actor = User.get_cached_by_ap_id(data["actor"])
# ensure that the actor who published the announced object appears only once # somehow, get an AS2 object, preferring the normalized object if we have one
to = object_data =
if actor.nickname != nil do if object do
to ++ [object.data["actor"]] object.data
else else
to if is_map(data["object"]) do
data["object"]
else
%{}
end
end end
# finally extract AS2 mentions from this object
tagged_mentions =
if object_data["tag"] do
object_data["tag"]
|> Enum.filter(fn x -> is_map(x) end)
|> Enum.filter(fn x -> x["type"] == "Mention" end)
|> Enum.map(fn x -> x["href"] end)
else
[]
end
# ensure all mentioned users are unique
to =
(to ++ tagged_mentions)
|> Enum.uniq() |> Enum.uniq()
query = get_notified_from_activity_query(to, local_only) query = get_notified_from_activity_query(to, local_only)
@ -503,12 +518,6 @@ defmodule Pleroma.User do
Repo.all(query) Repo.all(query)
end end
def get_notified_from_activity(%Activity{data: %{"to" => to}}, local_only) do
query = get_notified_from_activity_query(to, local_only)
Repo.all(query)
end
def get_notified_from_activity(_, _), do: [] def get_notified_from_activity(_, _), do: []
def get_recipients_from_activity(%Activity{recipients: to}) do def get_recipients_from_activity(%Activity{recipients: to}) do