Fix displaying follow notifications from Mastodon

Mastodon, unlike Pleroma, doesn't include `published` in the Follow
activity, so we fall back to the DB's inserted_at.
This commit is contained in:
Shadowfacts 2021-08-25 23:15:57 -04:00
parent 5b7a0dba6d
commit 1ad70f3357
Signed by: shadowfacts
GPG Key ID: 94A5AB95422746E5
2 changed files with 10 additions and 3 deletions

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.data["published"]) %></time>
<time datetime="<%= @activity.data["published"] %>"><%= display_timestamp(@activity) %></time>
</p>
</div>
</div>

View File

@ -35,13 +35,20 @@ defmodule ClacksWeb.FrontendView do
def local_actor_link(%Actor{local: false, id: id}),
do: Routes.frontend_path(Endpoint, :actor, id)
@spec display_timestamp(datetime :: String.t() | DateTime.t() | NaiveDateTime.t()) :: String.t()
@spec display_timestamp(
datetime :: String.t() | DateTime.t() | NaiveDateTime.t() | Activity.t()
) :: String.t()
def display_timestamp(str) when is_binary(str) do
display_timestamp(Timex.parse!(str, "{ISO:Extended}"))
end
def display_timestamp(datetime) do
def display_timestamp(%Activity{data: data, inserted_at: inserted_at}) do
display_timestamp(Map.get(data, "published", inserted_at))
end
def display_timestamp(%{__struct__: struct} = datetime)
when struct == DateTime or struct == NaiveDateTime do
diff = Timex.diff(Timex.now(), datetime, :seconds)
cond do