activitypub: transmogrifier: add necessary translations for kroeg
This commit is contained in:
parent
8c0c930041
commit
f446e75577
1 changed files with 26 additions and 1 deletions
|
@ -21,6 +21,10 @@ def get_actor(%{"actor" => actor}) when is_list(actor) do
|
||||||
Enum.at(actor, 0)
|
Enum.at(actor, 0)
|
||||||
end
|
end
|
||||||
|
|
||||||
|
def get_actor(%{"actor" => actor}) when is_map(actor) do
|
||||||
|
actor["id"]
|
||||||
|
end
|
||||||
|
|
||||||
def get_actor(%{"actor" => actor_list}) do
|
def get_actor(%{"actor" => actor_list}) do
|
||||||
Enum.find(actor_list, fn %{"type" => type} -> type == "Person" end)
|
Enum.find(actor_list, fn %{"type" => type} -> type == "Person" end)
|
||||||
|> Map.get("id")
|
|> Map.get("id")
|
||||||
|
@ -38,6 +42,24 @@ def fix_object(object) do
|
||||||
|> fix_emoji
|
|> fix_emoji
|
||||||
|> fix_tag
|
|> fix_tag
|
||||||
|> fix_content_map
|
|> fix_content_map
|
||||||
|
|> fix_addressing
|
||||||
|
end
|
||||||
|
|
||||||
|
def fix_addressing_list(map, field) do
|
||||||
|
if is_binary(map[field]) do
|
||||||
|
map
|
||||||
|
|> Map.put(field, [map[field]])
|
||||||
|
else
|
||||||
|
map
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
def fix_addressing(map) do
|
||||||
|
map
|
||||||
|
|> fix_addressing_list("to")
|
||||||
|
|> fix_addressing_list("cc")
|
||||||
|
|> fix_addressing_list("bto")
|
||||||
|
|> fix_addressing_list("bcc")
|
||||||
end
|
end
|
||||||
|
|
||||||
def fix_actor(%{"attributedTo" => actor} = object) do
|
def fix_actor(%{"attributedTo" => actor} = object) do
|
||||||
|
@ -143,7 +165,10 @@ def fix_content_map(object), do: object
|
||||||
def handle_incoming(%{"type" => "Create", "object" => %{"type" => objtype} = object} = data)
|
def handle_incoming(%{"type" => "Create", "object" => %{"type" => objtype} = object} = data)
|
||||||
when objtype in ["Article", "Note"] do
|
when objtype in ["Article", "Note"] do
|
||||||
actor = get_actor(data)
|
actor = get_actor(data)
|
||||||
data = Map.put(data, "actor", actor)
|
|
||||||
|
data =
|
||||||
|
Map.put(data, "actor", actor)
|
||||||
|
|> fix_addressing
|
||||||
|
|
||||||
with nil <- Activity.get_create_activity_by_object_ap_id(object["id"]),
|
with nil <- Activity.get_create_activity_by_object_ap_id(object["id"]),
|
||||||
%User{} = user <- User.get_or_fetch_by_ap_id(data["actor"]) do
|
%User{} = user <- User.get_or_fetch_by_ap_id(data["actor"]) do
|
||||||
|
|
Loading…
Reference in a new issue