From 8ac7cc98c1ba241ce104cc2ee15723f087c367d2 Mon Sep 17 00:00:00 2001 From: "Haelwenn (lanodan) Monnier" Date: Thu, 16 Nov 2023 15:48:37 +0100 Subject: [PATCH 1/2] MastoAPI AccountView: Change last_status_at to be a date Changed in Mastodon 3.1.0 with: https://github.com/tootsuite/mastodon/pull/12966 --- changelog.d/last_status_at.change | 1 + lib/pleroma/web/mastodon_api/views/account_view.ex | 11 +++++++++-- 2 files changed, 10 insertions(+), 2 deletions(-) create mode 100644 changelog.d/last_status_at.change diff --git a/changelog.d/last_status_at.change b/changelog.d/last_status_at.change new file mode 100644 index 000000000..5417aff30 --- /dev/null +++ b/changelog.d/last_status_at.change @@ -0,0 +1 @@ +- Change AccountView `last_status_at` from a datetime to a date (as done in Mastodon 3.1.0) \ No newline at end of file diff --git a/lib/pleroma/web/mastodon_api/views/account_view.ex b/lib/pleroma/web/mastodon_api/views/account_view.ex index cc3e3582f..34478cec8 100644 --- a/lib/pleroma/web/mastodon_api/views/account_view.ex +++ b/lib/pleroma/web/mastodon_api/views/account_view.ex @@ -1,5 +1,5 @@ # Pleroma: A lightweight social networking server -# Copyright © 2017-2022 Pleroma Authors +# Copyright © 2017-2023 Pleroma Authors # SPDX-License-Identifier: AGPL-3.0-only defmodule Pleroma.Web.MastodonAPI.AccountView do @@ -249,6 +249,13 @@ defp do_render("show.json", %{user: user} = opts) do nil end + last_status_at = + if not is_nil(user.last_status_at) do + user.last_status_at |> NaiveDateTime.to_date() |> Date.to_iso8601() + else + nil + end + %{ id: to_string(user.id), username: username_from_nickname(user.nickname), @@ -277,7 +284,7 @@ defp do_render("show.json", %{user: user} = opts) do actor_type: user.actor_type } }, - last_status_at: user.last_status_at, + last_status_at: last_status_at, # Pleroma extensions # Note: it's insecure to output :email but fully-qualified nickname may serve as safe stub From ef8a2134bc9e2e9f3aa08172b982c347332e14c1 Mon Sep 17 00:00:00 2001 From: Lain Soykaf Date: Thu, 7 Dec 2023 11:25:18 +0400 Subject: [PATCH 2/2] AccountView: Add test, refactor --- lib/pleroma/web/mastodon_api/views/account_view.ex | 5 +---- test/pleroma/web/mastodon_api/views/account_view_test.exs | 5 +++-- 2 files changed, 4 insertions(+), 6 deletions(-) diff --git a/lib/pleroma/web/mastodon_api/views/account_view.ex b/lib/pleroma/web/mastodon_api/views/account_view.ex index 34478cec8..237de3055 100644 --- a/lib/pleroma/web/mastodon_api/views/account_view.ex +++ b/lib/pleroma/web/mastodon_api/views/account_view.ex @@ -250,11 +250,8 @@ defp do_render("show.json", %{user: user} = opts) do end last_status_at = - if not is_nil(user.last_status_at) do + user.last_status_at && user.last_status_at |> NaiveDateTime.to_date() |> Date.to_iso8601() - else - nil - end %{ id: to_string(user.id), diff --git a/test/pleroma/web/mastodon_api/views/account_view_test.exs b/test/pleroma/web/mastodon_api/views/account_view_test.exs index 3bb4970ca..d5b8ad8b0 100644 --- a/test/pleroma/web/mastodon_api/views/account_view_test.exs +++ b/test/pleroma/web/mastodon_api/views/account_view_test.exs @@ -35,7 +35,8 @@ test "Represent a user account" do inserted_at: ~N[2017-08-15 15:47:06.597036], emoji: %{"karjalanpiirakka" => "/file.png"}, raw_bio: "valid html. a\nb\nc\nd\nf '&<>\"", - also_known_as: ["https://shitposter.zone/users/shp"] + also_known_as: ["https://shitposter.zone/users/shp"], + last_status_at: NaiveDateTime.utc_now() }) expected = %{ @@ -74,7 +75,7 @@ test "Represent a user account" do fields: [] }, fqn: "shp@shitposter.club", - last_status_at: nil, + last_status_at: user.last_status_at |> NaiveDateTime.to_date() |> Date.to_iso8601(), pleroma: %{ ap_id: user.ap_id, also_known_as: ["https://shitposter.zone/users/shp"],