[#534] Websub fix: made SQL use UTC time zone when comparing with `valid_until` ...
[akkoma] / lib / pleroma / instances.ex
1 defmodule Pleroma.Instances do
2 @moduledoc "Instances context."
3
4 @adapter Pleroma.Instances.Instance
5
6 defdelegate filter_reachable(urls), to: @adapter
7 defdelegate reachable?(url), to: @adapter
8 defdelegate set_reachable(url), to: @adapter
9 defdelegate set_unreachable(url, unreachable_since \\ nil), to: @adapter
10
11 def reachability_datetime_threshold do
12 federation_reachability_timeout_days =
13 Pleroma.Config.get(:instance)[:federation_reachability_timeout_days] || 90
14
15 if federation_reachability_timeout_days > 0 do
16 NaiveDateTime.add(
17 NaiveDateTime.utc_now(),
18 -federation_reachability_timeout_days * 24 * 3600,
19 :second
20 )
21 else
22 ~N[0000-01-01 00:00:00]
23 end
24 end
25
26 def host(url_or_host) when is_binary(url_or_host) do
27 if url_or_host =~ ~r/^http/i do
28 URI.parse(url_or_host).host
29 else
30 url_or_host
31 end
32 end
33 end