Make no_empty_policy multilang-aware
This commit is contained in:
parent
9354ee31d2
commit
e958ec57db
2 changed files with 70 additions and 2 deletions
|
@ -43,8 +43,16 @@ defp has_attachment?(_), do: false
|
|||
defp only_mentions?(%{"object" => %{"type" => "Note", "source" => source}}) do
|
||||
source =
|
||||
case source do
|
||||
%{"content" => text} -> text
|
||||
_ -> source
|
||||
%{"contentMap" => %{} = text_map} ->
|
||||
text_map
|
||||
|> Enum.map(fn {_, content} -> content end)
|
||||
|> Enum.join("\n")
|
||||
|
||||
%{"content" => text} ->
|
||||
text
|
||||
|
||||
_ ->
|
||||
source
|
||||
end
|
||||
|
||||
non_mentions =
|
||||
|
|
|
@ -129,6 +129,66 @@ test "Notes with only mentions are denied" do
|
|||
assert NoEmptyPolicy.filter(message) == {:reject, "[NoEmptyPolicy]"}
|
||||
end
|
||||
|
||||
test "Notes with only mentions in source.contentMap are denied" do
|
||||
message = %{
|
||||
"actor" => "http://localhost:4001/users/testuser",
|
||||
"cc" => ["http://localhost:4001/users/testuser/followers"],
|
||||
"object" => %{
|
||||
"actor" => "http://localhost:4001/users/testuser",
|
||||
"attachment" => [],
|
||||
"cc" => ["http://localhost:4001/users/testuser/followers"],
|
||||
"source" => %{
|
||||
"contentMap" => %{
|
||||
"a" => "@user2",
|
||||
"b" => "@user2"
|
||||
}
|
||||
},
|
||||
"to" => [
|
||||
"https://www.w3.org/ns/activitystreams#Public",
|
||||
"http://localhost:4001/users/user2"
|
||||
],
|
||||
"type" => "Note"
|
||||
},
|
||||
"to" => [
|
||||
"https://www.w3.org/ns/activitystreams#Public",
|
||||
"http://localhost:4001/users/user2"
|
||||
],
|
||||
"type" => "Create"
|
||||
}
|
||||
|
||||
assert NoEmptyPolicy.filter(message) == {:reject, "[NoEmptyPolicy]"}
|
||||
end
|
||||
|
||||
test "Notes with mentions and other content in source.contentMap are allowed" do
|
||||
message = %{
|
||||
"actor" => "http://localhost:4001/users/testuser",
|
||||
"cc" => ["http://localhost:4001/users/testuser/followers"],
|
||||
"object" => %{
|
||||
"actor" => "http://localhost:4001/users/testuser",
|
||||
"attachment" => [],
|
||||
"cc" => ["http://localhost:4001/users/testuser/followers"],
|
||||
"source" => %{
|
||||
"contentMap" => %{
|
||||
"a" => "@user2",
|
||||
"b" => "@user2 lol"
|
||||
}
|
||||
},
|
||||
"to" => [
|
||||
"https://www.w3.org/ns/activitystreams#Public",
|
||||
"http://localhost:4001/users/user2"
|
||||
],
|
||||
"type" => "Note"
|
||||
},
|
||||
"to" => [
|
||||
"https://www.w3.org/ns/activitystreams#Public",
|
||||
"http://localhost:4001/users/user2"
|
||||
],
|
||||
"type" => "Create"
|
||||
}
|
||||
|
||||
assert {:ok, _} = NoEmptyPolicy.filter(message)
|
||||
end
|
||||
|
||||
test "Notes with no content are denied" do
|
||||
message = %{
|
||||
"actor" => "http://localhost:4001/users/testuser",
|
||||
|
|
Loading…
Reference in a new issue