philomena/lib/philomena_web/views/profile/alias_view.ex

25 lines
701 B
Elixir
Raw Normal View History

2019-12-17 03:26:43 +01:00
defmodule PhilomenaWeb.Profile.AliasView do
use PhilomenaWeb, :view
def younger_than_7_days?(user),
2020-01-11 05:20:19 +01:00
do: younger_than_time_offset?(user, -7 * 24 * 60 * 60)
2019-12-17 03:26:43 +01:00
def younger_than_14_days?(user),
2020-01-11 05:20:19 +01:00
do: younger_than_time_offset?(user, -14 * 24 * 60 * 60)
2019-12-17 03:26:43 +01:00
def currently_banned?(%{bans: bans}) do
now = DateTime.utc_now()
2020-01-11 05:20:19 +01:00
Enum.any?(bans, &(DateTime.diff(&1.valid_until, now) >= 0))
2019-12-17 03:26:43 +01:00
end
def previously_banned?(%{bans: []}), do: false
def previously_banned?(_user), do: true
defp younger_than_time_offset?(%{created_at: created_at}, time_offset) do
time_ago = DateTime.utc_now() |> DateTime.add(-time_offset, :second)
2019-12-17 03:26:43 +01:00
DateTime.diff(created_at, time_ago) >= 0
2019-12-17 03:26:43 +01:00
end
end