Merge branch 'tusooa/3205-group-actor' into 'develop'
Implement group actors See merge request pleroma/pleroma!3969
This commit is contained in:
commit
ddc321a094
11 changed files with 210 additions and 3 deletions
|
|
@ -76,6 +76,14 @@ defmodule Pleroma.Constants do
|
|||
]
|
||||
)
|
||||
|
||||
const(allowed_user_actor_types,
|
||||
do: [
|
||||
"Person",
|
||||
"Service",
|
||||
"Group"
|
||||
]
|
||||
)
|
||||
|
||||
# basic regex, just there to weed out potential mistakes
|
||||
# https://datatracker.ietf.org/doc/html/rfc2045#section-5.1
|
||||
const(mime_regex,
|
||||
|
|
|
|||
|
|
@ -39,6 +39,7 @@ defmodule Pleroma.User do
|
|||
alias Pleroma.Workers.BackgroundWorker
|
||||
|
||||
require Logger
|
||||
require Pleroma.Constants
|
||||
|
||||
@type t :: %__MODULE__{}
|
||||
@type account_status ::
|
||||
|
|
@ -579,7 +580,7 @@ defmodule Pleroma.User do
|
|||
|> validate_format(:nickname, local_nickname_regex())
|
||||
|> validate_length(:bio, max: bio_limit)
|
||||
|> validate_length(:name, min: 1, max: name_limit)
|
||||
|> validate_inclusion(:actor_type, ["Person", "Service"])
|
||||
|> validate_inclusion(:actor_type, Pleroma.Constants.allowed_user_actor_types())
|
||||
|> put_fields()
|
||||
|> put_emoji()
|
||||
|> put_change_if_present(:bio, &{:ok, parse_bio(&1, struct)})
|
||||
|
|
|
|||
|
|
@ -319,6 +319,7 @@ defmodule Pleroma.Web.ActivityPub.ActivityPub do
|
|||
{:ok, _actor} <- update_last_status_at_if_public(actor, activity),
|
||||
_ <- notify_and_stream(activity),
|
||||
:ok <- maybe_schedule_poll_notifications(activity),
|
||||
:ok <- maybe_handle_group_posts(activity),
|
||||
:ok <- maybe_federate(activity) do
|
||||
{:ok, activity}
|
||||
else
|
||||
|
|
|
|||
|
|
@ -233,6 +233,8 @@ defmodule Pleroma.Web.ActivityPub.SideEffects do
|
|||
|
||||
Pleroma.Search.add_to_index(Map.put(activity, :object, object))
|
||||
|
||||
Utils.maybe_handle_group_posts(activity)
|
||||
|
||||
meta =
|
||||
meta
|
||||
|> add_notifications(notifications)
|
||||
|
|
|
|||
|
|
@ -935,4 +935,27 @@ defmodule Pleroma.Web.ActivityPub.Utils do
|
|||
|> where([a, object: o], fragment("(?)->>'type' = 'Answer'", o.data))
|
||||
|> Repo.all()
|
||||
end
|
||||
|
||||
def maybe_handle_group_posts(activity) do
|
||||
poster = User.get_cached_by_ap_id(activity.actor)
|
||||
|
||||
mentions =
|
||||
activity.data["to"]
|
||||
|> Enum.filter(&(&1 != activity.actor))
|
||||
|
||||
mentioned_local_groups =
|
||||
User.get_all_by_ap_id(mentions)
|
||||
|> Enum.filter(fn user ->
|
||||
user.actor_type == "Group" and
|
||||
user.local and
|
||||
not User.blocks?(user, poster)
|
||||
end)
|
||||
|
||||
mentioned_local_groups
|
||||
|> Enum.each(fn group ->
|
||||
Pleroma.Web.CommonAPI.repeat(activity.id, group)
|
||||
end)
|
||||
|
||||
:ok
|
||||
end
|
||||
end
|
||||
|
|
|
|||
|
|
@ -212,7 +212,7 @@ defmodule Pleroma.Web.MastodonAPI.AccountView do
|
|||
do: user.follower_count,
|
||||
else: 0
|
||||
|
||||
bot = user.actor_type == "Service"
|
||||
bot = is_bot?(user)
|
||||
|
||||
emojis =
|
||||
Enum.map(user.emoji, fn {shortcode, raw_url} ->
|
||||
|
|
@ -468,4 +468,12 @@ defmodule Pleroma.Web.MastodonAPI.AccountView do
|
|||
|
||||
defp image_url(%{"url" => [%{"href" => href} | _]}), do: href
|
||||
defp image_url(_), do: nil
|
||||
|
||||
defp is_bot?(user) do
|
||||
# Because older and/or Mastodon clients may not recognize a Group actor properly,
|
||||
# and currently the group actor can only boost things, we should let these clients
|
||||
# think groups are bots.
|
||||
# See https://git.pleroma.social/pleroma/pleroma-meta/-/issues/14
|
||||
user.actor_type == "Service" || user.actor_type == "Group"
|
||||
end
|
||||
end
|
||||
|
|
|
|||
|
|
@ -125,7 +125,8 @@ defmodule Pleroma.Web.MastodonAPI.InstanceView do
|
|||
if Config.get([:instance, :profile_directory]) do
|
||||
"profile_directory"
|
||||
end,
|
||||
"pleroma:get:main/ostatus"
|
||||
"pleroma:get:main/ostatus",
|
||||
"pleroma:group_actors"
|
||||
]
|
||||
|> Enum.filter(& &1)
|
||||
end
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue