Merge branch 'develop' into 'fix/2411-mutes-api'
# Conflicts: # CHANGELOG.md # docs/development/API/differences_in_mastoapi_responses.md
This commit is contained in:
commit
d289ad8579
187 changed files with 1031 additions and 509 deletions
|
|
@ -146,6 +146,7 @@ defmodule Pleroma.User do
|
|||
field(:inbox, :string)
|
||||
field(:shared_inbox, :string)
|
||||
field(:accepts_chat_messages, :boolean, default: nil)
|
||||
field(:last_active_at, :naive_datetime)
|
||||
|
||||
embeds_one(
|
||||
:notification_settings,
|
||||
|
|
@ -2444,4 +2445,19 @@ defmodule Pleroma.User do
|
|||
def get_host(%User{ap_id: ap_id} = _user) do
|
||||
URI.parse(ap_id).host
|
||||
end
|
||||
|
||||
def update_last_active_at(%__MODULE__{local: true} = user) do
|
||||
user
|
||||
|> cast(%{last_active_at: NaiveDateTime.utc_now()}, [:last_active_at])
|
||||
|> update_and_set_cache()
|
||||
end
|
||||
|
||||
def active_user_count(weeks \\ 4) do
|
||||
active_after = Timex.shift(NaiveDateTime.utc_now(), weeks: -weeks)
|
||||
|
||||
__MODULE__
|
||||
|> where([u], u.last_active_at >= ^active_after)
|
||||
|> where([u], u.local == true)
|
||||
|> Repo.aggregate(:count)
|
||||
end
|
||||
end
|
||||
|
|
|
|||
|
|
@ -735,6 +735,12 @@ defmodule Pleroma.Web.ActivityPub.ActivityPub do
|
|||
|
||||
defp restrict_local(query, _), do: query
|
||||
|
||||
defp restrict_remote(query, %{remote: true}) do
|
||||
from(activity in query, where: activity.local == false)
|
||||
end
|
||||
|
||||
defp restrict_remote(query, _), do: query
|
||||
|
||||
defp restrict_actor(query, %{actor_id: actor_id}) do
|
||||
from(activity in query, where: activity.actor == ^actor_id)
|
||||
end
|
||||
|
|
@ -1111,6 +1117,7 @@ defmodule Pleroma.Web.ActivityPub.ActivityPub do
|
|||
|> restrict_tag_all(opts)
|
||||
|> restrict_since(opts)
|
||||
|> restrict_local(opts)
|
||||
|> restrict_remote(opts)
|
||||
|> restrict_actor(opts)
|
||||
|> restrict_type(opts)
|
||||
|> restrict_state(opts)
|
||||
|
|
|
|||
|
|
@ -133,7 +133,7 @@ defmodule Pleroma.Web.ApiSpec.AccountOperation do
|
|||
:with_muted,
|
||||
:query,
|
||||
BooleanLike,
|
||||
"Include statuses from muted acccounts."
|
||||
"Include statuses from muted accounts."
|
||||
),
|
||||
Operation.parameter(:exclude_reblogs, :query, BooleanLike, "Exclude reblogs"),
|
||||
Operation.parameter(:exclude_replies, :query, BooleanLike, "Exclude replies"),
|
||||
|
|
@ -147,7 +147,7 @@ defmodule Pleroma.Web.ApiSpec.AccountOperation do
|
|||
:with_muted,
|
||||
:query,
|
||||
BooleanLike,
|
||||
"Include reactions from muted acccounts."
|
||||
"Include reactions from muted accounts."
|
||||
)
|
||||
] ++ pagination_params(),
|
||||
responses: %{
|
||||
|
|
|
|||
|
|
@ -25,6 +25,8 @@ defmodule Pleroma.Web.ApiSpec.TimelineOperation do
|
|||
security: [%{"oAuth" => ["read:statuses"]}],
|
||||
parameters: [
|
||||
local_param(),
|
||||
remote_param(),
|
||||
only_media_param(),
|
||||
with_muted_param(),
|
||||
exclude_visibilities_param(),
|
||||
reply_visibility_param() | pagination_params()
|
||||
|
|
@ -61,6 +63,7 @@ defmodule Pleroma.Web.ApiSpec.TimelineOperation do
|
|||
local_param(),
|
||||
instance_param(),
|
||||
only_media_param(),
|
||||
remote_param(),
|
||||
with_muted_param(),
|
||||
exclude_visibilities_param(),
|
||||
reply_visibility_param() | pagination_params()
|
||||
|
|
@ -107,6 +110,7 @@ defmodule Pleroma.Web.ApiSpec.TimelineOperation do
|
|||
),
|
||||
local_param(),
|
||||
only_media_param(),
|
||||
remote_param(),
|
||||
with_muted_param(),
|
||||
exclude_visibilities_param() | pagination_params()
|
||||
],
|
||||
|
|
@ -132,6 +136,9 @@ defmodule Pleroma.Web.ApiSpec.TimelineOperation do
|
|||
required: true
|
||||
),
|
||||
with_muted_param(),
|
||||
local_param(),
|
||||
remote_param(),
|
||||
only_media_param(),
|
||||
exclude_visibilities_param() | pagination_params()
|
||||
],
|
||||
operationId: "TimelineController.list",
|
||||
|
|
@ -198,4 +205,13 @@ defmodule Pleroma.Web.ApiSpec.TimelineOperation do
|
|||
"Show only statuses with media attached?"
|
||||
)
|
||||
end
|
||||
|
||||
defp remote_param do
|
||||
Operation.parameter(
|
||||
:remote,
|
||||
:query,
|
||||
%Schema{allOf: [BooleanLike], default: false},
|
||||
"Show only remote statuses?"
|
||||
)
|
||||
end
|
||||
end
|
||||
|
|
|
|||
|
|
@ -23,6 +23,18 @@ defmodule Pleroma.Web.Endpoint do
|
|||
# InstanceStatic needs to be before Plug.Static to be able to override shipped-static files
|
||||
# If you're adding new paths to `only:` you'll need to configure them in InstanceStatic as well
|
||||
# Cache-control headers are duplicated in case we turn off etags in the future
|
||||
plug(
|
||||
Pleroma.Web.Plugs.InstanceStatic,
|
||||
at: "/",
|
||||
from: :pleroma,
|
||||
only: ["emoji", "images"],
|
||||
gzip: true,
|
||||
cache_control_for_etags: "public, max-age=1209600",
|
||||
headers: %{
|
||||
"cache-control" => "public, max-age=1209600"
|
||||
}
|
||||
)
|
||||
|
||||
plug(Pleroma.Web.Plugs.InstanceStatic,
|
||||
at: "/",
|
||||
gzip: true,
|
||||
|
|
|
|||
|
|
@ -51,6 +51,8 @@ defmodule Pleroma.Web.MastodonAPI.TimelineController do
|
|||
|> Map.put(:reply_filtering_user, user)
|
||||
|> Map.put(:announce_filtering_user, user)
|
||||
|> Map.put(:user, user)
|
||||
|> Map.put(:local_only, params[:local])
|
||||
|> Map.delete(:local)
|
||||
|
||||
activities =
|
||||
[user.ap_id | User.following(user)]
|
||||
|
|
@ -190,6 +192,7 @@ defmodule Pleroma.Web.MastodonAPI.TimelineController do
|
|||
|> Map.put(:blocking_user, user)
|
||||
|> Map.put(:user, user)
|
||||
|> Map.put(:muting_user, user)
|
||||
|> Map.put(:local_only, params[:local])
|
||||
|
||||
# we must filter the following list for the user to avoid leaking statuses the user
|
||||
# does not actually have permission to see (for more info, peruse security issue #270).
|
||||
|
|
|
|||
|
|
@ -45,6 +45,7 @@ defmodule Pleroma.Web.MastodonAPI.InstanceView do
|
|||
fields_limits: fields_limits(),
|
||||
post_formats: Config.get([:instance, :allowed_post_formats])
|
||||
},
|
||||
stats: %{mau: Pleroma.User.active_user_count()},
|
||||
vapid_public_key: Keyword.get(Pleroma.Web.Push.vapid_config(), :public_key)
|
||||
}
|
||||
}
|
||||
|
|
|
|||
30
lib/pleroma/web/plugs/user_tracking_plug.ex
Normal file
30
lib/pleroma/web/plugs/user_tracking_plug.ex
Normal file
|
|
@ -0,0 +1,30 @@
|
|||
# Pleroma: A lightweight social networking server
|
||||
# Copyright © 2017-2021 Pleroma Authors <https://pleroma.social/>
|
||||
# SPDX-License-Identifier: AGPL-3.0-only
|
||||
|
||||
defmodule Pleroma.Web.Plugs.UserTrackingPlug do
|
||||
alias Pleroma.User
|
||||
|
||||
import Plug.Conn, only: [assign: 3]
|
||||
|
||||
@update_interval :timer.hours(24)
|
||||
|
||||
def init(opts), do: opts
|
||||
|
||||
def call(%{assigns: %{user: %User{id: id} = user}} = conn, _) when not is_nil(id) do
|
||||
with true <- needs_update?(user),
|
||||
{:ok, user} <- User.update_last_active_at(user) do
|
||||
assign(conn, :user, user)
|
||||
else
|
||||
_ -> conn
|
||||
end
|
||||
end
|
||||
|
||||
def call(conn, _), do: conn
|
||||
|
||||
defp needs_update?(%User{last_active_at: nil}), do: true
|
||||
|
||||
defp needs_update?(%User{last_active_at: last_active_at}) do
|
||||
NaiveDateTime.diff(NaiveDateTime.utc_now(), last_active_at, :millisecond) >= @update_interval
|
||||
end
|
||||
end
|
||||
|
|
@ -56,6 +56,7 @@ defmodule Pleroma.Web.Router do
|
|||
plug(Pleroma.Web.Plugs.UserEnabledPlug)
|
||||
plug(Pleroma.Web.Plugs.SetUserSessionIdPlug)
|
||||
plug(Pleroma.Web.Plugs.EnsureUserTokenAssignsPlug)
|
||||
plug(Pleroma.Web.Plugs.UserTrackingPlug)
|
||||
end
|
||||
|
||||
pipeline :base_api do
|
||||
|
|
|
|||
|
|
@ -17,12 +17,14 @@ defmodule Pleroma.Workers.AttachmentsCleanupWorker do
|
|||
"object" => %{"data" => %{"attachment" => [_ | _] = attachments, "actor" => actor}}
|
||||
}
|
||||
}) do
|
||||
attachments
|
||||
|> Enum.flat_map(fn item -> Enum.map(item["url"], & &1["href"]) end)
|
||||
|> fetch_objects
|
||||
|> prepare_objects(actor, Enum.map(attachments, & &1["name"]))
|
||||
|> filter_objects
|
||||
|> do_clean
|
||||
if Pleroma.Config.get([:instance, :cleanup_attachments], false) do
|
||||
attachments
|
||||
|> Enum.flat_map(fn item -> Enum.map(item["url"], & &1["href"]) end)
|
||||
|> fetch_objects
|
||||
|> prepare_objects(actor, Enum.map(attachments, & &1["name"]))
|
||||
|> filter_objects
|
||||
|> do_clean
|
||||
end
|
||||
|
||||
{:ok, :success}
|
||||
end
|
||||
|
|
|
|||
|
|
@ -7,7 +7,7 @@ defmodule Pleroma.Workers.PurgeExpiredActivity do
|
|||
Worker which purges expired activity.
|
||||
"""
|
||||
|
||||
use Oban.Worker, queue: :activity_expiration, max_attempts: 1
|
||||
use Oban.Worker, queue: :activity_expiration, max_attempts: 1, unique: [period: :infinity]
|
||||
|
||||
import Ecto.Query
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue