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
direct? = visibility == "direct"
additional_data =
%{"cc" => cc, "directMessage" => direct?} |> maybe_add_list_data(user, visibility)
params = %{
%{
to: to,
actor: user,
context: context,
object: object,
additional: additional_data
additional: %{"cc" => cc, "directMessage" => direct?}
}
ActivityPub.create(params, preview?)
|> maybe_add_list_data(user, visibility)
|> ActivityPub.create(preview?)
else
{:private_to_public, true} ->
{: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 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
%Pleroma.List{} = list ->
additional_data
|> Map.put("listMessage", list.ap_id)
|> Map.put("bcc", [list.ap_id])
activity_params
|> put_in([:additional, "bcc"], [list.ap_id])
|> put_in([:additional, "listMessage"], list.ap_id)
|> put_in([:object, "listMessage"], list.ap_id)
_ ->
additional_data
activity_params
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)
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] ==
AccountView.render("relationship.json", %{user: user, target: user})
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