AP: Fix incoming conversations.

This commit is contained in:
lain 2018-02-19 10:39:03 +01:00
parent 6b32b9e346
commit 6b6ab592ab
2 changed files with 10 additions and 1 deletions

View File

@ -14,6 +14,12 @@ def fix_object(object) do
object object
|> Map.put("actor", object["attributedTo"]) |> Map.put("actor", object["attributedTo"])
|> fix_attachments |> fix_attachments
|> fix_context
end
def fix_context(object) do
object
|> Map.put("context", object["conversation"])
end end
def fix_attachments(object) do def fix_attachments(object) do
@ -130,7 +136,8 @@ def add_hashtags(object) do
end end
def add_mention_tags(object) do def add_mention_tags(object) do
mentions = object["to"] recipients = object["to"] ++ (object["cc"] || [])
mentions = recipients
|> Enum.map(fn (ap_id) -> User.get_cached_by_ap_id(ap_id) end) |> Enum.map(fn (ap_id) -> User.get_cached_by_ap_id(ap_id) end)
|> Enum.filter(&(&1)) |> Enum.filter(&(&1))
|> Enum.map(fn(user) -> %{"type" => "Mention", "href" => user.ap_id, "name" => "@#{user.nickname}"} end) |> Enum.map(fn(user) -> %{"type" => "Mention", "href" => user.ap_id, "name" => "@#{user.nickname}"} end)

View File

@ -33,6 +33,7 @@ test "it works for incoming notices" do
] ]
assert object["actor"] == "http://mastodon.example.org/users/admin" assert object["actor"] == "http://mastodon.example.org/users/admin"
assert object["attributedTo"] == "http://mastodon.example.org/users/admin" assert object["attributedTo"] == "http://mastodon.example.org/users/admin"
assert object["context"] == "tag:mastodon.example.org,2018-02-12:objectId=20:objectType=Conversation"
assert object["sensitive"] == true assert object["sensitive"] == true
end end
@ -111,6 +112,7 @@ test "it turns mentions into tags" do
"name" => "@#{other_user.nickname}", "name" => "@#{other_user.nickname}",
"type" => "Mention" "type" => "Mention"
} }
expected_tag = %{ expected_tag = %{
"href" => Pleroma.Web.Endpoint.url <> "/tags/2hu", "href" => Pleroma.Web.Endpoint.url <> "/tags/2hu",
"type" => "Hashtag", "type" => "Hashtag",