summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authormarcin mikołajczak <git@mkljczk.pl>2024-09-03 15:17:45 +0200
committermarcin mikołajczak <git@mkljczk.pl>2024-09-03 15:17:45 +0200
commit6d5ae4d2e91f8ea75115c0ffcdd1d94a24c9dc31 (patch)
tree0ca7c350c11d259054665cf53c70d8b2782bebb9
parentfecfe8bf89a32ffda0d52106f05b1f2e10d56472 (diff)
downloadpleroma-6d5ae4d2e91f8ea75115c0ffcdd1d94a24c9dc31.tar.gz
pleroma-6d5ae4d2e91f8ea75115c0ffcdd1d94a24c9dc31.zip
Include list id in StatusView
Signed-off-by: marcin mikołajczak <git@mkljczk.pl>
-rw-r--r--changelog.d/list-id-visibility.add1
-rw-r--r--docs/development/API/differences_in_mastoapi_responses.md1
-rw-r--r--lib/pleroma/web/api_spec/schemas/status.ex6
-rw-r--r--lib/pleroma/web/mastodon_api/views/status_view.ex13
-rw-r--r--test/pleroma/web/mastodon_api/views/status_view_test.exs8
5 files changed, 27 insertions, 2 deletions
diff --git a/changelog.d/list-id-visibility.add b/changelog.d/list-id-visibility.add
new file mode 100644
index 000000000..2fea2d771
--- /dev/null
+++ b/changelog.d/list-id-visibility.add
@@ -0,0 +1 @@
+Include list id in StatusView \ No newline at end of file
diff --git a/docs/development/API/differences_in_mastoapi_responses.md b/docs/development/API/differences_in_mastoapi_responses.md
index 41464e802..3bf8637f8 100644
--- a/docs/development/API/differences_in_mastoapi_responses.md
+++ b/docs/development/API/differences_in_mastoapi_responses.md
@@ -42,6 +42,7 @@ Has these additional fields under the `pleroma` object:
- `quotes_count`: the count of status quotes.
- `non_anonymous`: true if the source post specifies the poll results are not anonymous. Currently only implemented by Smithereen.
- `bookmark_folder`: the ID of the folder bookmark is stored within (if any).
+- `list_id`: the ID of the list the post is addressed to (if any, only returned to author).
The `GET /api/v1/statuses/:id/source` endpoint additionally has the following attributes:
diff --git a/lib/pleroma/web/api_spec/schemas/status.ex b/lib/pleroma/web/api_spec/schemas/status.ex
index 6e537b5da..25548d75b 100644
--- a/lib/pleroma/web/api_spec/schemas/status.ex
+++ b/lib/pleroma/web/api_spec/schemas/status.ex
@@ -249,6 +249,12 @@ defmodule Pleroma.Web.ApiSpec.Schemas.Status do
nullable: true,
description:
"A datetime (ISO 8601) that states when the post was pinned or `null` if the post is not pinned"
+ },
+ list_id: %Schema{
+ type: :integer,
+ nullable: true,
+ description:
+ "The ID of the list the post is addressed to (if any, only returned to author)"
}
}
},
diff --git a/lib/pleroma/web/mastodon_api/views/status_view.ex b/lib/pleroma/web/mastodon_api/views/status_view.ex
index 1b78477d0..3bf870c24 100644
--- a/lib/pleroma/web/mastodon_api/views/status_view.ex
+++ b/lib/pleroma/web/mastodon_api/views/status_view.ex
@@ -465,7 +465,8 @@ defmodule Pleroma.Web.MastodonAPI.StatusView do
parent_visible: visible_for_user?(reply_to, opts[:for]),
pinned_at: pinned_at,
quotes_count: object.data["quotesCount"] || 0,
- bookmark_folder: bookmark_folder
+ bookmark_folder: bookmark_folder,
+ list_id: get_list_id(object, client_posted_this_activity)
}
}
end
@@ -835,4 +836,14 @@ defmodule Pleroma.Web.MastodonAPI.StatusView do
nil
end
end
+
+ defp get_list_id(object, client_posted_this_activity) do
+ with true <- client_posted_this_activity,
+ %{data: %{"listMessage" => list_ap_id}} when is_binary(list_ap_id) <- object,
+ %{id: list_id} <- Pleroma.List.get_by_ap_id(list_ap_id) do
+ list_id
+ else
+ _ -> nil
+ end
+ end
end
diff --git a/test/pleroma/web/mastodon_api/views/status_view_test.exs b/test/pleroma/web/mastodon_api/views/status_view_test.exs
index afe0ccb28..bc6dec32a 100644
--- a/test/pleroma/web/mastodon_api/views/status_view_test.exs
+++ b/test/pleroma/web/mastodon_api/views/status_view_test.exs
@@ -342,7 +342,8 @@ defmodule Pleroma.Web.MastodonAPI.StatusViewTest do
parent_visible: false,
pinned_at: nil,
quotes_count: 0,
- bookmark_folder: nil
+ bookmark_folder: nil,
+ list_id: nil
}
}
@@ -912,6 +913,11 @@ defmodule Pleroma.Web.MastodonAPI.StatusViewTest do
status = StatusView.render("show.json", activity: activity)
assert status.visibility == "list"
+ assert status.pleroma.list_id == nil
+
+ status = StatusView.render("show.json", activity: activity, for: user)
+
+ assert status.pleroma.list_id == list.id
end
test "has a field for parent visibility" do