aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorlain <lain@soykaf.club>2019-08-06 14:51:17 +0200
committerlain <lain@soykaf.club>2019-08-06 14:51:17 +0200
commita49c92f6ae2dc68a80345cff4793820a75835eb1 (patch)
treed6d2c15479a7b7acba5fab3d70fcb7eeaa3269a0
parentd6fe220e32d581220cc33f4f44d6517a401eabbf (diff)
downloadpleroma-a49c92f6ae2dc68a80345cff4793820a75835eb1.tar.gz
Participation: Setting recipients will always add the owner.
-rw-r--r--docs/api/pleroma_api.md2
-rw-r--r--lib/pleroma/conversation/participation.ex6
-rw-r--r--test/conversation/participation_test.exs19
3 files changed, 26 insertions, 1 deletions
diff --git a/docs/api/pleroma_api.md b/docs/api/pleroma_api.md
index 4323e59f0..590f2a3fb 100644
--- a/docs/api/pleroma_api.md
+++ b/docs/api/pleroma_api.md
@@ -346,5 +346,5 @@ The status posting endpoint takes an additional parameter, `in_reply_to_conversa
* Method `PATCH`
* Authentication: required
* Params:
- * `recipients`: A list of ids of users that should receive posts to this conversation.
+ * `recipients`: A list of ids of users that should receive posts to this conversation. This will replace the current list of recipients, so submit the full list. The owner of owner of the conversation will always be part of the set of recipients, though.
* Response: JSON, statuses (200 - healthy, 503 unhealthy)
diff --git a/lib/pleroma/conversation/participation.ex b/lib/pleroma/conversation/participation.ex
index acdee5517..d17b6f7c5 100644
--- a/lib/pleroma/conversation/participation.ex
+++ b/lib/pleroma/conversation/participation.ex
@@ -101,6 +101,10 @@ defmodule Pleroma.Conversation.Participation do
end
def set_recipients(participation, user_ids) do
+ user_ids =
+ [participation.user_id | user_ids]
+ |> Enum.uniq()
+
Repo.transaction(fn ->
query =
from(r in RecipientShip,
@@ -118,5 +122,7 @@ defmodule Pleroma.Conversation.Participation do
RecipientShip.create(users, participation)
:ok
end)
+
+ {:ok, Repo.preload(participation, :recipients, force: true)}
end
end
diff --git a/test/conversation/participation_test.exs b/test/conversation/participation_test.exs
index 4a3c397bd..7958e8e89 100644
--- a/test/conversation/participation_test.exs
+++ b/test/conversation/participation_test.exs
@@ -132,4 +132,23 @@ defmodule Pleroma.Conversation.ParticipationTest do
[] = Participation.for_user_with_last_activity_id(user)
end
+
+ test "it sets recipients, always keeping the owner of the participation even when not explicitly set" do
+ user = insert(:user)
+ other_user = insert(:user)
+
+ {:ok, _activity} = CommonAPI.post(user, %{"status" => ".", "visibility" => "direct"})
+ [participation] = Participation.for_user_with_last_activity_id(user)
+
+ participation = Repo.preload(participation, :recipients)
+
+ assert participation.recipients |> length() == 1
+ assert user in participation.recipients
+
+ {:ok, participation} = Participation.set_recipients(participation, [other_user.id])
+
+ assert participation.recipients |> length() == 2
+ assert user in participation.recipients
+ assert other_user in participation.recipients
+ end
end