Support `list` visibility in StatusView

This commit is contained in:
Egor Kislitsyn 2019-07-15 14:00:29 +07:00
parent 9991254c06
commit a87c313309
3 changed files with 24 additions and 13 deletions

View File

@ -243,18 +243,15 @@ def post(user, %{"status" => status} = data) do
preview? = Pleroma.Web.ControllerHelper.truthy_param?(data["preview"]) || false preview? = Pleroma.Web.ControllerHelper.truthy_param?(data["preview"]) || false
direct? = visibility == "direct" direct? = visibility == "direct"
additional_data = %{
%{"cc" => cc, "directMessage" => direct?} |> maybe_add_list_data(user, visibility)
params = %{
to: to, to: to,
actor: user, actor: user,
context: context, context: context,
object: object, object: object,
additional: additional_data additional: %{"cc" => cc, "directMessage" => direct?}
} }
|> maybe_add_list_data(user, visibility)
ActivityPub.create(params, preview?) |> ActivityPub.create(preview?)
else else
{:private_to_public, true} -> {:private_to_public, true} ->
{:error, dgettext("errors", "The message visibility must be direct")} {:error, dgettext("errors", "The message visibility must be direct")}

View File

@ -108,19 +108,20 @@ def get_addressed_users(_, to) when is_list(to) do
def get_addressed_users(mentioned_users, _), do: mentioned_users def get_addressed_users(mentioned_users, _), do: mentioned_users
def maybe_add_list_data(additional_data, user, {:list, list_id}) do def maybe_add_list_data(activity_params, user, {:list, list_id}) do
case Pleroma.List.get(list_id, user) do case Pleroma.List.get(list_id, user) do
%Pleroma.List{} = list -> %Pleroma.List{} = list ->
additional_data activity_params
|> Map.put("listMessage", list.ap_id) |> put_in([:additional, "bcc"], [list.ap_id])
|> Map.put("bcc", [list.ap_id]) |> put_in([:additional, "listMessage"], list.ap_id)
|> put_in([:object, "listMessage"], list.ap_id)
_ -> _ ->
additional_data activity_params
end end
end end
def maybe_add_list_data(additional_data, _, _), do: additional_data def maybe_add_list_data(activity_params, _, _), do: activity_params
def make_poll_data(%{"poll" => %{"options" => options, "expires_in" => expires_in}} = data) def make_poll_data(%{"poll" => %{"options" => options, "expires_in" => expires_in}} = data)
when is_list(options) do when is_list(options) do

View File

@ -541,4 +541,17 @@ test "embeds a relationship in the account in reposts" do
assert result[:reblog][:account][:pleroma][:relationship] == assert result[:reblog][:account][:pleroma][:relationship] ==
AccountView.render("relationship.json", %{user: user, target: user}) AccountView.render("relationship.json", %{user: user, target: user})
end end
test "visibility/list" do
user = insert(:user)
{:ok, list} = Pleroma.List.create("foo", user)
{:ok, activity} =
CommonAPI.post(user, %{"status" => "foobar", "visibility" => "list:#{list.id}"})
status = StatusView.render("status.json", activity: activity)
assert status.visibility == "list"
end
end end