Allow group actors to boost posts
This commit is contained in:
parent
7a58ddfa48
commit
5459bbc1ef
|
@ -319,6 +319,7 @@ defp do_create(%{to: to, actor: actor, context: context, object: object} = param
|
||||||
{:ok, _actor} <- update_last_status_at_if_public(actor, activity),
|
{:ok, _actor} <- update_last_status_at_if_public(actor, activity),
|
||||||
_ <- notify_and_stream(activity),
|
_ <- notify_and_stream(activity),
|
||||||
:ok <- maybe_schedule_poll_notifications(activity),
|
:ok <- maybe_schedule_poll_notifications(activity),
|
||||||
|
:ok <- maybe_handle_group_posts(activity),
|
||||||
:ok <- maybe_federate(activity) do
|
:ok <- maybe_federate(activity) do
|
||||||
{:ok, activity}
|
{:ok, activity}
|
||||||
else
|
else
|
||||||
|
|
|
@ -233,6 +233,8 @@ def handle(%{data: %{"type" => "Create"}} = activity, meta) do
|
||||||
|
|
||||||
Pleroma.Search.add_to_index(Map.put(activity, :object, object))
|
Pleroma.Search.add_to_index(Map.put(activity, :object, object))
|
||||||
|
|
||||||
|
Utils.maybe_handle_group_posts(activity)
|
||||||
|
|
||||||
meta =
|
meta =
|
||||||
meta
|
meta
|
||||||
|> add_notifications(notifications)
|
|> add_notifications(notifications)
|
||||||
|
|
|
@ -935,4 +935,21 @@ def get_existing_votes(actor, %{data: %{"id" => id}}) do
|
||||||
|> where([a, object: o], fragment("(?)->>'type' = 'Answer'", o.data))
|
|> where([a, object: o], fragment("(?)->>'type' = 'Answer'", o.data))
|
||||||
|> Repo.all()
|
|> Repo.all()
|
||||||
end
|
end
|
||||||
|
|
||||||
|
def maybe_handle_group_posts(activity) do
|
||||||
|
mentions =
|
||||||
|
activity.data["to"]
|
||||||
|
|> Enum.filter(&(&1 != activity.actor))
|
||||||
|
|
||||||
|
mentioned_local_groups =
|
||||||
|
User.get_all_by_ap_id(mentions)
|
||||||
|
|> Enum.filter(&(&1.actor_type == "Group" and &1.local))
|
||||||
|
|
||||||
|
mentioned_local_groups
|
||||||
|
|> Enum.each(fn group ->
|
||||||
|
Pleroma.Web.CommonAPI.repeat(activity.id, group)
|
||||||
|
end)
|
||||||
|
|
||||||
|
:ok
|
||||||
|
end
|
||||||
end
|
end
|
||||||
|
|
|
@ -26,8 +26,15 @@ defmodule Pleroma.Web.CommonAPITest do
|
||||||
import Mox
|
import Mox
|
||||||
import Pleroma.Factory
|
import Pleroma.Factory
|
||||||
|
|
||||||
|
require Pleroma.Activity.Queries
|
||||||
require Pleroma.Constants
|
require Pleroma.Constants
|
||||||
|
|
||||||
|
defp get_announces_of_object(%{data: %{"id" => id}} = _object) do
|
||||||
|
Pleroma.Activity.Queries.by_type("Announce")
|
||||||
|
|> Pleroma.Activity.Queries.by_object_id(id)
|
||||||
|
|> Pleroma.Repo.all()
|
||||||
|
end
|
||||||
|
|
||||||
setup_all do
|
setup_all do
|
||||||
Tesla.Mock.mock_global(fn env -> apply(HttpRequestMock, :request, [env]) end)
|
Tesla.Mock.mock_global(fn env -> apply(HttpRequestMock, :request, [env]) end)
|
||||||
:ok
|
:ok
|
||||||
|
@ -1835,4 +1842,46 @@ test "respects MRF" do
|
||||||
assert Map.has_key?(updated_object.data, "updated")
|
assert Map.has_key?(updated_object.data, "updated")
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
describe "Group actors" do
|
||||||
|
setup do
|
||||||
|
poster = insert(:user)
|
||||||
|
group = insert(:user, actor_type: "Group")
|
||||||
|
other_group = insert(:user, actor_type: "Group")
|
||||||
|
%{poster: poster, group: group, other_group: other_group}
|
||||||
|
end
|
||||||
|
|
||||||
|
test "it boosts public posts", %{poster: poster, group: group} do
|
||||||
|
{:ok, post} = CommonAPI.post(poster, %{status: "hey @#{group.nickname}"})
|
||||||
|
|
||||||
|
announces = get_announces_of_object(post.object)
|
||||||
|
assert [_] = announces
|
||||||
|
end
|
||||||
|
|
||||||
|
test "it does not boost private posts", %{poster: poster, group: group} do
|
||||||
|
{:ok, private_post} =
|
||||||
|
CommonAPI.post(poster, %{status: "hey @#{group.nickname}", visibility: "private"})
|
||||||
|
|
||||||
|
assert [] = get_announces_of_object(private_post.object)
|
||||||
|
end
|
||||||
|
|
||||||
|
test "remote groups do not boost any posts", %{poster: poster} do
|
||||||
|
remote_group =
|
||||||
|
insert(:user, actor_type: "Group", local: false, nickname: "remote@example.com")
|
||||||
|
|
||||||
|
{:ok, post} = CommonAPI.post(poster, %{status: "hey @#{User.full_nickname(remote_group)}"})
|
||||||
|
assert remote_group.ap_id in post.data["to"]
|
||||||
|
|
||||||
|
announces = get_announces_of_object(post.object)
|
||||||
|
assert [] = announces
|
||||||
|
end
|
||||||
|
|
||||||
|
test "multiple groups mentioned", %{poster: poster, group: group, other_group: other_group} do
|
||||||
|
{:ok, post} =
|
||||||
|
CommonAPI.post(poster, %{status: "hey @#{group.nickname} @#{other_group.nickname}"})
|
||||||
|
|
||||||
|
announces = get_announces_of_object(post.object)
|
||||||
|
assert [_, _] = announces
|
||||||
|
end
|
||||||
|
end
|
||||||
end
|
end
|
||||||
|
|
Loading…
Reference in New Issue