From 1ad70f3357d4bd642f0512142218285a260fe7cc Mon Sep 17 00:00:00 2001 From: Shadowfacts Date: Wed, 25 Aug 2021 23:15:57 -0400 Subject: [PATCH] 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. --- .../templates/frontend/_follow_notification.html.eex | 2 +- lib/clacks_web/views/frontend_view.ex | 11 +++++++++-- 2 files changed, 10 insertions(+), 3 deletions(-) diff --git a/lib/clacks_web/templates/frontend/_follow_notification.html.eex b/lib/clacks_web/templates/frontend/_follow_notification.html.eex index 2a05c76..e950e35 100644 --- a/lib/clacks_web/templates/frontend/_follow_notification.html.eex +++ b/lib/clacks_web/templates/frontend/_follow_notification.html.eex @@ -4,7 +4,7 @@ Followed by <%= @actor.data["preferredUsername"] %>

- +

diff --git a/lib/clacks_web/views/frontend_view.ex b/lib/clacks_web/views/frontend_view.ex index f2b01b8..b7e4c82 100644 --- a/lib/clacks_web/views/frontend_view.ex +++ b/lib/clacks_web/views/frontend_view.ex @@ -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