commit: 294e08cb65940ff193d6920e576f56718a5623f4
parent 4168ead67290fce809c8c7bf671fd9de07079da6
Author: kaniini <ariadne@dereferenced.org>
Date: Sat, 5 Oct 2019 19:46:23 +0000
Merge branch 'backport/update-activity-fixes' into 'maint/1.1'
backport update activity fixes to maint/1.1
See merge request pleroma/pleroma!1797
Diffstat:
7 files changed, 18 insertions(+), 6 deletions(-)
diff --git a/CHANGELOG.md b/CHANGELOG.md
@@ -11,6 +11,7 @@ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/).
- Mastodon API: Inability to get some local users by nickname in `/api/v1/accounts/:id_or_nickname`
- Mastodon API: Blocks are now treated consistently between the Streaming API and the Timeline APIs
- ActivityPub: Correct addressing of Undo.
+- ActivityPub: Correct addressing of profile update activities.
- Mastodon API: Ensure the `account` field is not empty when rendering Notification entities.
### Removed
diff --git a/lib/pleroma/web/activity_pub/activity_pub.ex b/lib/pleroma/web/activity_pub/activity_pub.ex
@@ -17,6 +17,7 @@ defmodule Pleroma.Web.ActivityPub.ActivityPub do
alias Pleroma.User
alias Pleroma.Web.ActivityPub.MRF
alias Pleroma.Web.ActivityPub.Transmogrifier
+ alias Pleroma.Web.ActivityPub.Utils
alias Pleroma.Web.Streamer
alias Pleroma.Web.WebFinger
@@ -270,8 +271,8 @@ defmodule Pleroma.Web.ActivityPub.ActivityPub do
end
def update(%{to: to, cc: cc, actor: actor, object: object} = params) do
- # only accept false as false value
local = !(params[:local] == false)
+ activity_id = params[:activity_id]
with data <- %{
"to" => to,
@@ -280,6 +281,7 @@ defmodule Pleroma.Web.ActivityPub.ActivityPub do
"actor" => actor,
"object" => object
},
+ data <- Utils.maybe_put(data, "id", activity_id),
{:ok, activity} <- insert(data, local),
:ok <- maybe_federate(activity) do
{:ok, activity}
diff --git a/lib/pleroma/web/activity_pub/transmogrifier.ex b/lib/pleroma/web/activity_pub/transmogrifier.ex
@@ -621,7 +621,8 @@ defmodule Pleroma.Web.ActivityPub.Transmogrifier do
to: data["to"] || [],
cc: data["cc"] || [],
object: object,
- actor: actor_id
+ actor: actor_id,
+ activity_id: data["id"]
})
else
e ->
diff --git a/lib/pleroma/web/activity_pub/utils.ex b/lib/pleroma/web/activity_pub/utils.ex
@@ -728,6 +728,6 @@ defmodule Pleroma.Web.ActivityPub.Utils do
|> Repo.all()
end
- defp maybe_put(map, _key, nil), do: map
- defp maybe_put(map, key, value), do: Map.put(map, key, value)
+ def maybe_put(map, _key, nil), do: map
+ def maybe_put(map, key, value), do: Map.put(map, key, value)
end
diff --git a/lib/pleroma/web/common_api/common_api.ex b/lib/pleroma/web/common_api/common_api.ex
@@ -17,6 +17,8 @@ defmodule Pleroma.Web.CommonAPI do
import Pleroma.Web.Gettext
import Pleroma.Web.CommonAPI.Utils
+ require Pleroma.Constants
+
def follow(follower, followed) do
with {:ok, follower} <- User.maybe_direct_follow(follower, followed),
{:ok, activity} <- ActivityPub.follow(follower, followed),
@@ -316,7 +318,7 @@ defmodule Pleroma.Web.CommonAPI do
ActivityPub.update(%{
local: true,
- to: [user.follower_address],
+ to: [Pleroma.Constants.as_public(), user.follower_address],
cc: [],
actor: user.ap_id,
object: Pleroma.Web.ActivityPub.UserView.render("user.json", %{user: user})
diff --git a/test/web/activity_pub/transmogrifier_test.exs b/test/web/activity_pub/transmogrifier_test.exs
@@ -516,6 +516,8 @@ defmodule Pleroma.Web.ActivityPub.TransmogrifierTest do
{:ok, %Activity{data: data, local: false}} = Transmogrifier.handle_incoming(update_data)
+ assert data["id"] == update_data["id"]
+
user = User.get_cached_by_ap_id(data["actor"])
assert user.name == "gargle"
diff --git a/test/web/common_api/common_api_test.exs b/test/web/common_api/common_api_test.exs
@@ -14,6 +14,8 @@ defmodule Pleroma.Web.CommonAPITest do
import Pleroma.Factory
+ require Pleroma.Constants
+
clear_config([:instance, :safe_dm_mentions])
clear_config([:instance, :limit])
clear_config([:instance, :max_pinned_statuses])
@@ -96,11 +98,13 @@ defmodule Pleroma.Web.CommonAPITest do
test "it adds emoji when updating profiles" do
user = insert(:user, %{name: ":firefox:"})
- CommonAPI.update(user)
+ {:ok, activity} = CommonAPI.update(user)
user = User.get_cached_by_ap_id(user.ap_id)
[firefox] = user.info.source_data["tag"]
assert firefox["name"] == ":firefox:"
+
+ assert Pleroma.Constants.as_public() in activity.recipients
end
describe "posting" do