Merge branch 'develop' into activitypub-bot-federation
This commit is contained in:
commit
f5dd75b1a3
169 changed files with 6670 additions and 811 deletions
|
|
@ -537,9 +537,12 @@ defmodule Pleroma.Web.ActivityPub.ActivityPub do
|
|||
# and extra sorting on "activities.id DESC NULLS LAST" would worse the query plan
|
||||
opts = Map.put(opts, :skip_extra_order, true)
|
||||
|
||||
Pagination.fetch_paginated(query, opts, pagination)
|
||||
Pagination.fetch_paginated(query, opts, pagination, pagination_binding(opts))
|
||||
end
|
||||
|
||||
defp pagination_binding(%{favorited_by: _}), do: :favorited_activity
|
||||
defp pagination_binding(_), do: nil
|
||||
|
||||
def fetch_activities(recipients, opts \\ %{}, pagination \\ :keyset) do
|
||||
list_memberships = Pleroma.List.memberships(opts[:user])
|
||||
|
||||
|
|
@ -786,6 +789,8 @@ defmodule Pleroma.Web.ActivityPub.ActivityPub do
|
|||
|
||||
defp restrict_since(query, %{since_id: ""}), do: query
|
||||
|
||||
defp restrict_since(query, %{favorited_by: _, since_id: _}), do: query
|
||||
|
||||
defp restrict_since(query, %{since_id: since_id}) do
|
||||
from(activity in query, where: activity.id > ^since_id)
|
||||
end
|
||||
|
|
@ -893,14 +898,22 @@ defmodule Pleroma.Web.ActivityPub.ActivityPub do
|
|||
|> Repo.all()
|
||||
|
||||
# Note: NO extra ordering should be done on "activities.id desc nulls last" for optimal plan
|
||||
from(
|
||||
[_activity, object] in query,
|
||||
join: hto in "hashtags_objects",
|
||||
on: hto.object_id == object.id,
|
||||
where: hto.hashtag_id in ^hashtag_ids,
|
||||
distinct: [desc: object.id],
|
||||
order_by: [desc: object.id]
|
||||
)
|
||||
query =
|
||||
from(
|
||||
[_activity, object] in query,
|
||||
join: hto in "hashtags_objects",
|
||||
on: hto.object_id == object.id,
|
||||
where: hto.hashtag_id in ^hashtag_ids
|
||||
)
|
||||
|
||||
if is_nil(query.distinct) do
|
||||
from([_activity, object] in query,
|
||||
distinct: [desc: object.id],
|
||||
order_by: [desc: object.id]
|
||||
)
|
||||
else
|
||||
query
|
||||
end
|
||||
end
|
||||
|
||||
defp restrict_hashtag_any(query, %{tag: tag}) when is_binary(tag) do
|
||||
|
|
@ -1012,9 +1025,31 @@ defmodule Pleroma.Web.ActivityPub.ActivityPub do
|
|||
defp restrict_assigned_account(query, _), do: query
|
||||
|
||||
defp restrict_favorited_by(query, %{favorited_by: ap_id}) do
|
||||
newer_favorite =
|
||||
from(newer_favorite in Activity,
|
||||
where: newer_favorite.actor == ^ap_id,
|
||||
where: newer_favorite.id > parent_as(:favorited_activity).id,
|
||||
where: fragment("?->>'type' = ?", newer_favorite.data, "Like"),
|
||||
where:
|
||||
fragment(
|
||||
"associated_object_id(?) = associated_object_id(?)",
|
||||
newer_favorite.data,
|
||||
parent_as(:favorited_activity).data
|
||||
),
|
||||
select: 1
|
||||
)
|
||||
|
||||
from(
|
||||
[_activity, object] in query,
|
||||
where: fragment("(?)->'likes' \\? (?)", object.data, ^ap_id)
|
||||
[activity, object: object] in query,
|
||||
join: favorited_activity in Activity,
|
||||
as: :favorited_activity,
|
||||
on:
|
||||
favorited_activity.actor == ^ap_id and
|
||||
fragment("?->>'type' = ?", favorited_activity.data, "Like") and
|
||||
fragment("associated_object_id(?) = (?)->>'id'", favorited_activity.data, object.data),
|
||||
where: fragment("(?)->'likes' \\? (?)", object.data, ^ap_id),
|
||||
where: not exists(subquery(newer_favorite)),
|
||||
select: %Activity{activity | pagination_id: favorited_activity.id}
|
||||
)
|
||||
end
|
||||
|
||||
|
|
|
|||
|
|
@ -6,6 +6,8 @@ defmodule Pleroma.Web.ActivityPub.MRF.ActivityExpirationPolicy do
|
|||
@moduledoc "Adds expiration to all local Create activities"
|
||||
@behaviour Pleroma.Web.ActivityPub.MRF.Policy
|
||||
|
||||
use Pleroma.Web.ActivityPub.MRF.Policy
|
||||
|
||||
@impl true
|
||||
def filter(activity) do
|
||||
activity =
|
||||
|
|
|
|||
|
|
@ -3,11 +3,11 @@
|
|||
# SPDX-License-Identifier: AGPL-3.0-only
|
||||
|
||||
defmodule Pleroma.Web.ActivityPub.MRF.AntiFollowbotPolicy do
|
||||
@moduledoc "Prevent followbots from following with a bit of heuristic"
|
||||
@behaviour Pleroma.Web.ActivityPub.MRF.Policy
|
||||
alias Pleroma.User
|
||||
|
||||
@moduledoc "Prevent followbots from following with a bit of heuristic"
|
||||
|
||||
@behaviour Pleroma.Web.ActivityPub.MRF.Policy
|
||||
use Pleroma.Web.ActivityPub.MRF.Policy
|
||||
|
||||
# XXX: this should become User.normalize_by_ap_id() or similar, really.
|
||||
defp normalize_by_ap_id(%{"id" => id}), do: User.get_cached_by_ap_id(id)
|
||||
|
|
|
|||
|
|
@ -3,9 +3,11 @@
|
|||
# SPDX-License-Identifier: AGPL-3.0-only
|
||||
|
||||
defmodule Pleroma.Web.ActivityPub.MRF.AntiLinkSpamPolicy do
|
||||
@behaviour Pleroma.Web.ActivityPub.MRF.Policy
|
||||
|
||||
alias Pleroma.User
|
||||
|
||||
@behaviour Pleroma.Web.ActivityPub.MRF.Policy
|
||||
use Pleroma.Web.ActivityPub.MRF.Policy
|
||||
|
||||
require Logger
|
||||
|
||||
|
|
|
|||
|
|
@ -3,11 +3,13 @@
|
|||
# SPDX-License-Identifier: AGPL-3.0-only
|
||||
|
||||
defmodule Pleroma.Web.ActivityPub.MRF.AntiMentionSpamPolicy do
|
||||
@behaviour Pleroma.Web.ActivityPub.MRF.Policy
|
||||
|
||||
alias Pleroma.Config
|
||||
alias Pleroma.User
|
||||
require Pleroma.Constants
|
||||
|
||||
@behaviour Pleroma.Web.ActivityPub.MRF.Policy
|
||||
use Pleroma.Web.ActivityPub.MRF.Policy
|
||||
|
||||
defp user_has_posted?(%User{} = u), do: u.note_count > 0
|
||||
|
||||
|
|
|
|||
|
|
@ -3,10 +3,12 @@
|
|||
# SPDX-License-Identifier: AGPL-3.0-only
|
||||
|
||||
defmodule Pleroma.Web.ActivityPub.MRF.DropPolicy do
|
||||
require Logger
|
||||
@moduledoc "Drop and log everything received"
|
||||
@behaviour Pleroma.Web.ActivityPub.MRF.Policy
|
||||
|
||||
require Logger
|
||||
use Pleroma.Web.ActivityPub.MRF.Policy
|
||||
|
||||
@impl true
|
||||
def filter(activity) do
|
||||
Logger.debug("REJECTING #{inspect(activity)}")
|
||||
|
|
|
|||
|
|
@ -3,6 +3,8 @@
|
|||
# SPDX-License-Identifier: AGPL-3.0-only
|
||||
|
||||
defmodule Pleroma.Web.ActivityPub.MRF.EmojiPolicy do
|
||||
@behaviour Pleroma.Web.ActivityPub.MRF.Policy
|
||||
|
||||
require Pleroma.Constants
|
||||
|
||||
alias Pleroma.Object.Updater
|
||||
|
|
@ -10,7 +12,7 @@ defmodule Pleroma.Web.ActivityPub.MRF.EmojiPolicy do
|
|||
|
||||
@moduledoc "Reject or force-unlisted emojis with certain URLs or names"
|
||||
|
||||
@behaviour Pleroma.Web.ActivityPub.MRF.Policy
|
||||
use Pleroma.Web.ActivityPub.MRF.Policy
|
||||
|
||||
defp config_remove_url do
|
||||
Pleroma.Config.get([:mrf_emoji, :remove_url], [])
|
||||
|
|
|
|||
|
|
@ -3,11 +3,13 @@
|
|||
# SPDX-License-Identifier: AGPL-3.0-only
|
||||
|
||||
defmodule Pleroma.Web.ActivityPub.MRF.EnsureRePrepended do
|
||||
alias Pleroma.Object
|
||||
|
||||
@moduledoc "Ensure a re: is prepended on replies to a post with a Subject"
|
||||
@behaviour Pleroma.Web.ActivityPub.MRF.Policy
|
||||
|
||||
alias Pleroma.Object
|
||||
|
||||
use Pleroma.Web.ActivityPub.MRF.Policy
|
||||
|
||||
@reply_prefix Regex.compile!("^re:[[:space:]]*", [:caseless])
|
||||
|
||||
def history_awareness, do: :auto
|
||||
|
|
|
|||
|
|
@ -4,12 +4,15 @@
|
|||
|
||||
defmodule Pleroma.Web.ActivityPub.MRF.FollowBotPolicy do
|
||||
@behaviour Pleroma.Web.ActivityPub.MRF.Policy
|
||||
|
||||
alias Pleroma.Config
|
||||
alias Pleroma.User
|
||||
alias Pleroma.Web.CommonAPI
|
||||
|
||||
require Logger
|
||||
|
||||
use Pleroma.Web.ActivityPub.MRF.Policy
|
||||
|
||||
@impl true
|
||||
def filter(activity) do
|
||||
with follower_nickname <- Config.get([:mrf_follow_bot, :follower_nickname]),
|
||||
|
|
|
|||
|
|
@ -3,9 +3,12 @@
|
|||
# SPDX-License-Identifier: AGPL-3.0-only
|
||||
|
||||
defmodule Pleroma.Web.ActivityPub.MRF.ForceBotUnlistedPolicy do
|
||||
alias Pleroma.User
|
||||
@behaviour Pleroma.Web.ActivityPub.MRF.Policy
|
||||
@moduledoc "Remove bot posts from federated timeline"
|
||||
@behaviour Pleroma.Web.ActivityPub.MRF.Policy
|
||||
|
||||
alias Pleroma.User
|
||||
|
||||
use Pleroma.Web.ActivityPub.MRF.Policy
|
||||
|
||||
require Pleroma.Constants
|
||||
|
||||
|
|
|
|||
|
|
@ -3,13 +3,14 @@
|
|||
# SPDX-License-Identifier: AGPL-3.0-only
|
||||
|
||||
defmodule Pleroma.Web.ActivityPub.MRF.ForceMention do
|
||||
@behaviour Pleroma.Web.ActivityPub.MRF.Policy
|
||||
require Pleroma.Constants
|
||||
|
||||
alias Pleroma.Config
|
||||
alias Pleroma.Object
|
||||
alias Pleroma.User
|
||||
|
||||
@behaviour Pleroma.Web.ActivityPub.MRF.Policy
|
||||
use Pleroma.Web.ActivityPub.MRF.Policy
|
||||
|
||||
defp get_author(url) do
|
||||
with %Object{data: %{"actor" => actor}} <- Object.normalize(url, fetch: false),
|
||||
|
|
|
|||
|
|
@ -3,13 +3,15 @@
|
|||
# SPDX-License-Identifier: AGPL-3.0-only
|
||||
|
||||
defmodule Pleroma.Web.ActivityPub.MRF.ForceMentionsInContent do
|
||||
@behaviour Pleroma.Web.ActivityPub.MRF.Policy
|
||||
|
||||
require Pleroma.Constants
|
||||
|
||||
alias Pleroma.Formatter
|
||||
alias Pleroma.Object
|
||||
alias Pleroma.User
|
||||
|
||||
@behaviour Pleroma.Web.ActivityPub.MRF.Policy
|
||||
use Pleroma.Web.ActivityPub.MRF.Policy
|
||||
|
||||
@impl true
|
||||
def history_awareness, do: :auto
|
||||
|
|
|
|||
|
|
@ -3,6 +3,8 @@
|
|||
# SPDX-License-Identifier: AGPL-3.0-only
|
||||
|
||||
defmodule Pleroma.Web.ActivityPub.MRF.HashtagPolicy do
|
||||
@behaviour Pleroma.Web.ActivityPub.MRF.Policy
|
||||
|
||||
require Pleroma.Constants
|
||||
|
||||
alias Pleroma.Config
|
||||
|
|
@ -14,7 +16,7 @@ defmodule Pleroma.Web.ActivityPub.MRF.HashtagPolicy do
|
|||
Note: This MRF Policy is always enabled, if you want to disable it you have to set empty lists.
|
||||
"""
|
||||
|
||||
@behaviour Pleroma.Web.ActivityPub.MRF.Policy
|
||||
use Pleroma.Web.ActivityPub.MRF.Policy
|
||||
|
||||
@impl true
|
||||
def history_awareness, do: :manual
|
||||
|
|
|
|||
|
|
@ -3,13 +3,14 @@
|
|||
# SPDX-License-Identifier: AGPL-3.0-only
|
||||
|
||||
defmodule Pleroma.Web.ActivityPub.MRF.HellthreadPolicy do
|
||||
@moduledoc "Block activities with too much mentions (configurable)"
|
||||
@behaviour Pleroma.Web.ActivityPub.MRF.Policy
|
||||
|
||||
alias Pleroma.User
|
||||
|
||||
require Pleroma.Constants
|
||||
|
||||
@moduledoc "Block activities with too much mentions (configurable)"
|
||||
|
||||
@behaviour Pleroma.Web.ActivityPub.MRF.Policy
|
||||
use Pleroma.Web.ActivityPub.MRF.Policy
|
||||
|
||||
defp delist_activity(activity, threshold) when threshold > 0 do
|
||||
follower_collection = User.get_cached_by_ap_id(activity["actor"]).follower_address
|
||||
|
|
|
|||
|
|
@ -6,6 +6,8 @@ defmodule Pleroma.Web.ActivityPub.MRF.InlineQuotePolicy do
|
|||
@moduledoc "Force a quote line into the message content."
|
||||
@behaviour Pleroma.Web.ActivityPub.MRF.Policy
|
||||
|
||||
use Pleroma.Web.ActivityPub.MRF.Policy
|
||||
|
||||
defp build_inline_quote(template, url) do
|
||||
quote_line = String.replace(template, "{url}", "<a href=\"#{url}\">#{url}</a>")
|
||||
|
||||
|
|
|
|||
|
|
@ -3,13 +3,14 @@
|
|||
# SPDX-License-Identifier: AGPL-3.0-only
|
||||
|
||||
defmodule Pleroma.Web.ActivityPub.MRF.KeywordPolicy do
|
||||
@moduledoc "Reject or Word-Replace activities with a keyword or regex"
|
||||
@behaviour Pleroma.Web.ActivityPub.MRF.Policy
|
||||
|
||||
require Pleroma.Constants
|
||||
|
||||
alias Pleroma.Web.ActivityPub.MRF.Utils
|
||||
|
||||
@moduledoc "Reject or Word-Replace activities with a keyword or regex"
|
||||
|
||||
@behaviour Pleroma.Web.ActivityPub.MRF.Policy
|
||||
use Pleroma.Web.ActivityPub.MRF.Policy
|
||||
|
||||
defp string_matches?(string, pattern) when is_binary(pattern) do
|
||||
String.contains?(string, pattern)
|
||||
|
|
|
|||
|
|
@ -6,6 +6,8 @@ defmodule Pleroma.Web.ActivityPub.MRF.MediaProxyWarmingPolicy do
|
|||
@moduledoc "Preloads any attachments in the MediaProxy cache by prefetching them"
|
||||
@behaviour Pleroma.Web.ActivityPub.MRF.Policy
|
||||
|
||||
use Pleroma.Web.ActivityPub.MRF.Policy
|
||||
|
||||
alias Pleroma.HTTP
|
||||
alias Pleroma.Web.MediaProxy
|
||||
|
||||
|
|
|
|||
|
|
@ -4,9 +4,10 @@
|
|||
|
||||
defmodule Pleroma.Web.ActivityPub.MRF.MentionPolicy do
|
||||
@moduledoc "Block activities which mention a user"
|
||||
|
||||
@behaviour Pleroma.Web.ActivityPub.MRF.Policy
|
||||
|
||||
use Pleroma.Web.ActivityPub.MRF.Policy
|
||||
|
||||
@impl true
|
||||
def filter(%{"type" => "Create"} = activity) do
|
||||
reject_actors = Pleroma.Config.get([:mrf_mention, :actors], [])
|
||||
|
|
|
|||
|
|
@ -6,6 +6,8 @@ defmodule Pleroma.Web.ActivityPub.MRF.NoEmptyPolicy do
|
|||
@moduledoc "Filter local activities which have no content"
|
||||
@behaviour Pleroma.Web.ActivityPub.MRF.Policy
|
||||
|
||||
use Pleroma.Web.ActivityPub.MRF.Policy
|
||||
|
||||
alias Pleroma.Web.Endpoint
|
||||
|
||||
@impl true
|
||||
|
|
|
|||
|
|
@ -6,6 +6,8 @@ defmodule Pleroma.Web.ActivityPub.MRF.NoOpPolicy do
|
|||
@moduledoc "Does nothing (lets the messages go through unmodified)"
|
||||
@behaviour Pleroma.Web.ActivityPub.MRF.Policy
|
||||
|
||||
use Pleroma.Web.ActivityPub.MRF.Policy
|
||||
|
||||
@impl true
|
||||
def filter(activity) do
|
||||
{:ok, activity}
|
||||
|
|
|
|||
|
|
@ -6,6 +6,8 @@ defmodule Pleroma.Web.ActivityPub.MRF.NoPlaceholderTextPolicy do
|
|||
@moduledoc "Ensure no content placeholder is present (such as the dot from mastodon)"
|
||||
@behaviour Pleroma.Web.ActivityPub.MRF.Policy
|
||||
|
||||
use Pleroma.Web.ActivityPub.MRF.Policy
|
||||
|
||||
@impl true
|
||||
def history_awareness, do: :auto
|
||||
|
||||
|
|
|
|||
|
|
@ -4,9 +4,11 @@
|
|||
|
||||
defmodule Pleroma.Web.ActivityPub.MRF.NormalizeMarkup do
|
||||
@moduledoc "Scrub configured hypertext markup"
|
||||
@behaviour Pleroma.Web.ActivityPub.MRF.Policy
|
||||
|
||||
alias Pleroma.HTML
|
||||
|
||||
@behaviour Pleroma.Web.ActivityPub.MRF.Policy
|
||||
use Pleroma.Web.ActivityPub.MRF.Policy
|
||||
|
||||
@impl true
|
||||
def history_awareness, do: :auto
|
||||
|
|
|
|||
|
|
@ -38,6 +38,8 @@ defmodule Pleroma.Web.ActivityPub.MRF.NsfwApiPolicy do
|
|||
- `unlist`: Unlist all detected NSFW content? Default: `false`
|
||||
- `reject`: Reject all detected NSFW content (takes precedence)? Default: `false`
|
||||
"""
|
||||
@behaviour Pleroma.Web.ActivityPub.MRF.Policy
|
||||
|
||||
alias Pleroma.Config
|
||||
alias Pleroma.Constants
|
||||
alias Pleroma.HTTP
|
||||
|
|
@ -46,7 +48,8 @@ defmodule Pleroma.Web.ActivityPub.MRF.NsfwApiPolicy do
|
|||
require Logger
|
||||
require Pleroma.Constants
|
||||
|
||||
@behaviour Pleroma.Web.ActivityPub.MRF.Policy
|
||||
use Pleroma.Web.ActivityPub.MRF.Policy
|
||||
|
||||
@policy :mrf_nsfw_api
|
||||
|
||||
def build_request_url(url) do
|
||||
|
|
|
|||
|
|
@ -3,13 +3,15 @@
|
|||
# SPDX-License-Identifier: AGPL-3.0-only
|
||||
|
||||
defmodule Pleroma.Web.ActivityPub.MRF.ObjectAgePolicy do
|
||||
@moduledoc "Filter activities depending on their age"
|
||||
@behaviour Pleroma.Web.ActivityPub.MRF.Policy
|
||||
|
||||
alias Pleroma.Config
|
||||
alias Pleroma.User
|
||||
|
||||
require Pleroma.Constants
|
||||
|
||||
@moduledoc "Filter activities depending on their age"
|
||||
@behaviour Pleroma.Web.ActivityPub.MRF.Policy
|
||||
use Pleroma.Web.ActivityPub.MRF.Policy
|
||||
|
||||
defp check_date(%{"object" => %{"published" => published}} = activity) do
|
||||
with %DateTime{} = now <- DateTime.utc_now(),
|
||||
|
|
|
|||
|
|
@ -15,4 +15,12 @@ defmodule Pleroma.Web.ActivityPub.MRF.Policy do
|
|||
}
|
||||
@callback history_awareness() :: :auto | :manual
|
||||
@optional_callbacks config_description: 0, history_awareness: 0, id_filter: 1
|
||||
|
||||
defmacro __using__(_) do
|
||||
quote do
|
||||
# Otherwise Pleroma.Docs.Generator.list_behaviour_implementations fails
|
||||
# since the Elixir compiler doesn't automatically load the module since v1.19.
|
||||
@compile {:autoload, true}
|
||||
end
|
||||
end
|
||||
end
|
||||
|
|
|
|||
|
|
@ -6,11 +6,13 @@ defmodule Pleroma.Web.ActivityPub.MRF.QuietReply do
|
|||
@moduledoc """
|
||||
QuietReply alters the scope of activities from local users when replying by enforcing them to be "Unlisted" or "Quiet Public". This delivers the activity to all the expected recipients and instances, but it will not be published in the Federated / The Whole Known Network timelines. It will still be published to the Home timelines of the user's followers and visible to anyone who opens the thread.
|
||||
"""
|
||||
@behaviour Pleroma.Web.ActivityPub.MRF.Policy
|
||||
|
||||
require Pleroma.Constants
|
||||
|
||||
alias Pleroma.User
|
||||
|
||||
@behaviour Pleroma.Web.ActivityPub.MRF.Policy
|
||||
use Pleroma.Web.ActivityPub.MRF.Policy
|
||||
|
||||
@impl true
|
||||
def history_awareness, do: :auto
|
||||
|
|
|
|||
|
|
@ -6,6 +6,8 @@ defmodule Pleroma.Web.ActivityPub.MRF.QuoteToLinkTagPolicy do
|
|||
@moduledoc "Force a Link tag for posts quoting another post. (may break outgoing federation of quote posts with older Pleroma versions)"
|
||||
@behaviour Pleroma.Web.ActivityPub.MRF.Policy
|
||||
|
||||
use Pleroma.Web.ActivityPub.MRF.Policy
|
||||
|
||||
alias Pleroma.Web.ActivityPub.ObjectValidators.CommonFixes
|
||||
|
||||
require Pleroma.Constants
|
||||
|
|
|
|||
|
|
@ -4,11 +4,12 @@
|
|||
|
||||
defmodule Pleroma.Web.ActivityPub.MRF.RejectNonPublic do
|
||||
@moduledoc "Rejects non-public (followers-only, direct) activities"
|
||||
@behaviour Pleroma.Web.ActivityPub.MRF.Policy
|
||||
|
||||
alias Pleroma.Config
|
||||
alias Pleroma.User
|
||||
|
||||
@behaviour Pleroma.Web.ActivityPub.MRF.Policy
|
||||
use Pleroma.Web.ActivityPub.MRF.Policy
|
||||
|
||||
require Pleroma.Constants
|
||||
|
||||
|
|
|
|||
|
|
@ -2,6 +2,8 @@ defmodule Pleroma.Web.ActivityPub.MRF.RemoteReportPolicy do
|
|||
@moduledoc "Drop remote reports if they don't contain enough information."
|
||||
@behaviour Pleroma.Web.ActivityPub.MRF.Policy
|
||||
|
||||
use Pleroma.Web.ActivityPub.MRF.Policy
|
||||
|
||||
alias Pleroma.Config
|
||||
|
||||
@impl true
|
||||
|
|
|
|||
|
|
@ -6,6 +6,8 @@ defmodule Pleroma.Web.ActivityPub.MRF.SimplePolicy do
|
|||
@moduledoc "Filter activities depending on their origin instance"
|
||||
@behaviour Pleroma.Web.ActivityPub.MRF.Policy
|
||||
|
||||
use Pleroma.Web.ActivityPub.MRF.Policy
|
||||
|
||||
alias Pleroma.Config
|
||||
alias Pleroma.FollowingRelationship
|
||||
alias Pleroma.User
|
||||
|
|
|
|||
|
|
@ -3,12 +3,14 @@
|
|||
# SPDX-License-Identifier: AGPL-3.0-only
|
||||
|
||||
defmodule Pleroma.Web.ActivityPub.MRF.StealEmojiPolicy do
|
||||
@moduledoc "Detect new emojis by their shortcode and steals them"
|
||||
@behaviour Pleroma.Web.ActivityPub.MRF.Policy
|
||||
|
||||
require Logger
|
||||
|
||||
alias Pleroma.Config
|
||||
|
||||
@moduledoc "Detect new emojis by their shortcode and steals them"
|
||||
@behaviour Pleroma.Web.ActivityPub.MRF.Policy
|
||||
use Pleroma.Web.ActivityPub.MRF.Policy
|
||||
|
||||
defp accept_host?(host), do: host in Config.get([:mrf_steal_emoji, :hosts], [])
|
||||
|
||||
|
|
|
|||
|
|
@ -3,12 +3,14 @@
|
|||
# SPDX-License-Identifier: AGPL-3.0-only
|
||||
|
||||
defmodule Pleroma.Web.ActivityPub.MRF.SubchainPolicy do
|
||||
@behaviour Pleroma.Web.ActivityPub.MRF.Policy
|
||||
|
||||
alias Pleroma.Config
|
||||
alias Pleroma.Web.ActivityPub.MRF
|
||||
|
||||
require Logger
|
||||
|
||||
@behaviour Pleroma.Web.ActivityPub.MRF.Policy
|
||||
use Pleroma.Web.ActivityPub.MRF.Policy
|
||||
|
||||
defp lookup_subchain(actor) do
|
||||
with matches <- Config.get([:mrf_subchain, :match_actor]),
|
||||
|
|
|
|||
|
|
@ -3,8 +3,6 @@
|
|||
# SPDX-License-Identifier: AGPL-3.0-only
|
||||
|
||||
defmodule Pleroma.Web.ActivityPub.MRF.TagPolicy do
|
||||
alias Pleroma.User
|
||||
@behaviour Pleroma.Web.ActivityPub.MRF.Policy
|
||||
@moduledoc """
|
||||
Apply policies based on user tags
|
||||
|
||||
|
|
@ -18,6 +16,11 @@ defmodule Pleroma.Web.ActivityPub.MRF.TagPolicy do
|
|||
- `mrf_tag:disable-remote-subscription`: Reject non-local follow requests
|
||||
- `mrf_tag:disable-any-subscription`: Reject any follow requests
|
||||
"""
|
||||
@behaviour Pleroma.Web.ActivityPub.MRF.Policy
|
||||
|
||||
alias Pleroma.User
|
||||
|
||||
use Pleroma.Web.ActivityPub.MRF.Policy
|
||||
|
||||
require Pleroma.Constants
|
||||
|
||||
|
|
|
|||
|
|
@ -3,11 +3,13 @@
|
|||
# SPDX-License-Identifier: AGPL-3.0-only
|
||||
|
||||
defmodule Pleroma.Web.ActivityPub.MRF.UserAllowListPolicy do
|
||||
alias Pleroma.Config
|
||||
|
||||
@moduledoc "Accept-list of users from specified instances"
|
||||
@behaviour Pleroma.Web.ActivityPub.MRF.Policy
|
||||
|
||||
alias Pleroma.Config
|
||||
|
||||
use Pleroma.Web.ActivityPub.MRF.Policy
|
||||
|
||||
defp filter_by_list(activity, []), do: {:ok, activity}
|
||||
|
||||
defp filter_by_list(%{"actor" => actor} = activity, allow_list) do
|
||||
|
|
|
|||
|
|
@ -4,9 +4,10 @@
|
|||
|
||||
defmodule Pleroma.Web.ActivityPub.MRF.VocabularyPolicy do
|
||||
@moduledoc "Filter activities which belong to certain activity vocabularies"
|
||||
|
||||
@behaviour Pleroma.Web.ActivityPub.MRF.Policy
|
||||
|
||||
use Pleroma.Web.ActivityPub.MRF.Policy
|
||||
|
||||
@impl true
|
||||
def filter(%{"type" => "Undo", "object" => object} = activity) do
|
||||
with {:ok, _} <- filter(object) do
|
||||
|
|
|
|||
|
|
@ -68,7 +68,7 @@ defmodule Pleroma.Web.ActivityPub.UserView do
|
|||
capabilities =
|
||||
if is_boolean(user.accepts_chat_messages) do
|
||||
%{
|
||||
"acceptsChatMessages" => user.accepts_chat_messages
|
||||
"acceptsChatMessages" => Pleroma.Chat.enabled?() and user.accepts_chat_messages
|
||||
}
|
||||
else
|
||||
%{}
|
||||
|
|
|
|||
|
|
@ -71,7 +71,10 @@ defmodule Pleroma.Web.AdminAPI.ConfigController do
|
|||
end
|
||||
|
||||
def descriptions(conn, _params) do
|
||||
descriptions = Enum.filter(Pleroma.Docs.JSON.compiled_descriptions(), &whitelisted_config?/1)
|
||||
descriptions =
|
||||
Pleroma.Docs.JSON.compiled_descriptions()
|
||||
|> Enum.filter(&allowed_config?(&1, :whitelist))
|
||||
|> Enum.reject(&allowed_config?(&1, :blacklist))
|
||||
|
||||
json(conn, translate_descriptions(descriptions))
|
||||
end
|
||||
|
|
@ -132,7 +135,8 @@ defmodule Pleroma.Web.AdminAPI.ConfigController do
|
|||
with :ok <- configurable_from_database() do
|
||||
results =
|
||||
configs
|
||||
|> Enum.filter(&whitelisted_config?/1)
|
||||
|> Enum.filter(&allowed_config?(&1, :whitelist))
|
||||
|> Enum.reject(&allowed_config?(&1, :blacklist))
|
||||
|> Enum.map(fn
|
||||
%{group: group, key: key, delete: true} = params ->
|
||||
ConfigDB.delete(%{group: group, key: key, subkeys: params[:subkeys]})
|
||||
|
|
@ -174,27 +178,34 @@ defmodule Pleroma.Web.AdminAPI.ConfigController do
|
|||
end
|
||||
end
|
||||
|
||||
defp whitelisted_config?(":pleroma", ":database_config_whitelist"), do: false
|
||||
defp allowed_config?(":pleroma", ":database_config_whitelist", _), do: true
|
||||
defp allowed_config?(":pleroma", ":database_config_blacklist", _), do: true
|
||||
|
||||
defp whitelisted_config?(group, key) do
|
||||
if whitelisted_configs = Config.get(:database_config_whitelist) do
|
||||
Enum.any?(whitelisted_configs, fn
|
||||
{whitelisted_group} ->
|
||||
group == inspect(whitelisted_group)
|
||||
defp allowed_config?(group, key, mode) do
|
||||
configs =
|
||||
case mode do
|
||||
:whitelist -> Config.get(:database_config_whitelist)
|
||||
:blacklist -> Config.get(:database_config_blacklist)
|
||||
end
|
||||
|
||||
{whitelisted_group, whitelisted_key} ->
|
||||
group == inspect(whitelisted_group) && key == inspect(whitelisted_key)
|
||||
if configs do
|
||||
Enum.any?(configs, fn
|
||||
{allowed_group} ->
|
||||
group == inspect(allowed_group)
|
||||
|
||||
{allowed_group, allowed_key} ->
|
||||
group == inspect(allowed_group) && key == inspect(allowed_key)
|
||||
end)
|
||||
else
|
||||
true
|
||||
end
|
||||
end
|
||||
|
||||
defp whitelisted_config?(%{group: group, key: key}) do
|
||||
whitelisted_config?(group, key)
|
||||
defp allowed_config?(%{group: group, key: key}, mode) do
|
||||
allowed_config?(group, key, mode)
|
||||
end
|
||||
|
||||
defp whitelisted_config?(%{group: group} = config) do
|
||||
whitelisted_config?(group, config[:key])
|
||||
defp allowed_config?(%{group: group} = config, mode) do
|
||||
allowed_config?(group, config[:key], mode)
|
||||
end
|
||||
end
|
||||
|
|
|
|||
|
|
@ -31,7 +31,8 @@ defmodule Pleroma.Web.ApiSpec.ChatOperation do
|
|||
"The updated chat",
|
||||
"application/json",
|
||||
Chat
|
||||
)
|
||||
),
|
||||
404 => Operation.response("Not Found", "application/json", ApiError)
|
||||
},
|
||||
security: [
|
||||
%{
|
||||
|
|
@ -56,7 +57,8 @@ defmodule Pleroma.Web.ApiSpec.ChatOperation do
|
|||
"The read ChatMessage",
|
||||
"application/json",
|
||||
ChatMessage
|
||||
)
|
||||
),
|
||||
404 => Operation.response("Not Found", "application/json", ApiError)
|
||||
},
|
||||
security: [
|
||||
%{
|
||||
|
|
@ -87,7 +89,8 @@ defmodule Pleroma.Web.ApiSpec.ChatOperation do
|
|||
"The existing chat",
|
||||
"application/json",
|
||||
Chat
|
||||
)
|
||||
),
|
||||
404 => Operation.response("Not Found", "application/json", ApiError)
|
||||
},
|
||||
security: [
|
||||
%{
|
||||
|
|
@ -118,7 +121,8 @@ defmodule Pleroma.Web.ApiSpec.ChatOperation do
|
|||
"The created or existing chat",
|
||||
"application/json",
|
||||
Chat
|
||||
)
|
||||
),
|
||||
404 => Operation.response("Not Found", "application/json", ApiError)
|
||||
},
|
||||
security: [
|
||||
%{
|
||||
|
|
@ -146,7 +150,8 @@ defmodule Pleroma.Web.ApiSpec.ChatOperation do
|
|||
Operation.parameter(:pinned, :query, BooleanLike.schema(), "Include only pinned chats")
|
||||
],
|
||||
responses: %{
|
||||
200 => Operation.response("The chats of the user", "application/json", chats_response())
|
||||
200 => Operation.response("The chats of the user", "application/json", chats_response()),
|
||||
404 => Operation.response("Not Found", "application/json", ApiError)
|
||||
},
|
||||
security: [
|
||||
%{
|
||||
|
|
@ -172,7 +177,8 @@ defmodule Pleroma.Web.ApiSpec.ChatOperation do
|
|||
| pagination_params()
|
||||
],
|
||||
responses: %{
|
||||
200 => Operation.response("The chats of the user", "application/json", chats_response())
|
||||
200 => Operation.response("The chats of the user", "application/json", chats_response()),
|
||||
404 => Operation.response("Not Found", "application/json", ApiError)
|
||||
},
|
||||
security: [
|
||||
%{
|
||||
|
|
@ -224,6 +230,7 @@ defmodule Pleroma.Web.ApiSpec.ChatOperation do
|
|||
ChatMessage
|
||||
),
|
||||
400 => Operation.response("Bad Request", "application/json", ApiError),
|
||||
404 => Operation.response("Not Found", "application/json", ApiError),
|
||||
422 => Operation.response("MRF Rejection", "application/json", ApiError)
|
||||
},
|
||||
security: [
|
||||
|
|
@ -249,7 +256,8 @@ defmodule Pleroma.Web.ApiSpec.ChatOperation do
|
|||
"The deleted ChatMessage",
|
||||
"application/json",
|
||||
ChatMessage
|
||||
)
|
||||
),
|
||||
404 => Operation.response("Not Found", "application/json", ApiError)
|
||||
},
|
||||
security: [
|
||||
%{
|
||||
|
|
@ -268,7 +276,8 @@ defmodule Pleroma.Web.ApiSpec.ChatOperation do
|
|||
Operation.parameter(:id, :path, :string, "The id of the chat", required: true)
|
||||
],
|
||||
responses: %{
|
||||
200 => Operation.response("The existing chat", "application/json", Chat)
|
||||
200 => Operation.response("The existing chat", "application/json", Chat),
|
||||
404 => Operation.response("Not Found", "application/json", ApiError)
|
||||
},
|
||||
security: [
|
||||
%{
|
||||
|
|
@ -287,7 +296,8 @@ defmodule Pleroma.Web.ApiSpec.ChatOperation do
|
|||
Operation.parameter(:id, :path, :string, "The id of the chat", required: true)
|
||||
],
|
||||
responses: %{
|
||||
200 => Operation.response("The existing chat", "application/json", Chat)
|
||||
200 => Operation.response("The existing chat", "application/json", Chat),
|
||||
404 => Operation.response("Not Found", "application/json", ApiError)
|
||||
},
|
||||
security: [
|
||||
%{
|
||||
|
|
|
|||
|
|
@ -41,7 +41,8 @@ defmodule Pleroma.Web.ApiSpec.ListOperation do
|
|||
responses: %{
|
||||
200 => Operation.response("List", "application/json", List),
|
||||
400 => Operation.response("Error", "application/json", ApiError),
|
||||
404 => Operation.response("Error", "application/json", ApiError)
|
||||
404 => Operation.response("Error", "application/json", ApiError),
|
||||
422 => Operation.response("Error", "application/json", ApiError)
|
||||
}
|
||||
}
|
||||
end
|
||||
|
|
@ -175,7 +176,8 @@ defmodule Pleroma.Web.ApiSpec.ListOperation do
|
|||
exclusive: %Schema{
|
||||
type: :boolean,
|
||||
description: "Whether members of the list should be removed from the “Home” feed"
|
||||
}
|
||||
},
|
||||
emoji: %Schema{type: :string, description: "List emoji", nullable: true}
|
||||
},
|
||||
required: [:title]
|
||||
},
|
||||
|
|
@ -194,7 +196,8 @@ defmodule Pleroma.Web.ApiSpec.ListOperation do
|
|||
exclusive: %Schema{
|
||||
type: :boolean,
|
||||
description: "Whether members of the list should be removed from the “Home” feed"
|
||||
}
|
||||
},
|
||||
emoji: %Schema{type: :string, description: "List emoji", nullable: true}
|
||||
}
|
||||
},
|
||||
required: true
|
||||
|
|
|
|||
|
|
@ -3,7 +3,6 @@
|
|||
# SPDX-License-Identifier: AGPL-3.0-only
|
||||
|
||||
defmodule Pleroma.Web.ApiSpec.NotificationOperation do
|
||||
alias OpenApiSpex.Operation
|
||||
alias OpenApiSpex.Operation
|
||||
alias OpenApiSpex.Schema
|
||||
alias Pleroma.Web.ApiSpec.Schemas.Account
|
||||
|
|
@ -91,6 +90,79 @@ defmodule Pleroma.Web.ApiSpec.NotificationOperation do
|
|||
}
|
||||
end
|
||||
|
||||
def grouped_index_operation do
|
||||
%Operation{
|
||||
tags: ["Notifications"],
|
||||
summary: "Retrieve grouped notifications",
|
||||
description: "Notifications concerning the user, grouped by supported notification types.",
|
||||
operationId: "NotificationController.grouped_index",
|
||||
security: [%{"oAuth" => ["read:notifications"]}],
|
||||
parameters: grouped_notification_params() ++ pagination_params(),
|
||||
responses: %{
|
||||
200 => Operation.response("Grouped notifications", "application/json", grouped_result()),
|
||||
404 => Operation.response("Error", "application/json", ApiError)
|
||||
}
|
||||
}
|
||||
end
|
||||
|
||||
def show_group_operation do
|
||||
%Operation{
|
||||
tags: ["Notifications"],
|
||||
summary: "Retrieve a notification group",
|
||||
operationId: "NotificationController.show_group",
|
||||
security: [%{"oAuth" => ["read:notifications"]}],
|
||||
parameters: [group_key_param()],
|
||||
responses: %{
|
||||
200 => Operation.response("Grouped notifications", "application/json", grouped_result()),
|
||||
404 => Operation.response("Error", "application/json", ApiError)
|
||||
}
|
||||
}
|
||||
end
|
||||
|
||||
def group_accounts_operation do
|
||||
%Operation{
|
||||
tags: ["Notifications"],
|
||||
summary: "Retrieve notification group accounts",
|
||||
operationId: "NotificationController.group_accounts",
|
||||
security: [%{"oAuth" => ["read:notifications"]}],
|
||||
parameters: [group_key_param()],
|
||||
responses: %{
|
||||
200 =>
|
||||
Operation.response("Accounts", "application/json", %Schema{
|
||||
type: :array,
|
||||
items: Account
|
||||
})
|
||||
}
|
||||
}
|
||||
end
|
||||
|
||||
def unread_count_operation do
|
||||
%Operation{
|
||||
tags: ["Notifications"],
|
||||
summary: "Retrieve unread grouped notification count",
|
||||
operationId: "NotificationController.unread_count",
|
||||
security: [%{"oAuth" => ["read:notifications"]}],
|
||||
parameters:
|
||||
grouped_notification_params() ++
|
||||
[
|
||||
Operation.parameter(
|
||||
:limit,
|
||||
:query,
|
||||
%Schema{type: :integer},
|
||||
"Maximum number of notifications to count"
|
||||
)
|
||||
],
|
||||
responses: %{
|
||||
200 =>
|
||||
Operation.response("Unread notification group count", "application/json", %Schema{
|
||||
type: :object,
|
||||
properties: %{count: %Schema{type: :integer}}
|
||||
}),
|
||||
404 => Operation.response("Error", "application/json", ApiError)
|
||||
}
|
||||
}
|
||||
end
|
||||
|
||||
def clear_operation do
|
||||
%Operation{
|
||||
tags: ["Notifications"],
|
||||
|
|
@ -114,6 +186,18 @@ defmodule Pleroma.Web.ApiSpec.NotificationOperation do
|
|||
}
|
||||
end
|
||||
|
||||
def dismiss_group_operation do
|
||||
%Operation{
|
||||
tags: ["Notifications"],
|
||||
summary: "Dismiss a notification group",
|
||||
description: "Clear all notifications in a notification group from the server.",
|
||||
operationId: "NotificationController.dismiss_group",
|
||||
parameters: [group_key_param()],
|
||||
security: [%{"oAuth" => ["write:notifications"]}],
|
||||
responses: %{200 => empty_object_response()}
|
||||
}
|
||||
end
|
||||
|
||||
def dismiss_via_body_operation do
|
||||
%Operation{
|
||||
tags: ["Notifications"],
|
||||
|
|
@ -184,7 +268,7 @@ defmodule Pleroma.Web.ApiSpec.NotificationOperation do
|
|||
},
|
||||
example: %{
|
||||
"id" => "34975861",
|
||||
"group-key" => "ungrouped-34975861",
|
||||
"group_key" => "ungrouped-34975861",
|
||||
"type" => "mention",
|
||||
"created_at" => "2019-11-23T07:49:02.064Z",
|
||||
"account" => Account.schema().example,
|
||||
|
|
@ -194,6 +278,73 @@ defmodule Pleroma.Web.ApiSpec.NotificationOperation do
|
|||
}
|
||||
end
|
||||
|
||||
defp grouped_result do
|
||||
%Schema{
|
||||
title: "GroupedNotificationsResults",
|
||||
type: :object,
|
||||
properties: %{
|
||||
accounts: %Schema{type: :array, items: Account},
|
||||
statuses: %Schema{type: :array, items: Status},
|
||||
notification_groups: %Schema{type: :array, items: notification_group()}
|
||||
},
|
||||
required: [:accounts, :statuses, :notification_groups]
|
||||
}
|
||||
end
|
||||
|
||||
defp notification_group do
|
||||
%Schema{
|
||||
title: "NotificationGroup",
|
||||
type: :object,
|
||||
properties: %{
|
||||
group_key: %Schema{type: :string},
|
||||
notifications_count: %Schema{type: :integer},
|
||||
type: notification_type(),
|
||||
most_recent_notification_id: %Schema{type: :string},
|
||||
page_min_id: %Schema{type: :string, nullable: true},
|
||||
page_max_id: %Schema{type: :string, nullable: true},
|
||||
latest_page_notification_at: %Schema{type: :string, format: :"date-time", nullable: true},
|
||||
sample_account_ids: %Schema{type: :array, items: %Schema{type: :string}},
|
||||
status_id: %Schema{type: :string, nullable: true}
|
||||
},
|
||||
required: [
|
||||
:group_key,
|
||||
:notifications_count,
|
||||
:type,
|
||||
:most_recent_notification_id,
|
||||
:sample_account_ids
|
||||
]
|
||||
}
|
||||
end
|
||||
|
||||
defp grouped_notification_params do
|
||||
[
|
||||
Operation.parameter(
|
||||
:exclude_types,
|
||||
:query,
|
||||
%Schema{type: :array, items: notification_type()},
|
||||
"Array of types to exclude"
|
||||
),
|
||||
Operation.parameter(
|
||||
:account_id,
|
||||
:query,
|
||||
%Schema{type: :string},
|
||||
"Return only notifications received from this account"
|
||||
),
|
||||
Operation.parameter(
|
||||
:types,
|
||||
:query,
|
||||
%Schema{type: :array, items: notification_type()},
|
||||
"Include the notifications for activities with the given types"
|
||||
),
|
||||
Operation.parameter(
|
||||
:grouped_types,
|
||||
:query,
|
||||
%Schema{type: :array, items: notification_type()},
|
||||
"Notification types that may be grouped"
|
||||
)
|
||||
]
|
||||
end
|
||||
|
||||
defp notification_type do
|
||||
%Schema{
|
||||
type: :string,
|
||||
|
|
@ -239,4 +390,11 @@ defmodule Pleroma.Web.ApiSpec.NotificationOperation do
|
|||
required: true
|
||||
)
|
||||
end
|
||||
|
||||
defp group_key_param do
|
||||
Operation.parameter(:group_key, :path, :string, "Notification group key",
|
||||
example: "favourite-123",
|
||||
required: true
|
||||
)
|
||||
end
|
||||
end
|
||||
|
|
|
|||
|
|
@ -17,11 +17,26 @@ defmodule Pleroma.Web.ApiSpec.Schemas.List do
|
|||
exclusive: %Schema{
|
||||
type: :boolean,
|
||||
description: "Whether members of the list should be removed from the “Home” feed"
|
||||
},
|
||||
pleroma: %Schema{
|
||||
type: :object,
|
||||
properties: %{
|
||||
emoji: %Schema{type: :string, description: "List emoji", nullable: true},
|
||||
emoji_url: %Schema{
|
||||
type: :string,
|
||||
description: "URL of the list emoji if it's a custom emoji, null otherwise",
|
||||
nullable: true
|
||||
}
|
||||
}
|
||||
}
|
||||
},
|
||||
example: %{
|
||||
"id" => "12249",
|
||||
"title" => "Friends"
|
||||
"title" => "Friends",
|
||||
"pleroma" => %{
|
||||
"emoji" => nil,
|
||||
"emoji_url" => nil
|
||||
}
|
||||
}
|
||||
})
|
||||
end
|
||||
|
|
|
|||
|
|
@ -55,16 +55,28 @@ defmodule Pleroma.Web.ControllerHelper do
|
|||
|
||||
# TODO: Only fetch the params from open_api_spex when everything is converted
|
||||
@id_keys Pagination.page_keys() -- ["limit", "order"]
|
||||
@id_key_atoms Enum.map(@id_keys, &String.to_atom/1)
|
||||
@drop_id_params_key :drop_id_params
|
||||
defp build_pagination_fields(conn, min_id, max_id, extra_params, order) do
|
||||
drop_id_params? = Map.get(extra_params, @drop_id_params_key, false)
|
||||
extra_params = Map.delete(extra_params, @drop_id_params_key)
|
||||
|
||||
path_param_keys =
|
||||
conn.path_params
|
||||
|> Map.keys()
|
||||
|> Enum.flat_map(&[&1, String.to_existing_atom(&1)])
|
||||
|
||||
params =
|
||||
if Map.has_key?(conn.private, :open_api_spex) do
|
||||
get_in(conn, [Access.key(:private), Access.key(:open_api_spex), Access.key(:params)])
|
||||
else
|
||||
conn.params
|
||||
end
|
||||
|> Map.drop(Map.keys(conn.path_params) |> Enum.map(&String.to_existing_atom/1))
|
||||
|> Map.drop(path_param_keys)
|
||||
|> Map.merge(extra_params)
|
||||
|> Map.drop(@id_keys)
|
||||
# Some OpenApiSpex routes cast cursor params to atoms. Keep the historical default for
|
||||
# existing endpoints, but allow grouped notifications to opt out of stale request cursors.
|
||||
|> Map.drop(@id_keys ++ if(drop_id_params?, do: @id_key_atoms, else: []))
|
||||
|
||||
{{next_id, nid}, {prev_id, pid}} =
|
||||
if order == :desc,
|
||||
|
|
|
|||
|
|
@ -139,6 +139,8 @@ defmodule Pleroma.Web.Endpoint do
|
|||
from: {:pleroma, "priv/static/adminfe/"}
|
||||
)
|
||||
|
||||
plug(Pleroma.Web.Plugs.StaticNotFoundPlug)
|
||||
|
||||
# Code reloading can be explicitly enabled under the
|
||||
# :code_reloader configuration of your endpoint.
|
||||
if code_reloading? do
|
||||
|
|
|
|||
|
|
@ -89,7 +89,8 @@ defmodule Pleroma.Web.Federator do
|
|||
|
||||
# Job Worker Callbacks
|
||||
|
||||
@spec perform(atom(), any()) :: {:ok, any()} | {:error, any()}
|
||||
@impl true
|
||||
@spec perform(atom(), any()) :: :ok | {:ok, any()} | {:error, any()}
|
||||
def perform(:publish_one, params) do
|
||||
Publisher.prepare_one(params)
|
||||
|> Publisher.publish_one()
|
||||
|
|
|
|||
|
|
@ -3,5 +3,6 @@
|
|||
# SPDX-License-Identifier: AGPL-3.0-only
|
||||
|
||||
defmodule Pleroma.Web.Federator.Publishing do
|
||||
@callback perform(atom(), any()) :: :ok | {:ok, any()} | {:error, any()}
|
||||
@callback publish(map()) :: any()
|
||||
end
|
||||
|
|
|
|||
|
|
@ -38,6 +38,20 @@ defmodule Pleroma.Web.Feed.FeedView do
|
|||
end
|
||||
end
|
||||
|
||||
def most_recent_update([], :rss), do: nil
|
||||
|
||||
def most_recent_update(activities, :rss) do
|
||||
activities
|
||||
|> Enum.map(fn activity ->
|
||||
case activity.object do
|
||||
%Object{updated_at: updated_at} -> updated_at
|
||||
_ -> activity.updated_at
|
||||
end
|
||||
end)
|
||||
|> Enum.max_by(&NaiveDateTime.to_erl/1)
|
||||
|> to_rfc2822()
|
||||
end
|
||||
|
||||
def most_recent_update(activities, user, :atom) do
|
||||
(List.first(activities) || user).updated_at
|
||||
|> to_rfc3339()
|
||||
|
|
@ -97,6 +111,67 @@ defmodule Pleroma.Web.Feed.FeedView do
|
|||
end
|
||||
end
|
||||
|
||||
def rss_content_encoded(data) do
|
||||
data
|
||||
|> feed_content_encoded()
|
||||
|> String.replace("]]>", "]]>")
|
||||
end
|
||||
|
||||
def atom_content_encoded(data), do: feed_content_encoded(data)
|
||||
|
||||
defp feed_content_encoded(data) do
|
||||
base_content =
|
||||
case activity_content(data) do
|
||||
"" ->
|
||||
(data["summary"] || data["type"] || "")
|
||||
|> escape()
|
||||
|
||||
content ->
|
||||
content
|
||||
end
|
||||
|
||||
attachments_html =
|
||||
if sensitive?(data) do
|
||||
""
|
||||
else
|
||||
(data["attachment"] || [])
|
||||
|> Enum.map(&rss_attachment_preview/1)
|
||||
|> Enum.reject(&(&1 == ""))
|
||||
|> Enum.join("<br/><br/>")
|
||||
end
|
||||
|
||||
[base_content, attachments_html]
|
||||
|> Enum.reject(&(&1 == ""))
|
||||
|> Enum.join("<br/><br/>")
|
||||
end
|
||||
|
||||
defp rss_attachment_preview(attachment) do
|
||||
href = attachment_href(attachment)
|
||||
|
||||
if is_binary(href) and href != "" do
|
||||
media_type = attachment_type(attachment) || "application/octet-stream"
|
||||
escaped_href = escape(href)
|
||||
name = attachment["name"] || "Attachment"
|
||||
escaped_name = escape(name)
|
||||
|
||||
cond do
|
||||
String.starts_with?(media_type, "image/") ->
|
||||
~s(<p><img src="#{escaped_href}" alt="#{escaped_name}" loading="lazy"/></p>)
|
||||
|
||||
String.starts_with?(media_type, "video/") ->
|
||||
~s(<p><video controls preload="metadata" src="#{escaped_href}"></video></p><p><a href="#{escaped_href}">#{escaped_name}</a></p>)
|
||||
|
||||
String.starts_with?(media_type, "audio/") ->
|
||||
~s(<p><audio controls preload="metadata" src="#{escaped_href}"></audio></p><p><a href="#{escaped_href}">#{escaped_name}</a></p>)
|
||||
|
||||
true ->
|
||||
~s(<p><a href="#{escaped_href}">#{escaped_name}</a></p>)
|
||||
end
|
||||
else
|
||||
""
|
||||
end
|
||||
end
|
||||
|
||||
def activity_content(%{"content" => content}) do
|
||||
content
|
||||
|> String.replace(~r/[\n\r]/, "")
|
||||
|
|
@ -106,16 +181,104 @@ defmodule Pleroma.Web.Feed.FeedView do
|
|||
|
||||
def activity_context(activity), do: escape(activity.data["context"])
|
||||
|
||||
def sensitive?(data), do: data["sensitive"] in [true, "true"]
|
||||
|
||||
def feed_self_url(conn) do
|
||||
conn
|
||||
|> Phoenix.Controller.current_url()
|
||||
|> escape()
|
||||
end
|
||||
|
||||
def activity_link(activity, data) do
|
||||
cond do
|
||||
activity.local -> data["id"] || data["url"]
|
||||
true -> data["external_url"] || data["id"] || data["url"]
|
||||
end
|
||||
end
|
||||
|
||||
def attachment_href(attachment) do
|
||||
attachment["url"]
|
||||
|> hd()
|
||||
attachment
|
||||
|> attachment_url_data()
|
||||
|> Map.get("href")
|
||||
end
|
||||
|
||||
def attachment_type(attachment) do
|
||||
attachment["url"]
|
||||
|> hd()
|
||||
|> Map.get("mediaType")
|
||||
attachment
|
||||
|> attachment_url_data()
|
||||
|> Map.get("mediaType") || attachment["mediaType"]
|
||||
end
|
||||
|
||||
def attachment_size(attachment) do
|
||||
attachment
|
||||
|> attachment_url_data()
|
||||
|> Map.get("size", 0)
|
||||
end
|
||||
|
||||
def attachment_size_positive(attachment) do
|
||||
case attachment_size(attachment) do
|
||||
size when is_integer(size) and size > 0 ->
|
||||
size
|
||||
|
||||
size when is_binary(size) ->
|
||||
case Integer.parse(size) do
|
||||
{parsed, ""} when parsed > 0 -> parsed
|
||||
_ -> nil
|
||||
end
|
||||
|
||||
_ ->
|
||||
nil
|
||||
end
|
||||
end
|
||||
|
||||
def attachment_medium(attachment) do
|
||||
case attachment_type(attachment) do
|
||||
"image/" <> _rest -> "image"
|
||||
"video/" <> _rest -> "video"
|
||||
"audio/" <> _rest -> "audio"
|
||||
_ -> "document"
|
||||
end
|
||||
end
|
||||
|
||||
def rss_enclosure_attachment(attachments) do
|
||||
Enum.find(attachments || [], &(not is_nil(attachment_size_positive(&1))))
|
||||
end
|
||||
|
||||
def attachment_description(attachment) do
|
||||
attachment["name"] || ""
|
||||
end
|
||||
|
||||
def media_content_xml(_attachment, sensitive) when sensitive in [true, "true"], do: ""
|
||||
|
||||
def media_content_xml(attachment, _sensitive) do
|
||||
href = escape(attachment_href(attachment) || "")
|
||||
type = escape(attachment_type(attachment) || "application/octet-stream")
|
||||
medium = escape(attachment_medium(attachment))
|
||||
|
||||
file_size_attr =
|
||||
case attachment_size_positive(attachment) do
|
||||
size when is_integer(size) -> ~s( fileSize="#{size}")
|
||||
_ -> ""
|
||||
end
|
||||
|
||||
case attachment_description(attachment) do
|
||||
"" ->
|
||||
~s(<media:content url="#{href}" type="#{type}"#{file_size_attr} medium="#{medium}"/>\n)
|
||||
|
||||
description ->
|
||||
"""
|
||||
<media:content url="#{href}" type="#{type}"#{file_size_attr} medium="#{medium}">
|
||||
<media:description type="plain">#{escape(description)}</media:description>
|
||||
</media:content>
|
||||
"""
|
||||
end
|
||||
end
|
||||
|
||||
defp attachment_url_data(attachment) do
|
||||
case attachment["url"] do
|
||||
[first | _] when is_map(first) -> first
|
||||
%{} = map -> map
|
||||
_ -> %{}
|
||||
end
|
||||
end
|
||||
|
||||
def get_href(id) do
|
||||
|
|
|
|||
|
|
@ -5,13 +5,17 @@
|
|||
defmodule Pleroma.Web.MastodonAPI.NotificationController do
|
||||
use Pleroma.Web, :controller
|
||||
|
||||
import Pleroma.Web.ControllerHelper, only: [add_link_headers: 2]
|
||||
import Pleroma.Web.ControllerHelper, only: [add_link_headers: 2, add_link_headers: 3]
|
||||
|
||||
alias Pleroma.Notification
|
||||
alias Pleroma.User
|
||||
alias Pleroma.Web.MastodonAPI.AccountView
|
||||
alias Pleroma.Web.MastodonAPI.MastodonAPI
|
||||
alias Pleroma.Web.Plugs.OAuthScopesPlug
|
||||
|
||||
@oauth_read_actions [:show, :index]
|
||||
# Mastodon's docs currently list write:notifications for group accounts, but the endpoint is
|
||||
# read-only and Mastodon's implementation accepts read:notifications. Prefer least privilege.
|
||||
@oauth_read_actions [:show, :index, :grouped_index, :show_group, :group_accounts, :unread_count]
|
||||
|
||||
plug(Pleroma.Web.ApiSpec.CastAndValidate, replace_params: false)
|
||||
|
||||
|
|
@ -39,7 +43,7 @@ defmodule Pleroma.Web.MastodonAPI.NotificationController do
|
|||
|
||||
# GET /api/v1/notifications
|
||||
def index(%{private: %{open_api_spex: %{params: %{account_id: account_id} = params}}} = conn, _) do
|
||||
case Pleroma.User.get_cached_by_id(account_id) do
|
||||
case User.get_cached_by_id(account_id) do
|
||||
%{ap_id: account_ap_id} ->
|
||||
params =
|
||||
params
|
||||
|
|
@ -59,10 +63,108 @@ defmodule Pleroma.Web.MastodonAPI.NotificationController do
|
|||
do_get_notifications(conn, params)
|
||||
end
|
||||
|
||||
# GET /api/v2/notifications
|
||||
def grouped_index(
|
||||
%{private: %{open_api_spex: %{params: %{account_id: account_id} = params}}} = conn,
|
||||
_
|
||||
) do
|
||||
case User.get_cached_by_id(account_id) do
|
||||
%{ap_id: account_ap_id} ->
|
||||
params =
|
||||
params
|
||||
|> Map.delete(:account_id)
|
||||
|> Map.put(:account_ap_id, account_ap_id)
|
||||
|
||||
do_get_grouped_notifications(conn, params)
|
||||
|
||||
_ ->
|
||||
conn
|
||||
|> put_status(:not_found)
|
||||
|> json(%{"error" => "Account is not found"})
|
||||
end
|
||||
end
|
||||
|
||||
def grouped_index(%{private: %{open_api_spex: %{params: params}}} = conn, _) do
|
||||
do_get_grouped_notifications(conn, params)
|
||||
end
|
||||
|
||||
# GET /api/v2/notifications/:group_key
|
||||
def show_group(
|
||||
%{assigns: %{user: user}, private: %{open_api_spex: %{params: %{group_key: group_key}}}} =
|
||||
conn,
|
||||
_
|
||||
) do
|
||||
{notifications, notification_group_counts, notification_group_bounds} =
|
||||
MastodonAPI.get_notification_group_result(user, group_key, %{})
|
||||
|
||||
if Enum.empty?(notifications) do
|
||||
conn
|
||||
|> put_status(:not_found)
|
||||
|> json(%{"error" => "Notification group is not found"})
|
||||
else
|
||||
grouped_types = if String.starts_with?(group_key, "ungrouped-"), do: [], else: nil
|
||||
|
||||
render(conn, "grouped_index.json",
|
||||
notification_groups: [notifications],
|
||||
notification_group_counts: notification_group_counts,
|
||||
notification_group_bounds: notification_group_bounds,
|
||||
for: user,
|
||||
grouped_types: grouped_types,
|
||||
include_page_metadata: false
|
||||
)
|
||||
end
|
||||
end
|
||||
|
||||
# GET /api/v2/notifications/:group_key/accounts
|
||||
def group_accounts(
|
||||
%{assigns: %{user: user}, private: %{open_api_spex: %{params: %{group_key: group_key}}}} =
|
||||
conn,
|
||||
_
|
||||
) do
|
||||
# Mastodon paginates this endpoint in code, but the public docs say it returns accounts of all
|
||||
# notifications in the group and do not document cursor params here. Follow the documented API.
|
||||
users = MastodonAPI.get_notification_group_accounts(user, group_key)
|
||||
|
||||
json(conn, AccountView.render("index.json", %{users: users, for: user}))
|
||||
end
|
||||
|
||||
# GET /api/v2/notifications/unread_count
|
||||
def unread_count(
|
||||
%{private: %{open_api_spex: %{params: %{account_id: account_id} = params}}} = conn,
|
||||
_
|
||||
) do
|
||||
case User.get_cached_by_id(account_id) do
|
||||
%{ap_id: account_ap_id} ->
|
||||
params =
|
||||
params
|
||||
|> Map.delete(:account_id)
|
||||
|> Map.put(:account_ap_id, account_ap_id)
|
||||
|
||||
do_get_unread_group_count(conn, params)
|
||||
|
||||
_ ->
|
||||
conn
|
||||
|> put_status(:not_found)
|
||||
|> json(%{"error" => "Account is not found"})
|
||||
end
|
||||
end
|
||||
|
||||
def unread_count(%{private: %{open_api_spex: %{params: params}}} = conn, _) do
|
||||
do_get_unread_group_count(conn, params)
|
||||
end
|
||||
|
||||
# POST /api/v2/notifications/:group_key/dismiss
|
||||
def dismiss_group(
|
||||
%{assigns: %{user: user}, private: %{open_api_spex: %{params: %{group_key: group_key}}}} =
|
||||
conn,
|
||||
_
|
||||
) do
|
||||
MastodonAPI.dismiss_notification_group(user, group_key)
|
||||
json(conn, %{})
|
||||
end
|
||||
|
||||
defp do_get_notifications(%{assigns: %{user: user}} = conn, params) do
|
||||
params =
|
||||
Map.new(params, fn {k, v} -> {to_string(k), v} end)
|
||||
|> Map.put_new("types", Map.get(params, :include_types, @default_notification_types))
|
||||
params = normalize_notification_params(params)
|
||||
|
||||
notifications = MastodonAPI.get_notifications(user, params)
|
||||
|
||||
|
|
@ -74,6 +176,35 @@ defmodule Pleroma.Web.MastodonAPI.NotificationController do
|
|||
)
|
||||
end
|
||||
|
||||
defp do_get_grouped_notifications(%{assigns: %{user: user}} = conn, params) do
|
||||
params = normalize_notification_params(params)
|
||||
|
||||
{notification_groups, page_notifications, notification_group_counts,
|
||||
notification_group_bounds} =
|
||||
MastodonAPI.get_grouped_notification_page(user, params)
|
||||
|
||||
conn
|
||||
|> add_link_headers(page_notifications, %{drop_id_params: true})
|
||||
|> render("grouped_index.json",
|
||||
notification_groups: notification_groups,
|
||||
notification_group_counts: notification_group_counts,
|
||||
notification_group_bounds: notification_group_bounds,
|
||||
for: user,
|
||||
grouped_types: params["grouped_types"]
|
||||
)
|
||||
end
|
||||
|
||||
defp do_get_unread_group_count(%{assigns: %{user: user}} = conn, params) do
|
||||
params = normalize_notification_params(params)
|
||||
json(conn, %{count: MastodonAPI.unread_notification_group_count(user, params)})
|
||||
end
|
||||
|
||||
defp normalize_notification_params(params) do
|
||||
params
|
||||
|> Map.new(fn {k, v} -> {to_string(k), v} end)
|
||||
|> Map.put_new("types", Map.get(params, :include_types, @default_notification_types))
|
||||
end
|
||||
|
||||
# GET /api/v1/notifications/:id
|
||||
def show(%{assigns: %{user: user}, private: %{open_api_spex: %{params: %{id: id}}}} = conn, _) do
|
||||
with {:ok, notification} <- Notification.get(user, id) do
|
||||
|
|
|
|||
|
|
@ -716,7 +716,10 @@ defmodule Pleroma.Web.MastodonAPI.StatusController do
|
|||
end
|
||||
end
|
||||
|
||||
defp put_application(params, %{assigns: %{token: %Token{user: %User{} = user} = token}} = _conn) do
|
||||
defp put_application(
|
||||
params,
|
||||
%{assigns: %{token: %Token{} = token, user: %User{} = user}} = _conn
|
||||
) do
|
||||
if user.disclose_client do
|
||||
%{client_name: client_name, website: website} = Repo.preload(token, :app).app
|
||||
Map.put(params, :generator, %{type: "Application", name: client_name, url: website})
|
||||
|
|
|
|||
|
|
@ -6,12 +6,16 @@ defmodule Pleroma.Web.MastodonAPI.MastodonAPI do
|
|||
import Ecto.Query
|
||||
import Ecto.Changeset
|
||||
|
||||
alias Pleroma.Marker
|
||||
alias Pleroma.Notification
|
||||
alias Pleroma.Pagination
|
||||
alias Pleroma.Repo
|
||||
alias Pleroma.ScheduledActivity
|
||||
alias Pleroma.User
|
||||
alias Pleroma.Web.CommonAPI
|
||||
|
||||
@notification_group_sample_limit 8
|
||||
|
||||
@spec follow(User.t(), User.t(), map) :: {:ok, User.t()} | {:error, String.t()}
|
||||
def follow(follower, followed, params \\ %{}) do
|
||||
result =
|
||||
|
|
@ -61,29 +65,365 @@ defmodule Pleroma.Web.MastodonAPI.MastodonAPI do
|
|||
end
|
||||
|
||||
def get_notifications(user, params \\ %{}) do
|
||||
options =
|
||||
cast_params(params) |> Map.update(:include_types, [], fn include_types -> include_types end)
|
||||
user
|
||||
|> notifications_query(params)
|
||||
|> Pagination.fetch_paginated(params)
|
||||
end
|
||||
|
||||
options =
|
||||
if ("pleroma:report" not in options.include_types and
|
||||
User.privileged?(user, :reports_manage_reports)) or
|
||||
User.privileged?(user, :reports_manage_reports) do
|
||||
options
|
||||
else
|
||||
options
|
||||
|> Map.update(:exclude_types, ["pleroma:report"], fn current_exclude_types ->
|
||||
current_exclude_types ++ ["pleroma:report"]
|
||||
end)
|
||||
end
|
||||
def get_grouped_notification_page(user, params \\ %{}) do
|
||||
grouped_types =
|
||||
params
|
||||
|> Map.get("grouped_types")
|
||||
|> Notification.normalize_grouped_types()
|
||||
|
||||
query = notifications_query(user, params)
|
||||
{order, cursor_filters} = group_pagination(params)
|
||||
|
||||
group_rows =
|
||||
query
|
||||
|> notification_group_rows(grouped_types, grouped_limit(params), order, cursor_filters)
|
||||
|
||||
group_rows = if order == :asc, do: Enum.reverse(group_rows), else: group_rows
|
||||
|
||||
page_notifications = representative_notifications(query, group_rows)
|
||||
|
||||
notification_groups =
|
||||
Enum.map(group_rows, ¬ification_group_sample(user, params, &1.group_key))
|
||||
|
||||
{
|
||||
notification_groups,
|
||||
page_notifications,
|
||||
notification_group_counts(group_rows),
|
||||
notification_group_bounds(group_rows)
|
||||
}
|
||||
end
|
||||
|
||||
def get_notification_group_result(user, group_key, params \\ %{}) do
|
||||
notifications = notification_group_sample(user, params, group_key)
|
||||
metadata = notification_group_metadata(user, group_key, params)
|
||||
|
||||
if Enum.empty?(notifications) or is_nil(metadata) do
|
||||
{[], %{}, %{}}
|
||||
else
|
||||
{
|
||||
notifications,
|
||||
%{group_key => metadata.notifications_count},
|
||||
%{group_key => Map.drop(metadata, [:notifications_count])}
|
||||
}
|
||||
end
|
||||
end
|
||||
|
||||
def get_notification_group(user, group_key, params \\ %{})
|
||||
|
||||
def get_notification_group(user, "ungrouped-" <> notification_id, _params) do
|
||||
case Notification.get(user, notification_id) do
|
||||
{:ok, notification} -> [notification]
|
||||
_ -> []
|
||||
end
|
||||
end
|
||||
|
||||
def get_notification_group(user, group_key, params) do
|
||||
notification_group_sample(user, params, group_key)
|
||||
end
|
||||
|
||||
def get_notification_group_accounts(user, "ungrouped-" <> notification_id) do
|
||||
with {:ok, notification} <- Notification.get(user, notification_id),
|
||||
%User{} = actor <- User.get_cached_by_ap_id(notification.activity.data["actor"]) do
|
||||
[actor]
|
||||
else
|
||||
_ -> []
|
||||
end
|
||||
end
|
||||
|
||||
def get_notification_group_accounts(user, group_key) do
|
||||
user
|
||||
|> notification_group_query(group_key, %{})
|
||||
|> exclude(:preload)
|
||||
|> distinct(true)
|
||||
|> select([user_actor: user_actor], user_actor)
|
||||
|> Repo.all()
|
||||
end
|
||||
|
||||
def dismiss_notification_group(user, "ungrouped-" <> notification_id) do
|
||||
Notification.destroy_multiple(user, [notification_id])
|
||||
end
|
||||
|
||||
def dismiss_notification_group(%User{id: user_id}, group_key) do
|
||||
Notification
|
||||
|> where([n], n.user_id == ^user_id and n.group_key == ^group_key)
|
||||
|> Repo.delete_all()
|
||||
end
|
||||
|
||||
defp group_pagination(params) do
|
||||
cond do
|
||||
min_id = Map.get(params, "min_id") ->
|
||||
cursor_filters = [{:gt, min_id}]
|
||||
|
||||
cursor_filters =
|
||||
case Map.get(params, "max_id") do
|
||||
nil -> cursor_filters
|
||||
max_id -> [{:lt, max_id} | cursor_filters]
|
||||
end
|
||||
|
||||
{:asc, cursor_filters}
|
||||
|
||||
since_id = Map.get(params, "since_id") ->
|
||||
{:desc, [{:gt, since_id}]}
|
||||
|
||||
max_id = Map.get(params, "max_id") ->
|
||||
{:desc, [{:lt, max_id}]}
|
||||
|
||||
true ->
|
||||
{:desc, []}
|
||||
end
|
||||
end
|
||||
|
||||
defp grouped_limit(params) do
|
||||
params
|
||||
|> Map.get("limit", 40)
|
||||
|> parse_limit(40)
|
||||
|> min(80)
|
||||
end
|
||||
|
||||
def unread_notification_group_count(user, params \\ %{}) do
|
||||
grouped_types =
|
||||
params
|
||||
|> Map.get("grouped_types")
|
||||
|> Notification.normalize_grouped_types()
|
||||
|
||||
limit = unread_count_limit(params)
|
||||
|
||||
user
|
||||
|> notifications_query(params)
|
||||
# The grouped API docs define unread by the notifications marker, not by Pleroma's per-row
|
||||
# seen flag used by the v1 unread count. Keep this marker-based for Mastodon clients.
|
||||
|> restrict_after_marker(notification_marker_last_read_id(user))
|
||||
|> notification_group_rows(grouped_types, limit, :desc, [])
|
||||
|> length()
|
||||
end
|
||||
|
||||
defp notification_group_rows(query, grouped_types, group_limit, :desc, cursor_filters) do
|
||||
query
|
||||
|> notification_group_keyed_query(grouped_types)
|
||||
|> group_by([n], n.group_key)
|
||||
|> apply_group_cursor_filters(cursor_filters)
|
||||
|> select([n], %{
|
||||
group_key: n.group_key,
|
||||
representative_id: max(n.id),
|
||||
notifications_count: count(n.id),
|
||||
page_min_id: min(n.id),
|
||||
page_max_id: max(n.id),
|
||||
latest_page_notification_at: max(n.inserted_at)
|
||||
})
|
||||
|> order_by([n], desc: max(n.id))
|
||||
|> limit(^group_limit)
|
||||
|> Repo.all()
|
||||
end
|
||||
|
||||
defp notification_group_rows(query, grouped_types, group_limit, :asc, cursor_filters) do
|
||||
query
|
||||
|> notification_group_keyed_query(grouped_types)
|
||||
|> group_by([n], n.group_key)
|
||||
|> apply_group_cursor_filters(cursor_filters)
|
||||
|> select([n], %{
|
||||
group_key: n.group_key,
|
||||
representative_id: max(n.id),
|
||||
notifications_count: count(n.id),
|
||||
page_min_id: min(n.id),
|
||||
page_max_id: max(n.id),
|
||||
latest_page_notification_at: max(n.inserted_at)
|
||||
})
|
||||
|> order_by([n], asc: max(n.id))
|
||||
|> limit(^group_limit)
|
||||
|> Repo.all()
|
||||
end
|
||||
|
||||
defp apply_group_cursor_filters(query, []), do: query
|
||||
|
||||
defp apply_group_cursor_filters(query, [{:gt, id} | rest]) do
|
||||
query
|
||||
|> having([n], max(n.id) > ^id)
|
||||
|> apply_group_cursor_filters(rest)
|
||||
end
|
||||
|
||||
defp apply_group_cursor_filters(query, [{:lt, id} | rest]) do
|
||||
query
|
||||
|> having([n], max(n.id) < ^id)
|
||||
|> apply_group_cursor_filters(rest)
|
||||
end
|
||||
|
||||
defp notification_group_keyed_query(query, grouped_types) do
|
||||
query
|
||||
|> exclude(:preload)
|
||||
|> select([n], %{
|
||||
id: n.id,
|
||||
inserted_at: n.inserted_at,
|
||||
group_key:
|
||||
fragment(
|
||||
"CASE WHEN ? IS NOT NULL AND ?::text = ANY(?) THEN ? ELSE 'ungrouped-' || ?::text END",
|
||||
n.group_key,
|
||||
n.type,
|
||||
type(^grouped_types, {:array, :string}),
|
||||
n.group_key,
|
||||
n.id
|
||||
)
|
||||
})
|
||||
|> subquery()
|
||||
end
|
||||
|
||||
defp representative_notifications(_query, []), do: []
|
||||
|
||||
defp representative_notifications(query, group_rows) do
|
||||
representative_ids = Enum.map(group_rows, & &1.representative_id)
|
||||
|
||||
notifications_by_id =
|
||||
query
|
||||
|> where([n], n.id in ^representative_ids)
|
||||
|> Repo.all()
|
||||
|> Map.new(&{to_string(&1.id), &1})
|
||||
|
||||
group_rows
|
||||
|> Enum.map(&Map.get(notifications_by_id, to_string(&1.representative_id)))
|
||||
|> Enum.filter(& &1)
|
||||
end
|
||||
|
||||
defp notification_group_counts(group_rows) do
|
||||
Map.new(group_rows, &{&1.group_key, &1.notifications_count})
|
||||
end
|
||||
|
||||
defp notification_group_bounds(group_rows) do
|
||||
Map.new(group_rows, fn row ->
|
||||
{row.group_key,
|
||||
%{
|
||||
page_min_id: row.page_min_id,
|
||||
page_max_id: row.page_max_id,
|
||||
latest_page_notification_at: row.latest_page_notification_at
|
||||
}}
|
||||
end)
|
||||
end
|
||||
|
||||
defp notification_group_sample(user, _params, "ungrouped-" <> notification_id) do
|
||||
case Notification.get(user, notification_id) do
|
||||
{:ok, notification} -> [notification]
|
||||
_ -> []
|
||||
end
|
||||
end
|
||||
|
||||
defp notification_group_sample(user, params, group_key) do
|
||||
user
|
||||
|> notification_group_query(group_key, params)
|
||||
|> order_by([n], desc: n.id)
|
||||
|> limit(^@notification_group_sample_limit)
|
||||
|> Repo.all()
|
||||
end
|
||||
|
||||
defp notification_group_metadata(user, "ungrouped-" <> notification_id, _params) do
|
||||
case Notification.get(user, notification_id) do
|
||||
{:ok, notification} ->
|
||||
%{
|
||||
notifications_count: 1,
|
||||
page_min_id: notification.id,
|
||||
page_max_id: notification.id,
|
||||
latest_page_notification_at: notification.inserted_at
|
||||
}
|
||||
|
||||
_ ->
|
||||
nil
|
||||
end
|
||||
end
|
||||
|
||||
defp notification_group_metadata(user, group_key, params) do
|
||||
user
|
||||
|> notification_group_query(group_key, params)
|
||||
|> exclude(:preload)
|
||||
|> select([n], %{
|
||||
notifications_count: count(n.id),
|
||||
page_min_id: min(n.id),
|
||||
page_max_id: max(n.id),
|
||||
latest_page_notification_at: max(n.inserted_at)
|
||||
})
|
||||
|> Repo.one()
|
||||
|> case do
|
||||
%{notifications_count: 0} -> nil
|
||||
metadata -> metadata
|
||||
end
|
||||
end
|
||||
|
||||
defp notification_group_query(user, group_key, params) do
|
||||
user
|
||||
|> notifications_query(params)
|
||||
|> where([n], n.group_key == ^group_key)
|
||||
end
|
||||
|
||||
defp notification_marker_last_read_id(user) do
|
||||
Marker
|
||||
|> where([m], m.user_id == ^user.id and m.timeline == "notifications")
|
||||
|> select([m], m.last_read_id)
|
||||
|> Repo.one()
|
||||
end
|
||||
|
||||
defp restrict_after_marker(query, last_read_id)
|
||||
when is_binary(last_read_id) and last_read_id != "" do
|
||||
where(query, [n], n.id > ^last_read_id)
|
||||
end
|
||||
|
||||
defp restrict_after_marker(query, _last_read_id), do: query
|
||||
|
||||
defp notifications_query(user, params) do
|
||||
options = notification_options(user, params)
|
||||
|
||||
user
|
||||
|> Notification.for_user_query(options)
|
||||
|> restrict(:types, options)
|
||||
|> restrict(:exclude_types, options)
|
||||
|> restrict(:account_ap_id, options)
|
||||
|> Pagination.fetch_paginated(params)
|
||||
end
|
||||
|
||||
defp notification_options(user, params) do
|
||||
options =
|
||||
params
|
||||
|> cast_params()
|
||||
|> Map.update(:include_types, [], fn include_types -> include_types end)
|
||||
|
||||
if "pleroma:chat_mention" in options.include_types and not Pleroma.Chat.enabled?() do
|
||||
options
|
||||
|> Map.update(:include_types, [], fn include_types ->
|
||||
List.delete(include_types, "pleroma:chat_mention")
|
||||
end)
|
||||
else
|
||||
options
|
||||
end
|
||||
|
||||
if ("pleroma:report" not in options.include_types and
|
||||
User.privileged?(user, :reports_manage_reports)) or
|
||||
User.privileged?(user, :reports_manage_reports) do
|
||||
options
|
||||
else
|
||||
options
|
||||
|> Map.update(:exclude_types, ["pleroma:report"], fn current_exclude_types ->
|
||||
current_exclude_types ++ ["pleroma:report"]
|
||||
end)
|
||||
end
|
||||
end
|
||||
|
||||
defp unread_count_limit(params) do
|
||||
params
|
||||
|> Map.get("limit", 100)
|
||||
|> parse_limit(100)
|
||||
|> min(1000)
|
||||
end
|
||||
|
||||
defp parse_limit(limit, _default) when is_integer(limit) and limit > 0, do: limit
|
||||
|
||||
defp parse_limit(limit, default) when is_binary(limit) do
|
||||
case Integer.parse(limit) do
|
||||
{limit, _} when limit > 0 -> limit
|
||||
_ -> default
|
||||
end
|
||||
end
|
||||
|
||||
defp parse_limit(_, default), do: default
|
||||
|
||||
def get_scheduled_activities(user, params \\ %{}) do
|
||||
user
|
||||
|> ScheduledActivity.for_user_query()
|
||||
|
|
@ -95,6 +435,8 @@ defmodule Pleroma.Web.MastodonAPI.MastodonAPI do
|
|||
exclude_types: {:array, :string},
|
||||
types: {:array, :string},
|
||||
exclude_visibilities: {:array, :string},
|
||||
grouped_types: {:array, :string},
|
||||
limit: :integer,
|
||||
reblogs: :boolean,
|
||||
with_muted: :boolean,
|
||||
account_ap_id: :string,
|
||||
|
|
|
|||
|
|
@ -287,6 +287,8 @@ defmodule Pleroma.Web.MastodonAPI.AccountView do
|
|||
user.last_status_at &&
|
||||
user.last_status_at |> NaiveDateTime.to_date() |> Date.to_iso8601()
|
||||
|
||||
accepts_chat_messages = Pleroma.Chat.enabled?() and user.accepts_chat_messages
|
||||
|
||||
%{
|
||||
id: to_string(user.id),
|
||||
username: username_from_nickname(user.nickname),
|
||||
|
|
@ -336,7 +338,7 @@ defmodule Pleroma.Web.MastodonAPI.AccountView do
|
|||
relationship: relationship,
|
||||
skip_thread_containment: user.skip_thread_containment,
|
||||
background_image: image_url(user.background) |> MediaProxy.url(),
|
||||
accepts_chat_messages: user.accepts_chat_messages,
|
||||
accepts_chat_messages: accepts_chat_messages,
|
||||
favicon: favicon,
|
||||
avatar_description: avatar_description,
|
||||
header_description: header_description
|
||||
|
|
@ -391,6 +393,7 @@ defmodule Pleroma.Web.MastodonAPI.AccountView do
|
|||
|> Kernel.put_in([:source, :pleroma, :show_role], user.show_role)
|
||||
|> Kernel.put_in([:source, :pleroma, :no_rich_text], user.no_rich_text)
|
||||
|> Kernel.put_in([:source, :pleroma, :show_birthday], user.show_birthday)
|
||||
|> Kernel.put_in([:source, :pleroma, :accepts_chat_messages], user.accepts_chat_messages)
|
||||
end
|
||||
|
||||
defp maybe_put_settings(data, _, _, _), do: data
|
||||
|
|
|
|||
|
|
@ -17,6 +17,8 @@ defmodule Pleroma.Web.MastodonAPI.InstanceView do
|
|||
reject: "suspend"
|
||||
}
|
||||
|
||||
def mastodon_api_level, do: @mastodon_api_level
|
||||
|
||||
def render("show.json", _) do
|
||||
instance = Config.get(:instance)
|
||||
|
||||
|
|
@ -166,6 +168,7 @@ defmodule Pleroma.Web.MastodonAPI.InstanceView do
|
|||
[
|
||||
"pleroma_api",
|
||||
"mastodon_api",
|
||||
"mastodon_api_grouped_notifications",
|
||||
"mastodon_api_streaming",
|
||||
"polls",
|
||||
"v2_suggestions",
|
||||
|
|
@ -199,8 +202,12 @@ defmodule Pleroma.Web.MastodonAPI.InstanceView do
|
|||
end,
|
||||
"pleroma_emoji_reactions",
|
||||
"pleroma_custom_emoji_reactions",
|
||||
"pleroma_chat_messages",
|
||||
"pleroma:pin_chats",
|
||||
if Pleroma.Chat.enabled?() do
|
||||
"pleroma_chat_messages"
|
||||
end,
|
||||
if Pleroma.Chat.enabled?() do
|
||||
"pleroma:pin_chats"
|
||||
end,
|
||||
if Config.get([:instance, :show_reactions]) do
|
||||
"exposable_reactions"
|
||||
end,
|
||||
|
|
|
|||
|
|
@ -4,6 +4,8 @@
|
|||
|
||||
defmodule Pleroma.Web.MastodonAPI.ListView do
|
||||
use Pleroma.Web, :view
|
||||
|
||||
alias Pleroma.Emoji
|
||||
alias Pleroma.Web.MastodonAPI.ListView
|
||||
|
||||
def render("index.json", %{lists: lists} = opts) do
|
||||
|
|
@ -11,10 +13,29 @@ defmodule Pleroma.Web.MastodonAPI.ListView do
|
|||
end
|
||||
|
||||
def render("show.json", %{list: list}) do
|
||||
{emoji, emoji_url} = get_emoji(list.emoji)
|
||||
|
||||
%{
|
||||
id: to_string(list.id),
|
||||
title: list.title,
|
||||
exclusive: list.exclusive
|
||||
exclusive: list.exclusive,
|
||||
pleroma: %{
|
||||
emoji: emoji,
|
||||
emoji_url: emoji_url
|
||||
}
|
||||
}
|
||||
end
|
||||
|
||||
defp get_emoji(nil), do: {nil, nil}
|
||||
|
||||
defp get_emoji(emoji) do
|
||||
if Emoji.unicode?(emoji) do
|
||||
{emoji, nil}
|
||||
else
|
||||
case Emoji.get(emoji) do
|
||||
nil -> {nil, nil}
|
||||
emoji_data -> {emoji, Emoji.local_url(emoji_data.file)}
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
|
|
|
|||
|
|
@ -72,6 +72,58 @@ defmodule Pleroma.Web.MastodonAPI.NotificationView do
|
|||
safe_render_many(notifications, NotificationView, "show.json", opts)
|
||||
end
|
||||
|
||||
def render("grouped_index.json", %{notifications: notifications} = opts) do
|
||||
grouped_types = Notification.normalize_grouped_types(opts[:grouped_types])
|
||||
|
||||
opts
|
||||
|> Map.delete(:notifications)
|
||||
|> Map.put(
|
||||
:notification_groups,
|
||||
Notification.group_notifications(notifications, grouped_types)
|
||||
)
|
||||
|> then(&render("grouped_index.json", &1))
|
||||
end
|
||||
|
||||
def render(
|
||||
"grouped_index.json",
|
||||
%{notification_groups: notification_groups, for: reading_user} = opts
|
||||
) do
|
||||
grouped_types = Notification.normalize_grouped_types(opts[:grouped_types])
|
||||
notification_group_counts = Map.get(opts, :notification_group_counts, %{})
|
||||
notification_group_bounds = Map.get(opts, :notification_group_bounds, %{})
|
||||
include_page_metadata = Map.get(opts, :include_page_metadata, true)
|
||||
|
||||
statuses =
|
||||
notification_groups
|
||||
|> Enum.map(&List.first/1)
|
||||
|> Enum.map(&render("show.json", %{notification: &1, for: reading_user}))
|
||||
|> Enum.map(& &1[:status])
|
||||
|> Enum.filter(& &1)
|
||||
|> Enum.uniq_by(& &1[:id])
|
||||
|
||||
actors =
|
||||
notification_groups
|
||||
|> List.flatten()
|
||||
|> notification_actors()
|
||||
|
||||
%{
|
||||
accounts: AccountView.render("index.json", %{users: actors, for: reading_user}),
|
||||
statuses: statuses,
|
||||
notification_groups:
|
||||
Enum.map(
|
||||
notification_groups,
|
||||
&render_group(
|
||||
&1,
|
||||
reading_user,
|
||||
grouped_types,
|
||||
notification_group_counts,
|
||||
notification_group_bounds,
|
||||
include_page_metadata
|
||||
)
|
||||
)
|
||||
}
|
||||
end
|
||||
|
||||
def render(
|
||||
"show.json",
|
||||
%{
|
||||
|
|
@ -95,7 +147,7 @@ defmodule Pleroma.Web.MastodonAPI.NotificationView do
|
|||
|
||||
response = %{
|
||||
id: to_string(notification.id),
|
||||
group_key: "ungrouped-" <> to_string(notification.id),
|
||||
group_key: Notification.group_key(notification),
|
||||
type: notification.type,
|
||||
created_at: CommonAPI.Utils.to_masto_date(notification.inserted_at),
|
||||
account: account,
|
||||
|
|
@ -137,6 +189,104 @@ defmodule Pleroma.Web.MastodonAPI.NotificationView do
|
|||
Map.put(response, :report, report_render)
|
||||
end
|
||||
|
||||
defp render_group(
|
||||
[%Notification{} = notification | _] = notifications,
|
||||
_reading_user,
|
||||
grouped_types,
|
||||
notification_group_counts,
|
||||
notification_group_bounds,
|
||||
include_page_metadata
|
||||
) do
|
||||
latest_notification = List.first(notifications)
|
||||
oldest_notification = List.last(notifications)
|
||||
status_activity = status_activity_for_group(notifications, grouped_types)
|
||||
group_key = Notification.group_key(notification, grouped_types)
|
||||
bounds = Map.get(notification_group_bounds, group_key, %{})
|
||||
|
||||
response = %{
|
||||
group_key: group_key,
|
||||
notifications_count: Map.get(notification_group_counts, group_key, length(notifications)),
|
||||
type: notification.type,
|
||||
most_recent_notification_id:
|
||||
bounds
|
||||
|> Map.get(:page_max_id, latest_notification.id)
|
||||
|> to_string(),
|
||||
sample_account_ids:
|
||||
notifications
|
||||
|> notification_actors()
|
||||
|> Enum.map(&to_string(&1.id))
|
||||
}
|
||||
|
||||
response =
|
||||
if include_page_metadata do
|
||||
Map.merge(response, %{
|
||||
page_min_id:
|
||||
bounds
|
||||
|> Map.get(:page_min_id, oldest_notification.id)
|
||||
|> to_string(),
|
||||
page_max_id:
|
||||
bounds
|
||||
|> Map.get(:page_max_id, latest_notification.id)
|
||||
|> to_string(),
|
||||
latest_page_notification_at:
|
||||
bounds
|
||||
|> Map.get(:latest_page_notification_at, latest_notification.inserted_at)
|
||||
|> CommonAPI.Utils.to_masto_date()
|
||||
})
|
||||
else
|
||||
response
|
||||
end
|
||||
|
||||
if status_activity do
|
||||
Map.put(response, :status_id, to_string(status_activity.id))
|
||||
else
|
||||
response
|
||||
end
|
||||
end
|
||||
|
||||
defp status_activity_for_group([%Notification{} = notification | _], grouped_types) do
|
||||
status_activity_for(notification, grouped_types)
|
||||
end
|
||||
|
||||
defp status_activity_for(%Notification{type: type, activity: activity}, _grouped_types)
|
||||
when type in ["mention", "status", "poll"] do
|
||||
activity
|
||||
end
|
||||
|
||||
defp status_activity_for(%Notification{type: type} = notification, grouped_types)
|
||||
when type in ["favourite", "reblog"] do
|
||||
group_key = Notification.group_key(notification, grouped_types)
|
||||
|
||||
case String.split(group_key, "-", parts: 3) do
|
||||
[^type, activity_id, _bucket] ->
|
||||
case Activity.create_by_id_with_object(activity_id) do
|
||||
%Activity{} = activity -> activity
|
||||
_ -> parent_status_activity(notification.activity)
|
||||
end
|
||||
|
||||
_ ->
|
||||
parent_status_activity(notification.activity)
|
||||
end
|
||||
end
|
||||
|
||||
defp status_activity_for(%Notification{type: type, activity: activity}, _grouped_types)
|
||||
when type in ["update", "pleroma:emoji_reaction"] do
|
||||
parent_status_activity(activity)
|
||||
end
|
||||
|
||||
defp status_activity_for(_, _grouped_types), do: nil
|
||||
|
||||
defp parent_status_activity(activity) do
|
||||
Activity.get_create_by_object_ap_id(object_id_for(activity))
|
||||
end
|
||||
|
||||
defp notification_actors(notifications) do
|
||||
notifications
|
||||
|> Enum.map(&User.get_cached_by_ap_id(&1.activity.data["actor"]))
|
||||
|> Enum.filter(& &1)
|
||||
|> Enum.uniq_by(& &1.id)
|
||||
end
|
||||
|
||||
defp put_emoji(response, activity) do
|
||||
response
|
||||
|> Map.put(:emoji, activity.data["content"])
|
||||
|
|
|
|||
|
|
@ -620,6 +620,7 @@ defmodule Pleroma.Web.MastodonAPI.StatusView do
|
|||
String.contains?(media_type, "image") -> "image"
|
||||
String.contains?(media_type, "video") -> "video"
|
||||
String.contains?(media_type, "audio") -> "audio"
|
||||
attachment["type"] == "Image" -> "image"
|
||||
true -> "unknown"
|
||||
end
|
||||
|
||||
|
|
|
|||
|
|
@ -208,6 +208,7 @@ defmodule Pleroma.Web.MediaProxy.MediaProxyController do
|
|||
|
||||
defp media_proxy_opts do
|
||||
Config.get([:media_proxy, :proxy_opts], [])
|
||||
|> Keyword.put_new(:sniff_content_type, true)
|
||||
end
|
||||
|
||||
defp sandbox(conn, _params) do
|
||||
|
|
|
|||
|
|
@ -41,6 +41,7 @@ defmodule Pleroma.Web.PleromaAPI.ChatController do
|
|||
)
|
||||
|
||||
plug(Pleroma.Web.ApiSpec.CastAndValidate, replace_params: false)
|
||||
plug(:ensure_chats_enabled)
|
||||
|
||||
defdelegate open_api_operation(action), to: Pleroma.Web.ApiSpec.ChatOperation
|
||||
|
||||
|
|
@ -244,4 +245,16 @@ defmodule Pleroma.Web.PleromaAPI.ChatController do
|
|||
_ -> nil
|
||||
end
|
||||
end
|
||||
|
||||
defp ensure_chats_enabled(conn, _opts) do
|
||||
if Chat.enabled?() do
|
||||
conn
|
||||
else
|
||||
conn
|
||||
|> put_status(:not_found)
|
||||
|> put_view(Pleroma.Web.ErrorView)
|
||||
|> render("404.json")
|
||||
|> halt()
|
||||
end
|
||||
end
|
||||
end
|
||||
|
|
|
|||
|
|
@ -4,6 +4,7 @@
|
|||
|
||||
defmodule Pleroma.Web.Plugs.EnsureHostMatchesPlug do
|
||||
@moduledoc "Ensures Host header matches instance"
|
||||
@behaviour Plug
|
||||
|
||||
alias Pleroma.Web.Endpoint
|
||||
|
||||
|
|
|
|||
|
|
@ -4,7 +4,7 @@
|
|||
|
||||
defmodule Pleroma.Web.Plugs.InstanceStatic do
|
||||
require Pleroma.Constants
|
||||
import Plug.Conn, only: [put_resp_header: 3, put_status: 2, send_resp: 3, halt: 1]
|
||||
import Plug.Conn, only: [put_resp_header: 3]
|
||||
|
||||
@moduledoc """
|
||||
This is a shim to call `Plug.Static` but with runtime `from` configuration.
|
||||
|
|
@ -51,37 +51,10 @@ defmodule Pleroma.Web.Plugs.InstanceStatic do
|
|||
|> Map.put(:from, from)
|
||||
|> Map.put(:content_types, false)
|
||||
|
||||
conn =
|
||||
conn
|
||||
|> set_content_type(conn.request_path)
|
||||
|> Plug.Static.call(opts)
|
||||
conn = set_content_type(conn, conn.request_path)
|
||||
|
||||
if conn.halted do
|
||||
conn
|
||||
else
|
||||
path = String.trim_leading(conn.request_path, "/")
|
||||
|
||||
if not File.exists?(file_path(path)) do
|
||||
conn
|
||||
|> put_status(:not_found)
|
||||
|> send_404()
|
||||
|> halt()
|
||||
else
|
||||
conn
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
defp send_404(conn) do
|
||||
if String.ends_with?(String.downcase(conn.request_path), ".json") do
|
||||
conn
|
||||
|> put_resp_header("content-type", "application/json")
|
||||
|> send_resp(404, Jason.encode!(%{error: "not found"}))
|
||||
else
|
||||
conn
|
||||
|> put_resp_header("content-type", "text/plain")
|
||||
|> send_resp(404, "Not found")
|
||||
end
|
||||
# Call Plug.Static with our sanitized content-type
|
||||
Plug.Static.call(conn, opts)
|
||||
end
|
||||
|
||||
defp set_content_type(conn, "/emoji/" <> filepath) do
|
||||
|
|
|
|||
|
|
@ -52,7 +52,7 @@ defmodule Pleroma.Web.Plugs.OAuthPlug do
|
|||
where: t.token == ^token
|
||||
)
|
||||
|
||||
with %Token{user_id: user_id} = token_record <- Repo.one(token_query) |> Repo.preload(:user),
|
||||
with %Token{user_id: user_id} = token_record <- Repo.one(token_query),
|
||||
false <- is_nil(user_id),
|
||||
%User{} = user <- User.get_cached_by_id(user_id) do
|
||||
{:ok, user, token_record}
|
||||
|
|
|
|||
38
lib/pleroma/web/plugs/static_not_found_plug.ex
Normal file
38
lib/pleroma/web/plugs/static_not_found_plug.ex
Normal file
|
|
@ -0,0 +1,38 @@
|
|||
# Pleroma: A lightweight social networking server
|
||||
# Copyright © 2017-2026 Pleroma Authors <https://pleroma.social/>
|
||||
# SPDX-License-Identifier: AGPL-3.0-only
|
||||
|
||||
defmodule Pleroma.Web.Plugs.StaticNotFoundPlug do
|
||||
@moduledoc """
|
||||
A small plug that enforces returning 404 on static files when they don't exist.
|
||||
"""
|
||||
@behaviour Plug
|
||||
|
||||
require Pleroma.Constants
|
||||
import Plug.Conn, only: [put_resp_header: 3, send_resp: 3, halt: 1]
|
||||
|
||||
def init(opts), do: opts
|
||||
|
||||
for only <- Pleroma.Constants.static_only_files() do
|
||||
def call(%{request_path: "/" <> unquote(only) <> _} = conn, _opts) do
|
||||
send_404(conn)
|
||||
end
|
||||
end
|
||||
|
||||
def call(conn, _) do
|
||||
conn
|
||||
end
|
||||
|
||||
defp send_404(conn) do
|
||||
if String.ends_with?(String.downcase(conn.request_path), ".json") do
|
||||
conn
|
||||
|> put_resp_header("content-type", "application/json")
|
||||
|> send_resp(404, Jason.encode!(%{error: "not found"}))
|
||||
else
|
||||
conn
|
||||
|> put_resp_header("content-type", "text/plain")
|
||||
|> send_resp(404, "Not found")
|
||||
end
|
||||
|> halt()
|
||||
end
|
||||
end
|
||||
|
|
@ -4,6 +4,8 @@
|
|||
|
||||
defmodule Pleroma.Web.RichMedia.Helpers do
|
||||
alias Pleroma.Config
|
||||
alias Pleroma.Gun.ConnectionPool
|
||||
alias Pleroma.ReverseProxy.Client.Tesla, as: TeslaClient
|
||||
|
||||
require Logger
|
||||
|
||||
|
|
@ -19,12 +21,30 @@ defmodule Pleroma.Web.RichMedia.Helpers do
|
|||
end
|
||||
|
||||
defp stream(url) do
|
||||
with {_, {:ok, %Tesla.Env{status: 200, body: stream_body, headers: headers}}} <-
|
||||
{:get, Pleroma.HTTP.get(url, req_headers(), http_options())},
|
||||
{_, :ok} <- {:content_type, check_content_type(headers)},
|
||||
{_, :ok} <- {:content_length, check_content_length(headers)},
|
||||
{:read_stream, {:ok, body}} <- {:read_stream, read_stream(stream_body)} do
|
||||
{:ok, body}
|
||||
case Pleroma.HTTP.get(url, req_headers(), http_options()) do
|
||||
{:ok, %Tesla.Env{status: 200, body: stream_body, headers: headers}} ->
|
||||
result =
|
||||
try do
|
||||
with {_, :ok} <- {:content_type, check_content_type(headers)},
|
||||
{_, :ok} <- {:content_length, check_content_length(headers)},
|
||||
{:read_stream, {:ok, body}} <- {:read_stream, read_stream(stream_body)} do
|
||||
{:ok, body}
|
||||
end
|
||||
rescue
|
||||
exception ->
|
||||
cleanup_stream(stream_body, :error)
|
||||
reraise exception, __STACKTRACE__
|
||||
end
|
||||
|
||||
cleanup_stream(stream_body, result)
|
||||
result
|
||||
|
||||
{:ok, %Tesla.Env{body: stream_body}} = response ->
|
||||
cleanup_stream(stream_body, :rejected)
|
||||
{:get, response}
|
||||
|
||||
response ->
|
||||
{:get, response}
|
||||
end
|
||||
end
|
||||
|
||||
|
|
@ -95,6 +115,10 @@ defmodule Pleroma.Web.RichMedia.Helpers do
|
|||
end
|
||||
end
|
||||
|
||||
defp read_stream(%{pid: pid, stream: stream, opts: opts}) do
|
||||
read_chunks(pid, stream, opts, "", 0, Keyword.get(http_options(), :max_body))
|
||||
end
|
||||
|
||||
defp read_stream(stream) do
|
||||
max_body = Keyword.get(http_options(), :max_body)
|
||||
|
||||
|
|
@ -117,6 +141,33 @@ defmodule Pleroma.Web.RichMedia.Helpers do
|
|||
end
|
||||
end
|
||||
|
||||
defp read_chunks(pid, stream, opts, acc, total_bytes, max_body) do
|
||||
case Tesla.Adapter.Gun.read_chunk(pid, stream, opts) do
|
||||
{fin, chunk} when fin in [:fin, :nofin] ->
|
||||
total_bytes = total_bytes + byte_size(chunk)
|
||||
|
||||
cond do
|
||||
total_bytes > max_body ->
|
||||
:error
|
||||
|
||||
fin == :fin ->
|
||||
{:ok, acc <> chunk}
|
||||
|
||||
true ->
|
||||
read_chunks(pid, stream, opts, acc <> chunk, total_bytes, max_body)
|
||||
end
|
||||
|
||||
{:error, _reason} ->
|
||||
:error
|
||||
end
|
||||
end
|
||||
|
||||
defp cleanup_stream(%{pid: pid, stream: stream}, {:ok, _body}),
|
||||
do: ConnectionPool.release_stream(pid, stream)
|
||||
|
||||
defp cleanup_stream(%{pid: _pid} = client, _result), do: TeslaClient.close(client)
|
||||
defp cleanup_stream(_stream, _result), do: :ok
|
||||
|
||||
defp http_options do
|
||||
[
|
||||
pool: :rich_media,
|
||||
|
|
|
|||
|
|
@ -844,6 +844,16 @@ defmodule Pleroma.Web.Router do
|
|||
get("/directory", DirectoryController, :index)
|
||||
end
|
||||
|
||||
scope "/api/v2", Pleroma.Web.MastodonAPI do
|
||||
pipe_through(:authenticated_api)
|
||||
|
||||
get("/notifications", NotificationController, :grouped_index)
|
||||
get("/notifications/unread_count", NotificationController, :unread_count)
|
||||
get("/notifications/:group_key/accounts", NotificationController, :group_accounts)
|
||||
get("/notifications/:group_key", NotificationController, :show_group)
|
||||
post("/notifications/:group_key/dismiss", NotificationController, :dismiss_group)
|
||||
end
|
||||
|
||||
scope "/api/v2", Pleroma.Web.MastodonAPI do
|
||||
pipe_through(:api)
|
||||
|
||||
|
|
|
|||
|
|
@ -195,6 +195,9 @@ defmodule Pleroma.Web.Streamer do
|
|||
recipients = MapSet.new(item.recipients)
|
||||
domain_blocks = Pleroma.Web.ActivityPub.MRF.subdomains_regex(user.domain_blocks)
|
||||
|
||||
following_ap_ids =
|
||||
if user.domain_blocks == [], do: [], else: User.get_cached_user_friends_ap_ids(user)
|
||||
|
||||
with parent <- Object.normalize(item, fetch: false) || item,
|
||||
true <- Enum.all?([blocked_ap_ids, muted_ap_ids], &(item.actor not in &1)),
|
||||
true <- item.data["type"] != "Announce" || item.actor not in reblog_muted_ap_ids,
|
||||
|
|
@ -205,8 +208,12 @@ defmodule Pleroma.Web.Streamer do
|
|||
true <- MapSet.disjoint?(recipients, recipient_blocks),
|
||||
%{host: item_host} <- URI.parse(item.actor),
|
||||
%{host: parent_host} <- URI.parse(parent.data["actor"]),
|
||||
false <- Pleroma.Web.ActivityPub.MRF.subdomain_match?(domain_blocks, item_host),
|
||||
false <- Pleroma.Web.ActivityPub.MRF.subdomain_match?(domain_blocks, parent_host),
|
||||
false <-
|
||||
item.actor not in following_ap_ids and
|
||||
Pleroma.Web.ActivityPub.MRF.subdomain_match?(domain_blocks, item_host),
|
||||
false <-
|
||||
parent.data["actor"] not in following_ap_ids and
|
||||
Pleroma.Web.ActivityPub.MRF.subdomain_match?(domain_blocks, parent_host),
|
||||
true <- thread_containment(item, user),
|
||||
false <- CommonAPI.thread_muted?(parent, user) do
|
||||
false
|
||||
|
|
@ -289,15 +296,17 @@ defmodule Pleroma.Web.Streamer do
|
|||
|
||||
defp do_stream(topic, {user, %MessageReference{} = cm_ref})
|
||||
when topic in ["user", "user:pleroma_chat"] do
|
||||
topic = "#{topic}:#{user.id}"
|
||||
if Pleroma.Chat.enabled?() do
|
||||
topic = "#{topic}:#{user.id}"
|
||||
|
||||
text = StreamerView.render("chat_update.json", %{chat_message_reference: cm_ref}, topic)
|
||||
text = StreamerView.render("chat_update.json", %{chat_message_reference: cm_ref}, topic)
|
||||
|
||||
Registry.dispatch(@registry, topic, fn list ->
|
||||
Enum.each(list, fn {pid, _auth} ->
|
||||
send(pid, {:text, text})
|
||||
Registry.dispatch(@registry, topic, fn list ->
|
||||
Enum.each(list, fn {pid, _auth} ->
|
||||
send(pid, {:text, text})
|
||||
end)
|
||||
end)
|
||||
end)
|
||||
end
|
||||
end
|
||||
|
||||
defp do_stream("user", %Activity{} = item) do
|
||||
|
|
|
|||
|
|
@ -1,9 +1,9 @@
|
|||
<entry>
|
||||
<activity:object-type>http://activitystrea.ms/schema/1.0/note</activity:object-type>
|
||||
<activity:verb>http://activitystrea.ms/schema/1.0/post</activity:verb>
|
||||
<id><%= @data["id"] %></id>
|
||||
<id><%= escape(@data["id"] || "") %></id>
|
||||
<title><%= activity_title(@data, Keyword.get(@feed_config, :post_title, %{})) %></title>
|
||||
<content type="html"><%= activity_description(@data) %></content>
|
||||
<content type="html"><%= escape(atom_content_encoded(@data)) %></content>
|
||||
<published><%= to_rfc3339(@data["published"]) %></published>
|
||||
<updated><%= to_rfc3339(@data["published"]) %></updated>
|
||||
<ostatus:conversation ref="<%= activity_context(@activity) %>">
|
||||
|
|
@ -15,35 +15,26 @@
|
|||
<summary><%= escape(@data["summary"]) %></summary>
|
||||
<% end %>
|
||||
|
||||
<%= if @activity.local do %>
|
||||
<link type="application/atom+xml" href='<%= @data["id"] %>' rel="self"/>
|
||||
<link type="text/html" href='<%= @data["id"] %>' rel="alternate"/>
|
||||
<% else %>
|
||||
<link type="text/html" href='<%= @data["external_url"] %>' rel="alternate"/>
|
||||
<% end %>
|
||||
<link type="text/html" href='<%= escape(activity_link(@activity, @data) || "") %>' rel="alternate"/>
|
||||
|
||||
<%= for tag <- Pleroma.Object.hashtags(@object) do %>
|
||||
<category term="<%= tag %>"></category>
|
||||
<% end %>
|
||||
|
||||
<%= for attachment <- @data["attachment"] || [] do %>
|
||||
<link rel="enclosure" href="<%= attachment_href(attachment) %>" type="<%= attachment_type(attachment) %>"/>
|
||||
<%= unless sensitive?(@data) do %>
|
||||
<%= for attachment <- @data["attachment"] || [] do %>
|
||||
<%= if size = attachment_size_positive(attachment) do %>
|
||||
<link rel="enclosure" href="<%= escape(attachment_href(attachment) || "") %>" type="<%= escape(attachment_type(attachment) || "application/octet-stream") %>" length="<%= size %>"/>
|
||||
<% else %>
|
||||
<link rel="enclosure" href="<%= escape(attachment_href(attachment) || "") %>" type="<%= escape(attachment_type(attachment) || "application/octet-stream") %>"/>
|
||||
<% end %>
|
||||
<% end %>
|
||||
<% end %>
|
||||
|
||||
<%= if @data["inReplyTo"] do %>
|
||||
<thr:in-reply-to ref='<%= @data["inReplyTo"] %>' href='<%= get_href(@data["inReplyTo"]) %>'/>
|
||||
<% end %>
|
||||
|
||||
<%= for id <- @activity.recipients do %>
|
||||
<%= if id == Pleroma.Constants.as_public() do %>
|
||||
<link rel="mentioned" ostatus:object-type="http://activitystrea.ms/schema/1.0/collection" href="http://activityschema.org/collection/public"/>
|
||||
<% else %>
|
||||
<%= unless Regex.match?(~r/^#{Pleroma.Web.Endpoint.url()}.+followers$/, id) do %>
|
||||
<link rel="mentioned" ostatus:object-type="http://activitystrea.ms/schema/1.0/person" href="<%= id %>"/>
|
||||
<% end %>
|
||||
<% end %>
|
||||
<% end %>
|
||||
|
||||
<%= for {emoji, file} <- @data["emoji"] || %{} do %>
|
||||
<link name="<%= emoji %>" rel="emoji" href="<%= file %>"/>
|
||||
<% end %>
|
||||
|
|
|
|||
|
|
@ -1,45 +1,34 @@
|
|||
<item>
|
||||
<activity:object-type>http://activitystrea.ms/schema/1.0/note</activity:object-type>
|
||||
<activity:verb>http://activitystrea.ms/schema/1.0/post</activity:verb>
|
||||
<guid><%= @data["id"] %></guid>
|
||||
<guid isPermaLink="true"><%= escape(@data["id"] || "") %></guid>
|
||||
<title><%= activity_title(@data, Keyword.get(@feed_config, :post_title, %{})) %></title>
|
||||
<description><%= activity_description(@data) %></description>
|
||||
<content:encoded><![CDATA[<%= rss_content_encoded(@data) %>]]></content:encoded>
|
||||
<pubDate><%= to_rfc2822(@data["published"]) %></pubDate>
|
||||
<ostatus:conversation ref="<%= activity_context(@activity) %>">
|
||||
<%= activity_context(@activity) %>
|
||||
</ostatus:conversation>
|
||||
|
||||
<%= if @activity.local do %>
|
||||
<link><%= @data["id"] %></link>
|
||||
<% else %>
|
||||
<link><%= @data["external_url"] %></link>
|
||||
<% end %>
|
||||
|
||||
<link rel="ostatus:conversation"><%= activity_context(@activity) %></link>
|
||||
<link><%= escape(activity_link(@activity, @data) || "") %></link>
|
||||
|
||||
<%= for tag <- Pleroma.Object.hashtags(@object) do %>
|
||||
<category term="<%= tag %>"></category>
|
||||
<%= if tag && tag != "" do %>
|
||||
<category><%= tag %></category>
|
||||
<% end %>
|
||||
<% end %>
|
||||
|
||||
<%= unless sensitive?(@data) do %>
|
||||
<%= with attachment when not is_nil(attachment) <- rss_enclosure_attachment(@data["attachment"]) do %>
|
||||
<enclosure url="<%= escape(attachment_href(attachment) || "") %>" type="<%= escape(attachment_type(attachment) || "application/octet-stream") %>" length="<%= attachment_size_positive(attachment) %>" />
|
||||
<% end %>
|
||||
<% end %>
|
||||
|
||||
<%= for attachment <- @data["attachment"] || [] do %>
|
||||
<enclosure url="<%= attachment_href(attachment) %>" type="<%= attachment_type(attachment) %>" />
|
||||
<%= media_content_xml(attachment, sensitive?(@data)) %>
|
||||
<% end %>
|
||||
|
||||
<%= if @data["inReplyTo"] do %>
|
||||
<thr:in-reply-to ref='<%= @data["inReplyTo"] %>' href='<%= get_href(@data["inReplyTo"]) %>'/>
|
||||
<% end %>
|
||||
|
||||
<%= for id <- @activity.recipients do %>
|
||||
<%= if id == Pleroma.Constants.as_public() do %>
|
||||
<link rel="mentioned" ostatus:object-type="http://activitystrea.ms/schema/1.0/collection">http://activityschema.org/collection/public</link>
|
||||
<% else %>
|
||||
<%= unless Regex.match?(~r/^#{Pleroma.Web.Endpoint.url()}.+followers$/, id) do %>
|
||||
<link rel="mentioned" ostatus:object-type="http://activitystrea.ms/schema/1.0/person"><%= id %></link>
|
||||
<% end %>
|
||||
<% end %>
|
||||
<% end %>
|
||||
|
||||
<%= for {emoji, file} <- @data["emoji"] || %{} do %>
|
||||
<link name="<%= emoji %>" rel="emoji"><%= file %></link>
|
||||
<% end %>
|
||||
</item>
|
||||
|
|
|
|||
|
|
@ -4,9 +4,9 @@
|
|||
|
||||
<%= render Phoenix.Controller.view_module(@conn), "_tag_author.atom", assigns %>
|
||||
|
||||
<id><%= @data["id"] %></id>
|
||||
<id><%= escape(@data["id"] || "") %></id>
|
||||
<title><%= activity_title(@data, Keyword.get(@feed_config, :post_title, %{})) %></title>
|
||||
<content type="html"><%= activity_description(@data) %></content>
|
||||
<content type="html"><%= escape(atom_content_encoded(@data)) %></content>
|
||||
<published><%= to_rfc3339(@data["published"]) %></published>
|
||||
<updated><%= to_rfc3339(@data["published"]) %></updated>
|
||||
<ostatus:conversation ref="<%= activity_context(@activity) %>">
|
||||
|
|
@ -15,34 +15,25 @@
|
|||
<link href="<%= activity_context(@activity) %>" rel="ostatus:conversation"/>
|
||||
|
||||
<%= if @data["summary"] != "" do %>
|
||||
<summary><%= @data["summary"] %></summary>
|
||||
<summary><%= escape(@data["summary"]) %></summary>
|
||||
<% end %>
|
||||
|
||||
<%= if @activity.local do %>
|
||||
<link type="application/atom+xml" href='<%= @data["id"] %>' rel="self"/>
|
||||
<link type="text/html" href='<%= @data["id"] %>' rel="alternate"/>
|
||||
<% else %>
|
||||
<link type="text/html" href='<%= @data["external_url"] %>' rel="alternate"/>
|
||||
<% end %>
|
||||
|
||||
<%= for id <- @activity.recipients do %>
|
||||
<%= if id == Pleroma.Constants.as_public() do %>
|
||||
<link rel="mentioned"
|
||||
ostatus:object-type="http://activitystrea.ms/schema/1.0/collection"
|
||||
href="http://activityschema.org/collection/public"/>
|
||||
<% else %>
|
||||
<%= unless Regex.match?(~r/^#{Pleroma.Web.Endpoint.url()}.+followers$/, id) do %>
|
||||
<link rel="mentioned"
|
||||
ostatus:object-type="http://activitystrea.ms/schema/1.0/person"
|
||||
href="<%= id %>" />
|
||||
<% end %>
|
||||
<% end %>
|
||||
<% end %>
|
||||
<link type="text/html" href='<%= escape(activity_link(@activity, @data) || "") %>' rel="alternate"/>
|
||||
|
||||
<%= for tag <- Pleroma.Object.hashtags(@object) do %>
|
||||
<category term="<%= tag %>"></category>
|
||||
<% end %>
|
||||
|
||||
<%= unless sensitive?(@data) do %>
|
||||
<%= for attachment <- @data["attachment"] || [] do %>
|
||||
<%= if size = attachment_size_positive(attachment) do %>
|
||||
<link rel="enclosure" href="<%= escape(attachment_href(attachment) || "") %>" type="<%= escape(attachment_type(attachment) || "application/octet-stream") %>" length="<%= size %>"/>
|
||||
<% else %>
|
||||
<link rel="enclosure" href="<%= escape(attachment_href(attachment) || "") %>" type="<%= escape(attachment_type(attachment) || "application/octet-stream") %>"/>
|
||||
<% end %>
|
||||
<% end %>
|
||||
<% end %>
|
||||
|
||||
<%= for {emoji, file} <- @data["emoji"] || %{} do %>
|
||||
<link name="<%= emoji %>" rel="emoji" href="<%= file %>"/>
|
||||
<% end %>
|
||||
|
|
|
|||
|
|
@ -1,14 +1,24 @@
|
|||
<item>
|
||||
<title><%= activity_title(@data, Keyword.get(@feed_config, :post_title, %{})) %></title>
|
||||
|
||||
|
||||
<guid isPermalink="true"><%= activity_context(@activity) %></guid>
|
||||
<link><%= activity_context(@activity) %></link>
|
||||
<guid isPermaLink="true"><%= escape(activity_link(@activity, @data) || "") %></guid>
|
||||
<link><%= escape(activity_link(@activity, @data) || "") %></link>
|
||||
<pubDate><%= to_rfc2822(@data["published"]) %></pubDate>
|
||||
|
||||
<title><%= activity_title(@data, Keyword.get(@feed_config, :post_title, %{})) %></title>
|
||||
<description><%= activity_description(@data) %></description>
|
||||
<%= for attachment <- @data["attachment"] || [] do %>
|
||||
<enclosure url="<%= attachment_href(attachment) %>" type="<%= attachment_type(attachment) %>"/>
|
||||
<content:encoded><![CDATA[<%= rss_content_encoded(@data) %>]]></content:encoded>
|
||||
|
||||
<%= unless sensitive?(@data) do %>
|
||||
<%= with attachment when not is_nil(attachment) <- rss_enclosure_attachment(@data["attachment"]) do %>
|
||||
<enclosure url="<%= escape(attachment_href(attachment) || "") %>" type="<%= escape(attachment_type(attachment) || "application/octet-stream") %>" length="<%= attachment_size_positive(attachment) %>"/>
|
||||
<% end %>
|
||||
<% end %>
|
||||
|
||||
<%= for attachment <- @data["attachment"] || [] do %>
|
||||
<%= media_content_xml(attachment, sensitive?(@data)) %>
|
||||
<% end %>
|
||||
|
||||
<%= for tag <- Pleroma.Object.hashtags(@object) do %>
|
||||
<%= if tag && tag != "" do %>
|
||||
<category><%= tag %></category>
|
||||
<% end %>
|
||||
<% end %>
|
||||
</item>
|
||||
|
|
|
|||
|
|
@ -9,10 +9,12 @@
|
|||
|
||||
<id><%= Routes.tag_feed_url(@conn, :feed, @tag) <> ".atom" %></id>
|
||||
<title>#<%= @tag %></title>
|
||||
<subtitle><%= Gettext.dpgettext("static_pages", "tag feed description", "These are public toots tagged with #%{tag}. You can interact with them if you have an account anywhere in the fediverse.", tag: @tag) %></subtitle>
|
||||
<%= with subtitle when subtitle not in [nil, ""] <- Gettext.dpgettext("static_pages", "tag feed description", "These are public toots tagged with #%{tag}. You can interact with them if you have an account anywhere in the fediverse.", tag: @tag) do %>
|
||||
<subtitle><%= subtitle %></subtitle>
|
||||
<% end %>
|
||||
<logo><%= feed_logo() %></logo>
|
||||
<updated><%= most_recent_update(@activities) %></updated>
|
||||
<link rel="self" href="<%= "#{Routes.tag_feed_url(@conn, :feed, @tag)}.atom" %>" type="application/atom+xml"/>
|
||||
<updated><%= most_recent_update(@activities) || to_rfc3339(NaiveDateTime.utc_now()) %></updated>
|
||||
<link rel="self" href="<%= feed_self_url(@conn) %>" type="application/atom+xml"/>
|
||||
|
||||
<%= for activity <- @activities do %>
|
||||
<%= render Phoenix.Controller.view_module(@conn), "_tag_activity.atom", Map.merge(assigns, prepare_activity(activity, actor: true)) %>
|
||||
|
|
|
|||
|
|
@ -1,6 +1,8 @@
|
|||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<rss version="2.0"
|
||||
xmlns:webfeeds="http://webfeeds.org/rss/1.0"
|
||||
xmlns:content="http://purl.org/rss/1.0/modules/content/"
|
||||
xmlns:media="http://search.yahoo.com/mrss/"
|
||||
xmlns:thr="http://purl.org/syndication/thread/1.0">
|
||||
<channel>
|
||||
|
||||
|
|
@ -8,7 +10,12 @@
|
|||
<description><%= Gettext.dpgettext("static_pages", "tag feed description", "These are public toots tagged with #%{tag}. You can interact with them if you have an account anywhere in the fediverse.", tag: @tag) %></description>
|
||||
<link><%= "#{Routes.tag_feed_url(@conn, :feed, @tag)}.rss" %></link>
|
||||
<webfeeds:logo><%= feed_logo() %></webfeeds:logo>
|
||||
<webfeeds:icon><%= feed_logo() %></webfeeds:icon>
|
||||
<webfeeds:accentColor>2b90d9</webfeeds:accentColor>
|
||||
<%= with last_build_date when not is_nil(last_build_date) <- most_recent_update(@activities, :rss) do %>
|
||||
<lastBuildDate><%= last_build_date %></lastBuildDate>
|
||||
<% end %>
|
||||
<generator><%= Pleroma.Application.named_version() %></generator>
|
||||
<%= for activity <- @activities do %>
|
||||
<%= render Phoenix.Controller.view_module(@conn), "_tag_activity.xml", Map.merge(assigns, prepare_activity(activity)) %>
|
||||
<% end %>
|
||||
|
|
|
|||
|
|
@ -8,10 +8,12 @@
|
|||
|
||||
<id><%= Routes.user_feed_url(@conn, :feed, @user.nickname) <> ".atom" %></id>
|
||||
<title><%= @user.nickname <> "'s timeline" %></title>
|
||||
<subtitle><%= escape(@user.bio) %></subtitle>
|
||||
<%= if @user.bio && @user.bio != "" do %>
|
||||
<subtitle><%= escape(@user.bio) %></subtitle>
|
||||
<% end %>
|
||||
<updated><%= most_recent_update(@activities, @user, :atom) %></updated>
|
||||
<logo><%= logo(@user) %></logo>
|
||||
<link rel="self" href="<%= "#{Routes.user_feed_url(@conn, :feed, @user.nickname)}.atom" %>" type="application/atom+xml"/>
|
||||
<link rel="self" href="<%= feed_self_url(@conn) %>" type="application/atom+xml"/>
|
||||
|
||||
<%= render Phoenix.Controller.view_module(@conn), "_author.atom", assigns %>
|
||||
|
||||
|
|
|
|||
|
|
@ -1,26 +1,32 @@
|
|||
<?xml version="1.0" encoding="UTF-8" ?>
|
||||
<rss version="2.0"
|
||||
xmlns:atom="http://www.w3.org/2005/Atom"
|
||||
xmlns:content="http://purl.org/rss/1.0/modules/content/"
|
||||
xmlns:webfeeds="http://webfeeds.org/rss/1.0"
|
||||
xmlns:media="http://search.yahoo.com/mrss/"
|
||||
xmlns:thr="http://purl.org/syndication/thread/1.0"
|
||||
xmlns:activity="http://activitystrea.ms/spec/1.0/"
|
||||
xmlns:ostatus="http://ostatus.org/schema/1.0"
|
||||
xmlns:poco="http://portablecontacts.net/spec/1.0">
|
||||
<channel>
|
||||
<title><%= @user.nickname <> "'s timeline" %></title>
|
||||
<link><%= "#{Routes.user_feed_url(@conn, :feed, @user.nickname)}.rss" %></link>
|
||||
<atom:link href="<%= Routes.user_feed_url(@conn, :feed, @user.nickname) <> ".atom" %>"
|
||||
<atom:link href="<%= feed_self_url(@conn) %>"
|
||||
rel="self" type="application/rss+xml" />
|
||||
<link><%= "#{Routes.user_feed_url(@conn, :feed, @user.nickname)}.rss" %></link>
|
||||
<description><%= escape(@user.bio) %></description>
|
||||
<image>
|
||||
<url><%= logo(@user) %></url>
|
||||
<title><%= @user.nickname <> "'s timeline" %></title>
|
||||
<link><%= "#{Routes.user_feed_url(@conn, :feed, @user.nickname)}.rss" %></link>
|
||||
</image>
|
||||
<lastBuildDate><%= most_recent_update(@activities, @user, :rss) %></lastBuildDate>
|
||||
<webfeeds:icon><%= logo(@user) %></webfeeds:icon>
|
||||
<generator><%= Pleroma.Application.named_version() %></generator>
|
||||
|
||||
<%= render Phoenix.Controller.view_module(@conn), "_author.rss", assigns %>
|
||||
|
||||
<%= if last_activity(@activities) do %>
|
||||
<link rel="next"><%= "#{Routes.user_feed_url(@conn, :feed, @user.nickname)}.rss?max_id=#{last_activity(@activities).id}" %></link>
|
||||
<atom:link rel="next" href="<%= "#{Routes.user_feed_url(@conn, :feed, @user.nickname)}.rss?max_id=#{last_activity(@activities).id}" %>" />
|
||||
<% end %>
|
||||
|
||||
<%= for activity <- @activities do %>
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue