ObjectValidators: improve quoteUrl compatibility

This commit is contained in:
Alex Gleason 2022-01-22 18:03:22 -06:00 committed by tusooa
parent 7deda1fa18
commit 795736af16
No known key found for this signature in database
GPG Key ID: 42AEC43D48433C51
2 changed files with 36 additions and 0 deletions

View File

@ -76,6 +76,21 @@ def fix_attachments(%{"attachment" => attachment} = data) when is_map(attachment
def fix_attachments(data), do: data def fix_attachments(data), do: data
defp fix_quote_url(%{"quoteUrl" => _quote_url} = data), do: data
# Fix for Fedibird
# https://github.com/fedibird/mastodon/issues/9
defp fix_quote_url(%{"quoteURL" => quote_url} = data) do
Map.put(data, "quoteUrl", quote_url)
end
# Misskey fallback
defp fix_quote_url(%{"_misskey_quote" => quote_url} = data) do
Map.put(data, "quoteUrl", quote_url)
end
defp fix_quote_url(data), do: data
defp fix(data) do defp fix(data) do
data data
|> CommonFixes.fix_actor() |> CommonFixes.fix_actor()
@ -84,6 +99,7 @@ defp fix(data) do
|> fix_tag() |> fix_tag()
|> fix_replies() |> fix_replies()
|> fix_attachments() |> fix_attachments()
|> fix_quote_url()
|> Transmogrifier.fix_emoji() |> Transmogrifier.fix_emoji()
|> Transmogrifier.fix_content_map() |> Transmogrifier.fix_content_map()
end end

View File

@ -116,4 +116,24 @@ test "a Note without replies/first/items validates" do
%{valid?: true} = ArticleNotePageValidator.cast_and_validate(note) %{valid?: true} = ArticleNotePageValidator.cast_and_validate(note)
end end
test "Fedibird quote post" do
insert(:user, ap_id: "https://fedibird.com/users/noellabo")
data = File.read!("test/fixtures/quote_post/fedibird_quote_post.json") |> Jason.decode!()
chg = ArticleNotePageValidator.cast_and_validate(data)
assert chg.valid?
assert chg.changes.quoteUrl == "https://misskey.io/notes/8vsn2izjwh"
end
test "Misskey quote post" do
insert(:user, ap_id: "https://misskey.io/users/7rkrarq81i")
data = File.read!("test/fixtures/quote_post/misskey_quote_post.json") |> Jason.decode!()
chg = ArticleNotePageValidator.cast_and_validate(data)
assert chg.valid?
assert chg.changes.quoteUrl == "https://misskey.io/notes/8vs6wxufd0"
end
end end