Merge branch 'develop' into 'feature/2164-unify-api-arguments'
# Conflicts: # CHANGELOG.md
This commit is contained in:
commit
cd5ff7a943
12 changed files with 168 additions and 7 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
|
||||
|
|
|
|||
|
|
@ -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
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue