CommonAPI: Change public->private implicit addressing.

This will not add the OP to the `to` field anymore when going from
public to private.
This commit is contained in:
lain 2020-05-20 13:38:47 +02:00
parent 94ba5a7802
commit eb5f428565
3 changed files with 38 additions and 3 deletions

View File

@ -102,7 +102,8 @@ def get_to_and_cc(user, mentioned_users, inReplyTo, "private", _) do
end end
def get_to_and_cc(_user, mentioned_users, inReplyTo, "direct", _) do def get_to_and_cc(_user, mentioned_users, inReplyTo, "direct", _) do
if inReplyTo do # If the OP is a DM already, add the implicit actor.
if inReplyTo && Visibility.is_direct?(inReplyTo) do
{Enum.uniq([inReplyTo.data["actor"] | mentioned_users]), []} {Enum.uniq([inReplyTo.data["actor"] | mentioned_users]), []}
else else
{mentioned_users, []} {mentioned_users, []}

View File

@ -335,6 +335,32 @@ test "it does not allow replies to direct messages that are not direct messages
end) end)
end end
test "replying with a direct message will NOT auto-add the author of the reply to the recipient list" do
user = insert(:user)
other_user = insert(:user)
third_user = insert(:user)
{:ok, post} = CommonAPI.post(user, %{status: "I'm stupid"})
{:ok, open_answer} =
CommonAPI.post(other_user, %{status: "No ur smart", in_reply_to_status_id: post.id})
# The OP is implicitly added
assert user.ap_id in open_answer.recipients
{:ok, secret_answer} =
CommonAPI.post(other_user, %{
status: "lol, that guy really is stupid, right, @#{third_user.nickname}?",
in_reply_to_status_id: post.id,
visibility: "direct"
})
assert third_user.ap_id in secret_answer.recipients
# The OP is not added
refute user.ap_id in secret_answer.recipients
end
test "it allows to address a list" do test "it allows to address a list" do
user = insert(:user) user = insert(:user)
{:ok, list} = Pleroma.List.create("foo", user) {:ok, list} = Pleroma.List.create("foo", user)

View File

@ -297,11 +297,10 @@ test "for private posts, a reply" do
{to, cc} = Utils.get_to_and_cc(user, mentions, activity, "private", nil) {to, cc} = Utils.get_to_and_cc(user, mentions, activity, "private", nil)
assert length(to) == 3 assert length(to) == 2
assert Enum.empty?(cc) assert Enum.empty?(cc)
assert mentioned_user.ap_id in to assert mentioned_user.ap_id in to
assert third_user.ap_id in to
assert user.follower_address in to assert user.follower_address in to
end end
@ -327,6 +326,15 @@ test "for direct posts, a reply" do
{to, cc} = Utils.get_to_and_cc(user, mentions, activity, "direct", nil) {to, cc} = Utils.get_to_and_cc(user, mentions, activity, "direct", nil)
assert length(to) == 1
assert Enum.empty?(cc)
assert mentioned_user.ap_id in to
{:ok, direct_activity} = CommonAPI.post(third_user, %{status: "uguu", visibility: "direct"})
{to, cc} = Utils.get_to_and_cc(user, mentions, direct_activity, "direct", nil)
assert length(to) == 2 assert length(to) == 2
assert Enum.empty?(cc) assert Enum.empty?(cc)