2020-10-12 11:00:50 -06:00
|
|
|
# Pleroma: A lightweight social networking server
|
2021-01-12 23:49:20 -07:00
|
|
|
# Copyright © 2017-2021 Pleroma Authors <https://pleroma.social/>
|
2020-10-12 11:00:50 -06:00
|
|
|
# SPDX-License-Identifier: AGPL-3.0-only
|
|
|
|
|
2019-09-16 04:03:37 -06:00
|
|
|
defmodule Pleroma.Activity.Ir.TopicsTest do
|
2023-08-01 04:43:50 -06:00
|
|
|
use Pleroma.DataCase, async: false
|
2019-09-16 04:03:37 -06:00
|
|
|
|
|
|
|
alias Pleroma.Activity
|
|
|
|
alias Pleroma.Activity.Ir.Topics
|
|
|
|
alias Pleroma.Object
|
|
|
|
|
|
|
|
require Pleroma.Constants
|
|
|
|
|
2020-12-27 14:08:09 -07:00
|
|
|
import Mock
|
|
|
|
|
2019-09-16 04:03:37 -06:00
|
|
|
describe "poll answer" do
|
|
|
|
test "produce no topics" do
|
|
|
|
activity = %Activity{object: %Object{data: %{"type" => "Answer"}}}
|
|
|
|
|
|
|
|
assert [] == Topics.get_activity_topics(activity)
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
describe "non poll answer" do
|
|
|
|
test "always add user and list topics" do
|
|
|
|
activity = %Activity{object: %Object{data: %{"type" => "FooBar"}}}
|
|
|
|
topics = Topics.get_activity_topics(activity)
|
|
|
|
|
|
|
|
assert Enum.member?(topics, "user")
|
|
|
|
assert Enum.member?(topics, "list")
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
describe "public visibility" do
|
|
|
|
setup do
|
|
|
|
activity = %Activity{
|
|
|
|
object: %Object{data: %{"type" => "Note"}},
|
2022-08-31 13:57:06 -06:00
|
|
|
data: %{"to" => [Pleroma.Constants.as_public()], "type" => "Create"}
|
2019-09-16 04:03:37 -06:00
|
|
|
}
|
|
|
|
|
|
|
|
{:ok, activity: activity}
|
|
|
|
end
|
|
|
|
|
|
|
|
test "produces public topic", %{activity: activity} do
|
|
|
|
topics = Topics.get_activity_topics(activity)
|
|
|
|
|
|
|
|
assert Enum.member?(topics, "public")
|
|
|
|
end
|
|
|
|
|
|
|
|
test "local action produces public:local topic", %{activity: activity} do
|
|
|
|
activity = %{activity | local: true}
|
|
|
|
topics = Topics.get_activity_topics(activity)
|
|
|
|
|
|
|
|
assert Enum.member?(topics, "public:local")
|
|
|
|
end
|
|
|
|
|
|
|
|
test "non-local action does not produce public:local topic", %{activity: activity} do
|
|
|
|
activity = %{activity | local: false}
|
|
|
|
topics = Topics.get_activity_topics(activity)
|
|
|
|
|
|
|
|
refute Enum.member?(topics, "public:local")
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
describe "public visibility create events" do
|
|
|
|
setup do
|
|
|
|
activity = %Activity{
|
2020-03-13 09:30:42 -06:00
|
|
|
object: %Object{data: %{"attachment" => []}},
|
|
|
|
data: %{"type" => "Create", "to" => [Pleroma.Constants.as_public()]}
|
2019-09-16 04:03:37 -06:00
|
|
|
}
|
|
|
|
|
|
|
|
{:ok, activity: activity}
|
|
|
|
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
|
|
|
|
|
2020-12-27 14:08:09 -07:00
|
|
|
test "converts tags to hash tags", %{activity: activity} do
|
|
|
|
with_mock(Object, [:passthrough], hashtags: fn _ -> ["foo", "bar"] end) do
|
|
|
|
topics = Topics.get_activity_topics(activity)
|
2019-09-16 04:03:37 -06:00
|
|
|
|
2020-12-27 14:08:09 -07:00
|
|
|
assert Enum.member?(topics, "hashtag:foo")
|
|
|
|
assert Enum.member?(topics, "hashtag:bar")
|
|
|
|
end
|
2019-09-16 04:03:37 -06:00
|
|
|
end
|
|
|
|
|
2020-02-11 00:12:57 -07:00
|
|
|
test "only converts strings to hash tags", %{
|
2019-09-16 04:03:37 -06:00
|
|
|
activity: %{object: %{data: data} = object} = activity
|
|
|
|
} do
|
|
|
|
tagged_data = Map.put(data, "tag", [2])
|
|
|
|
activity = %{activity | object: %{object | data: tagged_data}}
|
|
|
|
|
|
|
|
topics = Topics.get_activity_topics(activity)
|
|
|
|
|
|
|
|
refute Enum.member?(topics, "hashtag:2")
|
|
|
|
end
|
2020-10-08 19:01:48 -06:00
|
|
|
|
|
|
|
test "non-local action produces public:remote topic", %{activity: activity} do
|
|
|
|
activity = %{activity | local: false, actor: "https://lain.com/users/lain"}
|
|
|
|
topics = Topics.get_activity_topics(activity)
|
|
|
|
|
|
|
|
assert Enum.member?(topics, "public:remote:lain.com")
|
|
|
|
end
|
2020-11-04 07:24:10 -07:00
|
|
|
|
|
|
|
test "local action doesn't produce public:remote topic", %{activity: activity} do
|
|
|
|
activity = %{activity | local: true, actor: "https://lain.com/users/lain"}
|
|
|
|
topics = Topics.get_activity_topics(activity)
|
|
|
|
|
|
|
|
refute Enum.member?(topics, "public:remote:lain.com")
|
|
|
|
end
|
2019-09-16 04:03:37 -06:00
|
|
|
end
|
|
|
|
|
2022-08-31 13:57:06 -06:00
|
|
|
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
|
|
|
|
|
2022-08-27 17:34:56 -06:00
|
|
|
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
|
|
|
|
|
2019-09-16 04:03:37 -06:00
|
|
|
describe "public visibility create events with attachments" do
|
|
|
|
setup do
|
|
|
|
activity = %Activity{
|
2020-03-13 09:30:42 -06:00
|
|
|
object: %Object{data: %{"attachment" => ["foo"]}},
|
|
|
|
data: %{"type" => "Create", "to" => [Pleroma.Constants.as_public()]}
|
2019-09-16 04:03:37 -06:00
|
|
|
}
|
|
|
|
|
|
|
|
{:ok, activity: activity}
|
|
|
|
end
|
|
|
|
|
|
|
|
test "produce public:media topics", %{activity: activity} do
|
|
|
|
topics = Topics.get_activity_topics(activity)
|
|
|
|
|
|
|
|
assert Enum.member?(topics, "public:media")
|
|
|
|
end
|
|
|
|
|
|
|
|
test "local produces public:local:media topics", %{activity: activity} do
|
|
|
|
topics = Topics.get_activity_topics(activity)
|
|
|
|
|
|
|
|
assert Enum.member?(topics, "public:local:media")
|
|
|
|
end
|
|
|
|
|
|
|
|
test "non-local doesn't produce public:local:media topics", %{activity: activity} do
|
|
|
|
activity = %{activity | local: false}
|
|
|
|
|
|
|
|
topics = Topics.get_activity_topics(activity)
|
|
|
|
|
|
|
|
refute Enum.member?(topics, "public:local:media")
|
|
|
|
end
|
2020-10-08 19:01:48 -06:00
|
|
|
|
|
|
|
test "non-local action produces public:remote:media topic", %{activity: activity} do
|
|
|
|
activity = %{activity | local: false, actor: "https://lain.com/users/lain"}
|
|
|
|
topics = Topics.get_activity_topics(activity)
|
|
|
|
|
|
|
|
assert Enum.member?(topics, "public:remote:media:lain.com")
|
|
|
|
end
|
2019-09-16 04:03:37 -06:00
|
|
|
end
|
|
|
|
|
2022-08-27 17:34:56 -06:00
|
|
|
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
|
|
|
|
|
2019-09-16 04:03:37 -06:00
|
|
|
describe "non-public visibility" do
|
|
|
|
test "produces direct topic" do
|
2022-08-31 13:57:06 -06:00
|
|
|
activity = %Activity{
|
|
|
|
object: %Object{data: %{"type" => "Note"}},
|
|
|
|
data: %{"to" => [], "type" => "Create"}
|
|
|
|
}
|
|
|
|
|
2019-09-16 04:03:37 -06:00
|
|
|
topics = Topics.get_activity_topics(activity)
|
|
|
|
|
|
|
|
assert Enum.member?(topics, "direct")
|
|
|
|
refute Enum.member?(topics, "public")
|
|
|
|
refute Enum.member?(topics, "public:local")
|
|
|
|
refute Enum.member?(topics, "public:media")
|
|
|
|
refute Enum.member?(topics, "public:local:media")
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|