Merge branch 'develop' into 'bookmark-folders'
# Conflicts: # docs/development/API/differences_in_mastoapi_responses.md
This commit is contained in:
commit
2b71f4897f
47 changed files with 485 additions and 81 deletions
59
lib/pleroma/web/activity_pub/mrf/force_mention.ex
Normal file
59
lib/pleroma/web/activity_pub/mrf/force_mention.ex
Normal file
|
|
@ -0,0 +1,59 @@
|
|||
# Pleroma: A lightweight social networking server
|
||||
# Copyright © 2017-2024 Pleroma Authors <https://pleroma.social/>
|
||||
# SPDX-License-Identifier: AGPL-3.0-only
|
||||
|
||||
defmodule Pleroma.Web.ActivityPub.MRF.ForceMention do
|
||||
require Pleroma.Constants
|
||||
|
||||
alias Pleroma.Config
|
||||
alias Pleroma.Object
|
||||
alias Pleroma.User
|
||||
|
||||
@behaviour Pleroma.Web.ActivityPub.MRF.Policy
|
||||
|
||||
defp get_author(url) do
|
||||
with %Object{data: %{"actor" => actor}} <- Object.normalize(url, fetch: false),
|
||||
%User{ap_id: ap_id, nickname: nickname} <- User.get_cached_by_ap_id(actor) do
|
||||
%{"type" => "Mention", "href" => ap_id, "name" => "@#{nickname}"}
|
||||
else
|
||||
_ -> nil
|
||||
end
|
||||
end
|
||||
|
||||
defp prepend_author(tags, _, false), do: tags
|
||||
|
||||
defp prepend_author(tags, nil, _), do: tags
|
||||
|
||||
defp prepend_author(tags, url, _) do
|
||||
actor = get_author(url)
|
||||
|
||||
if not is_nil(actor) do
|
||||
[actor | tags]
|
||||
else
|
||||
tags
|
||||
end
|
||||
end
|
||||
|
||||
@impl true
|
||||
def filter(%{"type" => "Create", "object" => %{"tag" => tag} = object} = activity) do
|
||||
tag =
|
||||
tag
|
||||
|> prepend_author(
|
||||
object["inReplyTo"],
|
||||
Config.get([:mrf_force_mention, :mention_parent, true])
|
||||
)
|
||||
|> prepend_author(
|
||||
object["quoteUrl"],
|
||||
Config.get([:mrf_force_mention, :mention_quoted, true])
|
||||
)
|
||||
|> Enum.uniq()
|
||||
|
||||
{:ok, put_in(activity["object"]["tag"], tag)}
|
||||
end
|
||||
|
||||
@impl true
|
||||
def filter(object), do: {:ok, object}
|
||||
|
||||
@impl true
|
||||
def describe, do: {:ok, %{}}
|
||||
end
|
||||
|
|
@ -29,6 +29,7 @@ defmodule Pleroma.Web.ActivityPub.ObjectValidators.QuestionValidator do
|
|||
|
||||
field(:closed, ObjectValidators.DateTime)
|
||||
field(:voters, {:array, ObjectValidators.ObjectID}, default: [])
|
||||
field(:nonAnonymous, :boolean)
|
||||
embeds_many(:anyOf, QuestionOptionsValidator)
|
||||
embeds_many(:oneOf, QuestionOptionsValidator)
|
||||
end
|
||||
|
|
|
|||
|
|
@ -129,6 +129,10 @@ defmodule Pleroma.Web.ActivityPub.Publisher do
|
|||
_ -> {:error, e}
|
||||
end
|
||||
|
||||
{:error, :pool_full} ->
|
||||
Logger.debug("Publisher snoozing worker job due to full connection pool")
|
||||
{:snooze, 30}
|
||||
|
||||
e ->
|
||||
unless params[:unreachable_since], do: Instances.set_unreachable(inbox)
|
||||
Logger.metadata(activity: id, inbox: inbox)
|
||||
|
|
@ -154,19 +158,18 @@ defmodule Pleroma.Web.ActivityPub.Publisher do
|
|||
end
|
||||
end
|
||||
|
||||
defp should_federate?(inbox, public) do
|
||||
if public do
|
||||
true
|
||||
else
|
||||
%{host: host} = URI.parse(inbox)
|
||||
def should_federate?(nil, _), do: false
|
||||
def should_federate?(_, true), do: true
|
||||
|
||||
quarantined_instances =
|
||||
Config.get([:instance, :quarantined_instances], [])
|
||||
|> Pleroma.Web.ActivityPub.MRF.instance_list_from_tuples()
|
||||
|> Pleroma.Web.ActivityPub.MRF.subdomains_regex()
|
||||
def should_federate?(inbox, _) do
|
||||
%{host: host} = URI.parse(inbox)
|
||||
|
||||
!Pleroma.Web.ActivityPub.MRF.subdomain_match?(quarantined_instances, host)
|
||||
end
|
||||
quarantined_instances =
|
||||
Config.get([:instance, :quarantined_instances], [])
|
||||
|> Pleroma.Web.ActivityPub.MRF.instance_list_from_tuples()
|
||||
|> Pleroma.Web.ActivityPub.MRF.subdomains_regex()
|
||||
|
||||
!Pleroma.Web.ActivityPub.MRF.subdomain_match?(quarantined_instances, host)
|
||||
end
|
||||
|
||||
@spec recipients(User.t(), Activity.t()) :: [[User.t()]]
|
||||
|
|
|
|||
|
|
@ -56,6 +56,15 @@ defmodule Pleroma.Web.ApiSpec.Schemas.Poll do
|
|||
}
|
||||
},
|
||||
description: "Possible answers for the poll."
|
||||
},
|
||||
pleroma: %Schema{
|
||||
type: :object,
|
||||
properties: %{
|
||||
non_anonymous: %Schema{
|
||||
type: :boolean,
|
||||
description: "Can voters be publicly identified?"
|
||||
}
|
||||
}
|
||||
}
|
||||
},
|
||||
example: %{
|
||||
|
|
@ -79,7 +88,10 @@ defmodule Pleroma.Web.ApiSpec.Schemas.Poll do
|
|||
votes_count: 4
|
||||
}
|
||||
],
|
||||
emojis: []
|
||||
emojis: [],
|
||||
pleroma: %{
|
||||
non_anonymous: false
|
||||
}
|
||||
}
|
||||
})
|
||||
end
|
||||
|
|
|
|||
|
|
@ -28,6 +28,7 @@ defmodule Pleroma.Web.MastodonAPI.InstanceView do
|
|||
|> to_string,
|
||||
registrations: Keyword.get(instance, :registrations_open),
|
||||
approval_required: Keyword.get(instance, :account_approval_required),
|
||||
contact_account: contact_account(Keyword.get(instance, :contact_username)),
|
||||
configuration: configuration(),
|
||||
# Extra (not present in Mastodon):
|
||||
max_toot_chars: Keyword.get(instance, :limit),
|
||||
|
|
@ -63,11 +64,12 @@ defmodule Pleroma.Web.MastodonAPI.InstanceView do
|
|||
registrations: %{
|
||||
enabled: Keyword.get(instance, :registrations_open),
|
||||
approval_required: Keyword.get(instance, :account_approval_required),
|
||||
message: nil
|
||||
message: nil,
|
||||
url: nil
|
||||
},
|
||||
contact: %{
|
||||
email: Keyword.get(instance, :email),
|
||||
account: nil
|
||||
account: contact_account(Keyword.get(instance, :contact_username))
|
||||
},
|
||||
# Extra (not present in Mastodon):
|
||||
pleroma: pleroma_configuration2(instance)
|
||||
|
|
@ -78,7 +80,8 @@ defmodule Pleroma.Web.MastodonAPI.InstanceView do
|
|||
%{
|
||||
title: Keyword.get(instance, :name),
|
||||
version: "#{@mastodon_api_level} (compatible; #{Pleroma.Application.named_version()})",
|
||||
languages: Keyword.get(instance, :languages, ["en"])
|
||||
languages: Keyword.get(instance, :languages, ["en"]),
|
||||
rules: []
|
||||
}
|
||||
end
|
||||
|
||||
|
|
@ -168,15 +171,35 @@ defmodule Pleroma.Web.MastodonAPI.InstanceView do
|
|||
}
|
||||
end
|
||||
|
||||
defp contact_account(nil), do: nil
|
||||
|
||||
defp contact_account("@" <> username) do
|
||||
contact_account(username)
|
||||
end
|
||||
|
||||
defp contact_account(username) do
|
||||
user = Pleroma.User.get_cached_by_nickname(username)
|
||||
|
||||
if user do
|
||||
Pleroma.Web.MastodonAPI.AccountView.render("show.json", %{user: user, for: nil})
|
||||
else
|
||||
nil
|
||||
end
|
||||
end
|
||||
|
||||
defp configuration do
|
||||
%{
|
||||
accounts: %{
|
||||
max_featured_tags: 0
|
||||
},
|
||||
statuses: %{
|
||||
max_characters: Config.get([:instance, :limit]),
|
||||
max_media_attachments: Config.get([:instance, :max_media_attachments])
|
||||
},
|
||||
media_attachments: %{
|
||||
image_size_limit: Config.get([:instance, :upload_limit]),
|
||||
video_size_limit: Config.get([:instance, :upload_limit])
|
||||
video_size_limit: Config.get([:instance, :upload_limit]),
|
||||
supported_mime_types: ["application/octet-stream"]
|
||||
},
|
||||
polls: %{
|
||||
max_options: Config.get([:instance, :poll_limits, :max_options]),
|
||||
|
|
@ -190,7 +213,13 @@ defmodule Pleroma.Web.MastodonAPI.InstanceView do
|
|||
defp configuration2 do
|
||||
configuration()
|
||||
|> Map.merge(%{
|
||||
urls: %{streaming: Pleroma.Web.Endpoint.websocket_url()}
|
||||
urls: %{
|
||||
streaming: Pleroma.Web.Endpoint.websocket_url(),
|
||||
status: Config.get([:instance, :status_page])
|
||||
},
|
||||
vapid: %{
|
||||
public_key: Keyword.get(Pleroma.Web.Push.vapid_config(), :public_key)
|
||||
}
|
||||
})
|
||||
end
|
||||
|
||||
|
|
|
|||
|
|
@ -21,7 +21,10 @@ defmodule Pleroma.Web.MastodonAPI.PollView do
|
|||
votes_count: votes_count,
|
||||
voters_count: voters_count(object),
|
||||
options: options,
|
||||
emojis: Pleroma.Web.MastodonAPI.StatusView.build_emojis(object.data["emoji"])
|
||||
emojis: Pleroma.Web.MastodonAPI.StatusView.build_emojis(object.data["emoji"]),
|
||||
pleroma: %{
|
||||
non_anonymous: object.data["nonAnonymous"] || false
|
||||
}
|
||||
}
|
||||
|
||||
if params[:for] do
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue