Merge branch 'from/upstream-develop/tusooa/streaming-fix' into 'develop'
Streaming fix Closes #2796 See merge request pleroma/pleroma!3738
This commit is contained in:
commit
c63cf954de
3 changed files with 131 additions and 7 deletions
|
@ -13,6 +13,14 @@ defmodule Pleroma.Activity.Ir.Topics do
|
||||||
|> List.flatten()
|
|> List.flatten()
|
||||||
end
|
end
|
||||||
|
|
||||||
|
defp generate_topics(%{data: %{"type" => "ChatMessage"}}, %{data: %{"type" => "Delete"}}) do
|
||||||
|
["user", "user:pleroma_chat"]
|
||||||
|
end
|
||||||
|
|
||||||
|
defp generate_topics(%{data: %{"type" => "ChatMessage"}}, %{data: %{"type" => "Create"}}) do
|
||||||
|
[]
|
||||||
|
end
|
||||||
|
|
||||||
defp generate_topics(%{data: %{"type" => "Answer"}}, _) do
|
defp generate_topics(%{data: %{"type" => "Answer"}}, _) do
|
||||||
[]
|
[]
|
||||||
end
|
end
|
||||||
|
@ -21,7 +29,7 @@ defmodule Pleroma.Activity.Ir.Topics do
|
||||||
["user", "list"] ++ visibility_tags(object, activity)
|
["user", "list"] ++ visibility_tags(object, activity)
|
||||||
end
|
end
|
||||||
|
|
||||||
defp visibility_tags(object, activity) do
|
defp visibility_tags(object, %{data: %{"type" => type}} = activity) when type != "Announce" do
|
||||||
case Visibility.get_visibility(activity) do
|
case Visibility.get_visibility(activity) do
|
||||||
"public" ->
|
"public" ->
|
||||||
if activity.local do
|
if activity.local do
|
||||||
|
@ -31,6 +39,10 @@ defmodule Pleroma.Activity.Ir.Topics do
|
||||||
end
|
end
|
||||||
|> item_creation_tags(object, activity)
|
|> item_creation_tags(object, activity)
|
||||||
|
|
||||||
|
"local" ->
|
||||||
|
["public:local"]
|
||||||
|
|> item_creation_tags(object, activity)
|
||||||
|
|
||||||
"direct" ->
|
"direct" ->
|
||||||
["direct"]
|
["direct"]
|
||||||
|
|
||||||
|
@ -39,6 +51,10 @@ defmodule Pleroma.Activity.Ir.Topics do
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
defp visibility_tags(_object, _activity) do
|
||||||
|
[]
|
||||||
|
end
|
||||||
|
|
||||||
defp item_creation_tags(tags, object, %{data: %{"type" => "Create"}} = activity) do
|
defp item_creation_tags(tags, object, %{data: %{"type" => "Create"}} = activity) do
|
||||||
tags ++
|
tags ++
|
||||||
remote_topics(activity) ++ hashtags_to_topics(object) ++ attachment_topics(object, activity)
|
remote_topics(activity) ++ hashtags_to_topics(object) ++ attachment_topics(object, activity)
|
||||||
|
@ -63,7 +79,18 @@ defmodule Pleroma.Activity.Ir.Topics do
|
||||||
|
|
||||||
defp attachment_topics(%{data: %{"attachment" => []}}, _act), do: []
|
defp attachment_topics(%{data: %{"attachment" => []}}, _act), do: []
|
||||||
|
|
||||||
defp attachment_topics(_object, %{local: true}), do: ["public:media", "public:local:media"]
|
defp attachment_topics(_object, %{local: true} = activity) do
|
||||||
|
case Visibility.get_visibility(activity) do
|
||||||
|
"public" ->
|
||||||
|
["public:media", "public:local:media"]
|
||||||
|
|
||||||
|
"local" ->
|
||||||
|
["public:local:media"]
|
||||||
|
|
||||||
|
_ ->
|
||||||
|
[]
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
defp attachment_topics(_object, %{actor: actor}) when is_binary(actor),
|
defp attachment_topics(_object, %{actor: actor}) when is_binary(actor),
|
||||||
do: ["public:media", "public:remote:media:" <> URI.parse(actor).host]
|
do: ["public:media", "public:remote:media:" <> URI.parse(actor).host]
|
||||||
|
|
|
@ -13,6 +13,29 @@ defmodule Pleroma.Activity.Ir.TopicsTest do
|
||||||
|
|
||||||
import Mock
|
import Mock
|
||||||
|
|
||||||
|
describe "chat message" do
|
||||||
|
test "Create produces no topics" do
|
||||||
|
activity = %Activity{
|
||||||
|
object: %Object{data: %{"type" => "ChatMessage"}},
|
||||||
|
data: %{"type" => "Create"}
|
||||||
|
}
|
||||||
|
|
||||||
|
assert [] == Topics.get_activity_topics(activity)
|
||||||
|
end
|
||||||
|
|
||||||
|
test "Delete produces user and user:pleroma_chat" do
|
||||||
|
activity = %Activity{
|
||||||
|
object: %Object{data: %{"type" => "ChatMessage"}},
|
||||||
|
data: %{"type" => "Delete"}
|
||||||
|
}
|
||||||
|
|
||||||
|
topics = Topics.get_activity_topics(activity)
|
||||||
|
assert [_, _] = topics
|
||||||
|
assert "user" in topics
|
||||||
|
assert "user:pleroma_chat" in topics
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
describe "poll answer" do
|
describe "poll answer" do
|
||||||
test "produce no topics" do
|
test "produce no topics" do
|
||||||
activity = %Activity{object: %Object{data: %{"type" => "Answer"}}}
|
activity = %Activity{object: %Object{data: %{"type" => "Answer"}}}
|
||||||
|
@ -35,7 +58,7 @@ defmodule Pleroma.Activity.Ir.TopicsTest do
|
||||||
setup do
|
setup do
|
||||||
activity = %Activity{
|
activity = %Activity{
|
||||||
object: %Object{data: %{"type" => "Note"}},
|
object: %Object{data: %{"type" => "Note"}},
|
||||||
data: %{"to" => [Pleroma.Constants.as_public()]}
|
data: %{"to" => [Pleroma.Constants.as_public()], "type" => "Create"}
|
||||||
}
|
}
|
||||||
|
|
||||||
{:ok, activity: activity}
|
{:ok, activity: activity}
|
||||||
|
@ -114,6 +137,55 @@ defmodule Pleroma.Activity.Ir.TopicsTest do
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
describe "public visibility Announces" do
|
||||||
|
setup do
|
||||||
|
activity = %Activity{
|
||||||
|
object: %Object{data: %{"attachment" => []}},
|
||||||
|
data: %{"type" => "Announce", "to" => [Pleroma.Constants.as_public()]}
|
||||||
|
}
|
||||||
|
|
||||||
|
{:ok, activity: activity}
|
||||||
|
end
|
||||||
|
|
||||||
|
test "does not generate public topics", %{activity: activity} do
|
||||||
|
topics = Topics.get_activity_topics(activity)
|
||||||
|
|
||||||
|
refute "public" in topics
|
||||||
|
refute "public:remote" in topics
|
||||||
|
refute "public:local" in topics
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
describe "local-public visibility create events" do
|
||||||
|
setup do
|
||||||
|
activity = %Activity{
|
||||||
|
object: %Object{data: %{"attachment" => []}},
|
||||||
|
data: %{"type" => "Create", "to" => [Pleroma.Web.ActivityPub.Utils.as_local_public()]}
|
||||||
|
}
|
||||||
|
|
||||||
|
{:ok, activity: activity}
|
||||||
|
end
|
||||||
|
|
||||||
|
test "doesn't produce public topics", %{activity: activity} do
|
||||||
|
topics = Topics.get_activity_topics(activity)
|
||||||
|
|
||||||
|
refute Enum.member?(topics, "public")
|
||||||
|
end
|
||||||
|
|
||||||
|
test "produces public:local topics", %{activity: activity} do
|
||||||
|
topics = Topics.get_activity_topics(activity)
|
||||||
|
|
||||||
|
assert Enum.member?(topics, "public:local")
|
||||||
|
end
|
||||||
|
|
||||||
|
test "with no attachments doesn't produce public:media topics", %{activity: activity} do
|
||||||
|
topics = Topics.get_activity_topics(activity)
|
||||||
|
|
||||||
|
refute Enum.member?(topics, "public:media")
|
||||||
|
refute Enum.member?(topics, "public:local:media")
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
describe "public visibility create events with attachments" do
|
describe "public visibility create events with attachments" do
|
||||||
setup do
|
setup do
|
||||||
activity = %Activity{
|
activity = %Activity{
|
||||||
|
@ -152,9 +224,36 @@ defmodule Pleroma.Activity.Ir.TopicsTest do
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
describe "local-public visibility create events with attachments" do
|
||||||
|
setup do
|
||||||
|
activity = %Activity{
|
||||||
|
object: %Object{data: %{"attachment" => ["foo"]}},
|
||||||
|
data: %{"type" => "Create", "to" => [Pleroma.Web.ActivityPub.Utils.as_local_public()]}
|
||||||
|
}
|
||||||
|
|
||||||
|
{:ok, activity: activity}
|
||||||
|
end
|
||||||
|
|
||||||
|
test "do not produce public:media topics", %{activity: activity} do
|
||||||
|
topics = Topics.get_activity_topics(activity)
|
||||||
|
|
||||||
|
refute Enum.member?(topics, "public:media")
|
||||||
|
end
|
||||||
|
|
||||||
|
test "produces public:local:media topics", %{activity: activity} do
|
||||||
|
topics = Topics.get_activity_topics(activity)
|
||||||
|
|
||||||
|
assert Enum.member?(topics, "public:local:media")
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
describe "non-public visibility" do
|
describe "non-public visibility" do
|
||||||
test "produces direct topic" do
|
test "produces direct topic" do
|
||||||
activity = %Activity{object: %Object{data: %{"type" => "Note"}}, data: %{"to" => []}}
|
activity = %Activity{
|
||||||
|
object: %Object{data: %{"type" => "Note"}},
|
||||||
|
data: %{"to" => [], "type" => "Create"}
|
||||||
|
}
|
||||||
|
|
||||||
topics = Topics.get_activity_topics(activity)
|
topics = Topics.get_activity_topics(activity)
|
||||||
|
|
||||||
assert Enum.member?(topics, "direct")
|
assert Enum.member?(topics, "direct")
|
||||||
|
|
|
@ -839,9 +839,7 @@ defmodule Pleroma.Web.ActivityPub.SideEffectsTest do
|
||||||
]) do
|
]) do
|
||||||
{:ok, announce, _} = SideEffects.handle(announce)
|
{:ok, announce, _} = SideEffects.handle(announce)
|
||||||
|
|
||||||
assert called(
|
assert called(Pleroma.Web.Streamer.stream(["user", "list"], announce))
|
||||||
Pleroma.Web.Streamer.stream(["user", "list", "public", "public:local"], announce)
|
|
||||||
)
|
|
||||||
|
|
||||||
assert called(Pleroma.Web.Push.send(:_))
|
assert called(Pleroma.Web.Push.send(:_))
|
||||||
end
|
end
|
||||||
|
|
Loading…
Reference in a new issue