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:
parent
5b7a0dba6d
commit
1ad70f3357
|
@ -4,7 +4,7 @@
|
||||||
Followed by <a href="<%= local_actor_link(@actor) %>"><%= @actor.data["preferredUsername"] %></a>
|
Followed by <a href="<%= local_actor_link(@actor) %>"><%= @actor.data["preferredUsername"] %></a>
|
||||||
</p>
|
</p>
|
||||||
<p class="notification-info-right">
|
<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>
|
</p>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
|
|
|
@ -35,13 +35,20 @@ defmodule ClacksWeb.FrontendView do
|
||||||
def local_actor_link(%Actor{local: false, id: id}),
|
def local_actor_link(%Actor{local: false, id: id}),
|
||||||
do: Routes.frontend_path(Endpoint, :actor, 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
|
def display_timestamp(str) when is_binary(str) do
|
||||||
display_timestamp(Timex.parse!(str, "{ISO:Extended}"))
|
display_timestamp(Timex.parse!(str, "{ISO:Extended}"))
|
||||||
end
|
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)
|
diff = Timex.diff(Timex.now(), datetime, :seconds)
|
||||||
|
|
||||||
cond do
|
cond do
|
||||||
|
|
Loading…
Reference in New Issue