Support quoted_status_id parameter in post creation request
Signed-off-by: nicole mikołajczyk <git@mkljczk.pl>
This commit is contained in:
parent
606c9ae4b1
commit
c1699c6e60
9 changed files with 70 additions and 37 deletions
1
changelog.d/mastodon-quote-id-api.change
Normal file
1
changelog.d/mastodon-quote-id-api.change
Normal file
|
|
@ -0,0 +1 @@
|
||||||
|
Support `quoted_status_id` parameter in post creation request
|
||||||
|
|
@ -599,6 +599,20 @@ defmodule Pleroma.Web.ApiSpec.StatusOperation do
|
||||||
nullable: true,
|
nullable: true,
|
||||||
description: "ISO 639 language code for this status."
|
description: "ISO 639 language code for this status."
|
||||||
},
|
},
|
||||||
|
visibility: %Schema{
|
||||||
|
nullable: true,
|
||||||
|
anyOf: [
|
||||||
|
VisibilityScope,
|
||||||
|
%Schema{type: :string, description: "`list:LIST_ID`", example: "LIST:123"}
|
||||||
|
],
|
||||||
|
description:
|
||||||
|
"Visibility of the posted status. Besides standard MastoAPI values (`direct`, `private`, `unlisted` or `public`) it can be used to address a List by setting it to `list:LIST_ID`"
|
||||||
|
},
|
||||||
|
quoted_status_id: %Schema{
|
||||||
|
nullable: true,
|
||||||
|
allOf: [FlakeID],
|
||||||
|
description: "ID of the status being quoted, if any"
|
||||||
|
},
|
||||||
# Pleroma-specific properties:
|
# Pleroma-specific properties:
|
||||||
preview: %Schema{
|
preview: %Schema{
|
||||||
allOf: [BooleanLike],
|
allOf: [BooleanLike],
|
||||||
|
|
@ -619,15 +633,6 @@ defmodule Pleroma.Web.ApiSpec.StatusOperation do
|
||||||
description:
|
description:
|
||||||
"A list of nicknames (like `lain@soykaf.club` or `lain` on the local server) that will be used to determine who is going to be addressed by this post. Using this will disable the implicit addressing by mentioned names in the `status` body, only the people in the `to` list will be addressed. The normal rules for for post visibility are not affected by this and will still apply"
|
"A list of nicknames (like `lain@soykaf.club` or `lain` on the local server) that will be used to determine who is going to be addressed by this post. Using this will disable the implicit addressing by mentioned names in the `status` body, only the people in the `to` list will be addressed. The normal rules for for post visibility are not affected by this and will still apply"
|
||||||
},
|
},
|
||||||
visibility: %Schema{
|
|
||||||
nullable: true,
|
|
||||||
anyOf: [
|
|
||||||
VisibilityScope,
|
|
||||||
%Schema{type: :string, description: "`list:LIST_ID`", example: "LIST:123"}
|
|
||||||
],
|
|
||||||
description:
|
|
||||||
"Visibility of the posted status. Besides standard MastoAPI values (`direct`, `private`, `unlisted` or `public`) it can be used to address a List by setting it to `list:LIST_ID`"
|
|
||||||
},
|
|
||||||
expires_in: %Schema{
|
expires_in: %Schema{
|
||||||
nullable: true,
|
nullable: true,
|
||||||
type: :integer,
|
type: :integer,
|
||||||
|
|
@ -643,7 +648,8 @@ defmodule Pleroma.Web.ApiSpec.StatusOperation do
|
||||||
quote_id: %Schema{
|
quote_id: %Schema{
|
||||||
nullable: true,
|
nullable: true,
|
||||||
allOf: [FlakeID],
|
allOf: [FlakeID],
|
||||||
description: "ID of the status being quoted, if any"
|
description: "Deprecated in favor of `quoted_status_id`",
|
||||||
|
deprecated: true
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
example: %{
|
example: %{
|
||||||
|
|
|
||||||
|
|
@ -160,7 +160,7 @@ defmodule Pleroma.Web.CommonAPI.ActivityDraft do
|
||||||
|
|
||||||
defp in_reply_to(draft), do: draft
|
defp in_reply_to(draft), do: draft
|
||||||
|
|
||||||
defp quote_post(%{params: %{quote_id: id}} = draft) when not_empty_string(id) do
|
defp quote_post(%{params: %{quoted_status_id: id}} = draft) when not_empty_string(id) do
|
||||||
case Activity.get_by_id_with_object(id) do
|
case Activity.get_by_id_with_object(id) do
|
||||||
%Activity{} = activity ->
|
%Activity{} = activity ->
|
||||||
%__MODULE__{draft | quote_post: activity}
|
%__MODULE__{draft | quote_post: activity}
|
||||||
|
|
@ -170,6 +170,10 @@ defmodule Pleroma.Web.CommonAPI.ActivityDraft do
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
defp quote_post(%{params: %{quote_id: id}} = draft) when not_empty_string(id) do
|
||||||
|
quote_post(%{draft | params: Map.put(draft.params, :quoted_status_id, id)})
|
||||||
|
end
|
||||||
|
|
||||||
defp quote_post(draft), do: draft
|
defp quote_post(draft), do: draft
|
||||||
|
|
||||||
defp in_reply_to_conversation(draft) do
|
defp in_reply_to_conversation(draft) do
|
||||||
|
|
|
||||||
|
|
@ -831,7 +831,7 @@ defmodule Pleroma.Web.ActivityPub.ActivityPubTest do
|
||||||
|
|
||||||
{:ok, activity} = CommonAPI.post(user, %{status: "1", visibility: "public"})
|
{:ok, activity} = CommonAPI.post(user, %{status: "1", visibility: "public"})
|
||||||
ap_id = activity.data["id"]
|
ap_id = activity.data["id"]
|
||||||
quote_data = %{status: "1", quote_id: activity.id}
|
quote_data = %{status: "1", quoted_status_id: activity.id}
|
||||||
|
|
||||||
# public
|
# public
|
||||||
{:ok, _} = CommonAPI.post(user2, Map.put(quote_data, :visibility, "public"))
|
{:ok, _} = CommonAPI.post(user2, Map.put(quote_data, :visibility, "public"))
|
||||||
|
|
|
||||||
|
|
@ -615,7 +615,7 @@ defmodule Pleroma.Web.ActivityPub.TransmogrifierTest do
|
||||||
user = insert(:user)
|
user = insert(:user)
|
||||||
|
|
||||||
{:ok, quoted_post} = CommonAPI.post(user, %{status: "hey"})
|
{:ok, quoted_post} = CommonAPI.post(user, %{status: "hey"})
|
||||||
{:ok, quote_post} = CommonAPI.post(user, %{status: "hey", quote_id: quoted_post.id})
|
{:ok, quote_post} = CommonAPI.post(user, %{status: "hey", quoted_status_id: quoted_post.id})
|
||||||
|
|
||||||
{:ok, modified} = Transmogrifier.prepare_outgoing(quote_post.data)
|
{:ok, modified} = Transmogrifier.prepare_outgoing(quote_post.data)
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -20,14 +20,20 @@ defmodule Pleroma.Web.CommonAPI.ActivityDraftTest do
|
||||||
{:ok, local} = CommonAPI.post(user, %{status: ".", visibility: "local"})
|
{:ok, local} = CommonAPI.post(user, %{status: ".", visibility: "local"})
|
||||||
{:ok, public} = CommonAPI.post(user, %{status: ".", visibility: "public"})
|
{:ok, public} = CommonAPI.post(user, %{status: ".", visibility: "public"})
|
||||||
|
|
||||||
{:error, _} = ActivityDraft.create(user, %{status: "nice", quote_id: direct.id})
|
{:error, _} = ActivityDraft.create(user, %{status: "nice", quoted_status_id: direct.id})
|
||||||
{:ok, _} = ActivityDraft.create(user, %{status: "nice", quote_id: private.id})
|
{:ok, _} = ActivityDraft.create(user, %{status: "nice", quoted_status_id: private.id})
|
||||||
{:error, _} = ActivityDraft.create(another_user, %{status: "nice", quote_id: private.id})
|
|
||||||
{:ok, _} = ActivityDraft.create(user, %{status: "nice", quote_id: unlisted.id})
|
{:error, _} =
|
||||||
{:ok, _} = ActivityDraft.create(another_user, %{status: "nice", quote_id: unlisted.id})
|
ActivityDraft.create(another_user, %{status: "nice", quoted_status_id: private.id})
|
||||||
{:ok, _} = ActivityDraft.create(user, %{status: "nice", quote_id: local.id})
|
|
||||||
{:ok, _} = ActivityDraft.create(another_user, %{status: "nice", quote_id: local.id})
|
{:ok, _} = ActivityDraft.create(user, %{status: "nice", quoted_status_id: unlisted.id})
|
||||||
{:ok, _} = ActivityDraft.create(user, %{status: "nice", quote_id: public.id})
|
|
||||||
{:ok, _} = ActivityDraft.create(another_user, %{status: "nice", quote_id: public.id})
|
{:ok, _} =
|
||||||
|
ActivityDraft.create(another_user, %{status: "nice", quoted_status_id: unlisted.id})
|
||||||
|
|
||||||
|
{:ok, _} = ActivityDraft.create(user, %{status: "nice", quoted_status_id: local.id})
|
||||||
|
{:ok, _} = ActivityDraft.create(another_user, %{status: "nice", quoted_status_id: local.id})
|
||||||
|
{:ok, _} = ActivityDraft.create(user, %{status: "nice", quoted_status_id: public.id})
|
||||||
|
{:ok, _} = ActivityDraft.create(another_user, %{status: "nice", quoted_status_id: public.id})
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
|
||||||
|
|
@ -830,7 +830,9 @@ defmodule Pleroma.Web.CommonAPITest do
|
||||||
user = insert(:user)
|
user = insert(:user)
|
||||||
|
|
||||||
{:ok, quoted} = CommonAPI.post(user, %{status: "Hello world"})
|
{:ok, quoted} = CommonAPI.post(user, %{status: "Hello world"})
|
||||||
{:ok, quote_post} = CommonAPI.post(user, %{status: "nice post", quote_id: quoted.id})
|
|
||||||
|
{:ok, quote_post} =
|
||||||
|
CommonAPI.post(user, %{status: "nice post", quoted_status_id: quoted.id})
|
||||||
|
|
||||||
quoted = Object.normalize(quoted)
|
quoted = Object.normalize(quoted)
|
||||||
quote_post = Object.normalize(quote_post)
|
quote_post = Object.normalize(quote_post)
|
||||||
|
|
@ -841,13 +843,25 @@ defmodule Pleroma.Web.CommonAPITest do
|
||||||
refute quoted.data["actor"] in quote_post.data["to"]
|
refute quoted.data["actor"] in quote_post.data["to"]
|
||||||
end
|
end
|
||||||
|
|
||||||
|
test "it supports fallback from `quote_id`" do
|
||||||
|
user = insert(:user)
|
||||||
|
|
||||||
|
{:ok, quoted} = CommonAPI.post(user, %{status: "Hello world"})
|
||||||
|
{:ok, quote_post} = CommonAPI.post(user, %{status: "nice post", quote_id: quoted.id})
|
||||||
|
|
||||||
|
quoted = Object.normalize(quoted)
|
||||||
|
quote_post = Object.normalize(quote_post)
|
||||||
|
|
||||||
|
assert quote_post.data["quoteUrl"] == quoted.data["id"]
|
||||||
|
end
|
||||||
|
|
||||||
test "quote posting with explicit addressing doesn't mention the OP" do
|
test "quote posting with explicit addressing doesn't mention the OP" do
|
||||||
user = insert(:user)
|
user = insert(:user)
|
||||||
|
|
||||||
{:ok, quoted} = CommonAPI.post(user, %{status: "Hello world"})
|
{:ok, quoted} = CommonAPI.post(user, %{status: "Hello world"})
|
||||||
|
|
||||||
{:ok, quote_post} =
|
{:ok, quote_post} =
|
||||||
CommonAPI.post(user, %{status: "nice post", quote_id: quoted.id, to: []})
|
CommonAPI.post(user, %{status: "nice post", quoted_status_id: quoted.id, to: []})
|
||||||
|
|
||||||
assert Object.normalize(quote_post).data["to"] == [Pleroma.Constants.as_public()]
|
assert Object.normalize(quote_post).data["to"] == [Pleroma.Constants.as_public()]
|
||||||
end
|
end
|
||||||
|
|
@ -862,15 +876,15 @@ defmodule Pleroma.Web.CommonAPITest do
|
||||||
{:ok, local} = CommonAPI.post(user, %{status: ".", visibility: "local"})
|
{:ok, local} = CommonAPI.post(user, %{status: ".", visibility: "local"})
|
||||||
{:ok, public} = CommonAPI.post(user, %{status: ".", visibility: "public"})
|
{:ok, public} = CommonAPI.post(user, %{status: ".", visibility: "public"})
|
||||||
|
|
||||||
{:error, _} = CommonAPI.post(user, %{status: "nice", quote_id: direct.id})
|
{:error, _} = CommonAPI.post(user, %{status: "nice", quoted_status_id: direct.id})
|
||||||
{:ok, _} = CommonAPI.post(user, %{status: "nice", quote_id: private.id})
|
{:ok, _} = CommonAPI.post(user, %{status: "nice", quoted_status_id: private.id})
|
||||||
{:error, _} = CommonAPI.post(another_user, %{status: "nice", quote_id: private.id})
|
{:error, _} = CommonAPI.post(another_user, %{status: "nice", quoted_status_id: private.id})
|
||||||
{:ok, _} = CommonAPI.post(user, %{status: "nice", quote_id: unlisted.id})
|
{:ok, _} = CommonAPI.post(user, %{status: "nice", quoted_status_id: unlisted.id})
|
||||||
{:ok, _} = CommonAPI.post(another_user, %{status: "nice", quote_id: unlisted.id})
|
{:ok, _} = CommonAPI.post(another_user, %{status: "nice", quoted_status_id: unlisted.id})
|
||||||
{:ok, _} = CommonAPI.post(user, %{status: "nice", quote_id: local.id})
|
{:ok, _} = CommonAPI.post(user, %{status: "nice", quoted_status_id: local.id})
|
||||||
{:ok, _} = CommonAPI.post(another_user, %{status: "nice", quote_id: local.id})
|
{:ok, _} = CommonAPI.post(another_user, %{status: "nice", quoted_status_id: local.id})
|
||||||
{:ok, _} = CommonAPI.post(user, %{status: "nice", quote_id: public.id})
|
{:ok, _} = CommonAPI.post(user, %{status: "nice", quoted_status_id: public.id})
|
||||||
{:ok, _} = CommonAPI.post(another_user, %{status: "nice", quote_id: public.id})
|
{:ok, _} = CommonAPI.post(another_user, %{status: "nice", quoted_status_id: public.id})
|
||||||
end
|
end
|
||||||
|
|
||||||
test "it properly mentions punycode domain" do
|
test "it properly mentions punycode domain" do
|
||||||
|
|
|
||||||
|
|
@ -436,8 +436,10 @@ defmodule Pleroma.Web.MastodonAPI.StatusViewTest do
|
||||||
post = insert(:note_activity)
|
post = insert(:note_activity)
|
||||||
user = insert(:user)
|
user = insert(:user)
|
||||||
|
|
||||||
{:ok, quote_post} = CommonAPI.post(user, %{status: "he", quote_id: post.id})
|
{:ok, quote_post} = CommonAPI.post(user, %{status: "he", quoted_status_id: post.id})
|
||||||
{:ok, quoted_quote_post} = CommonAPI.post(user, %{status: "yo", quote_id: quote_post.id})
|
|
||||||
|
{:ok, quoted_quote_post} =
|
||||||
|
CommonAPI.post(user, %{status: "yo", quoted_status_id: quote_post.id})
|
||||||
|
|
||||||
status = StatusView.render("show.json", %{activity: quoted_quote_post})
|
status = StatusView.render("show.json", %{activity: quoted_quote_post})
|
||||||
|
|
||||||
|
|
@ -508,7 +510,7 @@ defmodule Pleroma.Web.MastodonAPI.StatusViewTest do
|
||||||
post = insert(:note_activity)
|
post = insert(:note_activity)
|
||||||
user = insert(:user)
|
user = insert(:user)
|
||||||
|
|
||||||
{:ok, quote_post} = CommonAPI.post(user, %{status: "he", quote_id: post.id})
|
{:ok, quote_post} = CommonAPI.post(user, %{status: "he", quoted_status_id: post.id})
|
||||||
{:ok, repost} = CommonAPI.repeat(quote_post.id, user)
|
{:ok, repost} = CommonAPI.repeat(quote_post.id, user)
|
||||||
|
|
||||||
[status] = StatusView.render("index.json", %{activities: [repost], as: :activity})
|
[status] = StatusView.render("index.json", %{activities: [repost], as: :activity})
|
||||||
|
|
|
||||||
|
|
@ -20,7 +20,7 @@ defmodule Pleroma.Web.PleromaAPI.StatusControllerTest do
|
||||||
user = insert(:user)
|
user = insert(:user)
|
||||||
activity = insert(:note_activity)
|
activity = insert(:note_activity)
|
||||||
|
|
||||||
{:ok, quote_post} = CommonAPI.post(user, %{status: "quoat", quote_id: activity.id})
|
{:ok, quote_post} = CommonAPI.post(user, %{status: "quoat", quoted_status_id: activity.id})
|
||||||
|
|
||||||
response =
|
response =
|
||||||
conn
|
conn
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue