diff options
author | Mark Felder <feld@feld.me> | 2021-02-02 12:01:48 -0600 |
---|---|---|
committer | Mark Felder <feld@feld.me> | 2021-02-02 12:01:48 -0600 |
commit | 28d2917c3a093e19bbaaa749a22cec0079b849b3 (patch) | |
tree | cb9a5a933acc5d63b9f0fc310aa6f02c7b8af46b /lib/pleroma/user.ex | |
parent | 9272cef500308862d0d86be329bad7f41c66d4ad (diff) | |
parent | 6a2d3fb9a3775fc0e167c71bb8a8fba3608b2f17 (diff) | |
download | pleroma-28d2917c3a093e19bbaaa749a22cec0079b849b3.tar.gz |
Merge branch 'develop' into fix/majic-nits
Diffstat (limited to 'lib/pleroma/user.ex')
-rw-r--r-- | lib/pleroma/user.ex | 16 |
1 files changed, 16 insertions, 0 deletions
diff --git a/lib/pleroma/user.ex b/lib/pleroma/user.ex index e422b59f1..06cdb42af 100644 --- a/lib/pleroma/user.ex +++ b/lib/pleroma/user.ex @@ -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 |