Fix timestamps for certain activity types

This commit is contained in:
Shadowfacts 2021-08-26 10:13:53 -04:00
parent 9dfb4b22e1
commit eacf6ab0a5
Signed by: shadowfacts
GPG Key ID: 94A5AB95422746E5
4 changed files with 20 additions and 4 deletions

View File

@ -11,7 +11,7 @@
<%= past_tense %> by <a href="<%= local_actor_link(@action_actor) %>"><%= @action_actor.data["preferredUsername"] %></a>
</p>
<p class="status-meta-right">
<time datetime="<%= @action_activity.data["published"] %>"><%= display_timestamp(@action_activity.data["published"]) %></time>
<time datetime="<%= iso_datetime(@action_activity) %>"><%= display_timestamp(@action_activity) %></time>
</p>
</div>
<div class="status-meta">
@ -26,7 +26,7 @@
</a>
</h3>
<p class="status-meta-right">
<time datetime="<%= @original_note["published"] %>"><%= display_timestamp(@original_note["published"]) %></time>
<time datetime="<%= iso_datetime(@original_activity) %>"><%= display_timestamp(@original_activity) %></time>
<a href="<%= @original_note["url"] || @original_note["id"] %>" class="status-permalink">Permalink</a>
</p>
</div>

View File

@ -4,7 +4,7 @@
Followed by <a href="<%= local_actor_link(@actor) %>"><%= @actor.data["preferredUsername"] %></a>
</p>
<p class="notification-info-right">
<time datetime="<%= @activity.data["published"] %>"><%= display_timestamp(@activity) %></time>
<time datetime="<%= iso_datetime(@activity) %>"><%= display_timestamp(@activity) %></time>
</p>
</div>
</div>

View File

@ -13,7 +13,7 @@
</h3>
</div>
<p class="status-meta-right">
<time datetime="<%= @note["published"] %>" class="dt-published"><%= display_timestamp(@note["published"]) %></time>
<time datetime="<%= iso_datetime(@note["published"]) %>" class="dt-published"><%= display_timestamp(@note["published"]) %></time>
<a href="<%= @note["url"] || @note["id"] %>" class="status-permalink u-url">Permalink</a>
</p>
</div>

View File

@ -82,6 +82,22 @@ defmodule ClacksWeb.FrontendView do
end
end
@spec iso_datetime(datetime :: String.t() | DateTime.t() | NaiveDateTime.t() | Activity.t()) ::
String.t()
def iso_datetime(str) when is_binary(str) do
str
end
def iso_datetime(%Activity{data: data, inserted_at: inserted_at}) do
iso_datetime(Map.get(data, "published", inserted_at))
end
def iso_datetime(%{__struct__: struct} = datetime)
when struct == DateTime or struct == NaiveDateTime do
Timex.format!(datetime, "{ISO:Extended:Z}")
end
@spec prev_page_path(conn :: Plug.Conn.t(), [
Activity.t() | {Activity.t(), Actor.t()} | Notification.t()
]) ::