Merge branch 'feature/local-only-scope' into 'develop'
Add local-only statuses Closes #75 and #1483 See merge request pleroma/pleroma!2289
This commit is contained in:
commit
fbd6217ed9
|
@ -15,6 +15,7 @@ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/).
|
||||||
|
|
||||||
- Reports now generate notifications for admins and mods.
|
- Reports now generate notifications for admins and mods.
|
||||||
- Experimental websocket-based federation between Pleroma instances.
|
- Experimental websocket-based federation between Pleroma instances.
|
||||||
|
- Support for local-only statuses
|
||||||
- Support pagination of blocks and mutes.
|
- Support pagination of blocks and mutes.
|
||||||
- Account backup.
|
- Account backup.
|
||||||
- Configuration: Add `:instance, autofollowing_nicknames` setting to provide a way to make accounts automatically follow new users that register on the local Pleroma instance.
|
- Configuration: Add `:instance, autofollowing_nicknames` setting to provide a way to make accounts automatically follow new users that register on the local Pleroma instance.
|
||||||
|
|
|
@ -18,7 +18,7 @@ Adding the parameter `instance=lain.com` to the public timeline will show only s
|
||||||
|
|
||||||
## Statuses
|
## Statuses
|
||||||
|
|
||||||
- `visibility`: has an additional possible value `list`
|
- `visibility`: has additional possible values `list` and `local` (for local-only statuses)
|
||||||
|
|
||||||
Has these additional fields under the `pleroma` object:
|
Has these additional fields under the `pleroma` object:
|
||||||
|
|
||||||
|
@ -173,7 +173,7 @@ Additional parameters can be added to the JSON body/Form data:
|
||||||
- `preview`: boolean, if set to `true` the post won't be actually posted, but the status entitiy would still be rendered back. This could be useful for previewing rich text/custom emoji, for example.
|
- `preview`: boolean, if set to `true` the post won't be actually posted, but the status entitiy would still be rendered back. This could be useful for previewing rich text/custom emoji, for example.
|
||||||
- `content_type`: string, contain the MIME type of the status, it is transformed into HTML by the backend. You can get the list of the supported MIME types with the nodeinfo endpoint.
|
- `content_type`: string, contain the MIME type of the status, it is transformed into HTML by the backend. You can get the list of the supported MIME types with the nodeinfo endpoint.
|
||||||
- `to`: A list of nicknames (like `lain@soykaf.club` or `lain` on the local server) that will be used to determine who is going to be addressed by this post. Using this will disable the implicit addressing by mentioned names in the `status` body, only the people in the `to` list will be addressed. The normal rules for for post visibility are not affected by this and will still apply.
|
- `to`: A list of nicknames (like `lain@soykaf.club` or `lain` on the local server) that will be used to determine who is going to be addressed by this post. Using this will disable the implicit addressing by mentioned names in the `status` body, only the people in the `to` list will be addressed. The normal rules for for post visibility are not affected by this and will still apply.
|
||||||
- `visibility`: string, besides standard MastoAPI values (`direct`, `private`, `unlisted` or `public`) it can be used to address a List by setting it to `list:LIST_ID`.
|
- `visibility`: string, besides standard MastoAPI values (`direct`, `private`, `unlisted`, `local` or `public`) it can be used to address a List by setting it to `list:LIST_ID`.
|
||||||
- `expires_in`: The number of seconds the posted activity should expire in. When a posted activity expires it will be deleted from the server, and a delete request for it will be federated. This needs to be longer than an hour.
|
- `expires_in`: The number of seconds the posted activity should expire in. When a posted activity expires it will be deleted from the server, and a delete request for it will be federated. This needs to be longer than an hour.
|
||||||
- `in_reply_to_conversation_id`: Will reply to a given conversation, addressing only the people who are part of the recipient set of that conversation. Sets the visibility to `direct`.
|
- `in_reply_to_conversation_id`: Will reply to a given conversation, addressing only the people who are part of the recipient set of that conversation. Sets the visibility to `direct`.
|
||||||
|
|
||||||
|
|
|
@ -26,4 +26,6 @@ defmodule Pleroma.Constants do
|
||||||
do:
|
do:
|
||||||
~w(index.html robots.txt static static-fe finmoji emoji packs sounds images instance sw.js sw-pleroma.js favicon.png schemas doc embed.js embed.css)
|
~w(index.html robots.txt static static-fe finmoji emoji packs sounds images instance sw.js sw-pleroma.js favicon.png schemas doc embed.js embed.css)
|
||||||
)
|
)
|
||||||
|
|
||||||
|
def as_local_public, do: Pleroma.Web.base_url() <> "/#Public"
|
||||||
end
|
end
|
||||||
|
|
|
@ -82,7 +82,8 @@ def user(conn, %{"nickname" => nickname}) do
|
||||||
def object(conn, _) do
|
def object(conn, _) do
|
||||||
with ap_id <- Endpoint.url() <> conn.request_path,
|
with ap_id <- Endpoint.url() <> conn.request_path,
|
||||||
%Object{} = object <- Object.get_cached_by_ap_id(ap_id),
|
%Object{} = object <- Object.get_cached_by_ap_id(ap_id),
|
||||||
{_, true} <- {:public?, Visibility.is_public?(object)} do
|
{_, true} <- {:public?, Visibility.is_public?(object)},
|
||||||
|
{_, false} <- {:local?, Visibility.is_local_public?(object)} do
|
||||||
conn
|
conn
|
||||||
|> assign(:tracking_fun_data, object.id)
|
|> assign(:tracking_fun_data, object.id)
|
||||||
|> set_cache_ttl_for(object)
|
|> set_cache_ttl_for(object)
|
||||||
|
@ -92,6 +93,9 @@ def object(conn, _) do
|
||||||
else
|
else
|
||||||
{:public?, false} ->
|
{:public?, false} ->
|
||||||
{:error, :not_found}
|
{:error, :not_found}
|
||||||
|
|
||||||
|
{:local?, true} ->
|
||||||
|
{:error, :not_found}
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
@ -108,7 +112,8 @@ def track_object_fetch(conn, object_id) do
|
||||||
def activity(conn, _params) do
|
def activity(conn, _params) do
|
||||||
with ap_id <- Endpoint.url() <> conn.request_path,
|
with ap_id <- Endpoint.url() <> conn.request_path,
|
||||||
%Activity{} = activity <- Activity.normalize(ap_id),
|
%Activity{} = activity <- Activity.normalize(ap_id),
|
||||||
{_, true} <- {:public?, Visibility.is_public?(activity)} do
|
{_, true} <- {:public?, Visibility.is_public?(activity)},
|
||||||
|
{_, false} <- {:local?, Visibility.is_local_public?(activity)} do
|
||||||
conn
|
conn
|
||||||
|> maybe_set_tracking_data(activity)
|
|> maybe_set_tracking_data(activity)
|
||||||
|> set_cache_ttl_for(activity)
|
|> set_cache_ttl_for(activity)
|
||||||
|
@ -117,6 +122,7 @@ def activity(conn, _params) do
|
||||||
|> render("object.json", object: activity)
|
|> render("object.json", object: activity)
|
||||||
else
|
else
|
||||||
{:public?, false} -> {:error, :not_found}
|
{:public?, false} -> {:error, :not_found}
|
||||||
|
{:local?, true} -> {:error, :not_found}
|
||||||
nil -> {:error, :not_found}
|
nil -> {:error, :not_found}
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
|
@ -222,6 +222,9 @@ def announce(actor, object, options \\ []) do
|
||||||
actor.ap_id == Relay.ap_id() ->
|
actor.ap_id == Relay.ap_id() ->
|
||||||
[actor.follower_address]
|
[actor.follower_address]
|
||||||
|
|
||||||
|
public? and Visibility.is_local_public?(object) ->
|
||||||
|
[actor.follower_address, object.data["actor"], Pleroma.Constants.as_local_public()]
|
||||||
|
|
||||||
public? ->
|
public? ->
|
||||||
[actor.follower_address, object.data["actor"], Pleroma.Constants.as_public()]
|
[actor.follower_address, object.data["actor"], Pleroma.Constants.as_public()]
|
||||||
|
|
||||||
|
|
|
@ -67,7 +67,12 @@ def validate_announcable(cng) do
|
||||||
%Object{} = object <- Object.get_cached_by_ap_id(object),
|
%Object{} = object <- Object.get_cached_by_ap_id(object),
|
||||||
false <- Visibility.is_public?(object) do
|
false <- Visibility.is_public?(object) do
|
||||||
same_actor = object.data["actor"] == actor.ap_id
|
same_actor = object.data["actor"] == actor.ap_id
|
||||||
is_public = Pleroma.Constants.as_public() in (get_field(cng, :to) ++ get_field(cng, :cc))
|
recipients = get_field(cng, :to) ++ get_field(cng, :cc)
|
||||||
|
local_public = Pleroma.Constants.as_local_public()
|
||||||
|
|
||||||
|
is_public =
|
||||||
|
Enum.member?(recipients, Pleroma.Constants.as_public()) or
|
||||||
|
Enum.member?(recipients, local_public)
|
||||||
|
|
||||||
cond do
|
cond do
|
||||||
same_actor && is_public ->
|
same_actor && is_public ->
|
||||||
|
|
|
@ -11,6 +11,7 @@ defmodule Pleroma.Web.ActivityPub.Pipeline do
|
||||||
alias Pleroma.Web.ActivityPub.MRF
|
alias Pleroma.Web.ActivityPub.MRF
|
||||||
alias Pleroma.Web.ActivityPub.ObjectValidator
|
alias Pleroma.Web.ActivityPub.ObjectValidator
|
||||||
alias Pleroma.Web.ActivityPub.SideEffects
|
alias Pleroma.Web.ActivityPub.SideEffects
|
||||||
|
alias Pleroma.Web.ActivityPub.Visibility
|
||||||
alias Pleroma.Web.Federator
|
alias Pleroma.Web.Federator
|
||||||
|
|
||||||
@spec common_pipeline(map(), keyword()) ::
|
@spec common_pipeline(map(), keyword()) ::
|
||||||
|
@ -55,7 +56,7 @@ defp maybe_federate(%Activity{} = activity, meta) do
|
||||||
with {:ok, local} <- Keyword.fetch(meta, :local) do
|
with {:ok, local} <- Keyword.fetch(meta, :local) do
|
||||||
do_not_federate = meta[:do_not_federate] || !Config.get([:instance, :federating])
|
do_not_federate = meta[:do_not_federate] || !Config.get([:instance, :federating])
|
||||||
|
|
||||||
if !do_not_federate && local do
|
if !do_not_federate and local and not Visibility.is_local_public?(activity) do
|
||||||
activity =
|
activity =
|
||||||
if object = Keyword.get(meta, :object_data) do
|
if object = Keyword.get(meta, :object_data) do
|
||||||
%{activity | data: Map.put(activity.data, "object", object)}
|
%{activity | data: Map.put(activity.data, "object", object)}
|
||||||
|
|
|
@ -175,7 +175,8 @@ def maybe_federate(%Activity{local: true, data: %{"type" => type}} = activity) d
|
||||||
outgoing_blocks = Config.get([:activitypub, :outgoing_blocks])
|
outgoing_blocks = Config.get([:activitypub, :outgoing_blocks])
|
||||||
|
|
||||||
with true <- Config.get!([:instance, :federating]),
|
with true <- Config.get!([:instance, :federating]),
|
||||||
true <- type != "Block" || outgoing_blocks do
|
true <- type != "Block" || outgoing_blocks,
|
||||||
|
false <- Visibility.is_local_public?(activity) do
|
||||||
Pleroma.Web.Federator.publish(activity)
|
Pleroma.Web.Federator.publish(activity)
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
|
@ -17,7 +17,19 @@ def is_public?(%Object{data: data}), do: is_public?(data)
|
||||||
def is_public?(%Activity{data: %{"type" => "Move"}}), do: true
|
def is_public?(%Activity{data: %{"type" => "Move"}}), do: true
|
||||||
def is_public?(%Activity{data: data}), do: is_public?(data)
|
def is_public?(%Activity{data: data}), do: is_public?(data)
|
||||||
def is_public?(%{"directMessage" => true}), do: false
|
def is_public?(%{"directMessage" => true}), do: false
|
||||||
def is_public?(data), do: Utils.label_in_message?(Pleroma.Constants.as_public(), data)
|
|
||||||
|
def is_public?(data) do
|
||||||
|
Utils.label_in_message?(Pleroma.Constants.as_public(), data) or
|
||||||
|
Utils.label_in_message?(Pleroma.Constants.as_local_public(), data)
|
||||||
|
end
|
||||||
|
|
||||||
|
def is_local_public?(%Object{data: data}), do: is_local_public?(data)
|
||||||
|
def is_local_public?(%Activity{data: data}), do: is_local_public?(data)
|
||||||
|
|
||||||
|
def is_local_public?(data) do
|
||||||
|
Utils.label_in_message?(Pleroma.Constants.as_local_public(), data) and
|
||||||
|
not Utils.label_in_message?(Pleroma.Constants.as_public(), data)
|
||||||
|
end
|
||||||
|
|
||||||
def is_private?(activity) do
|
def is_private?(activity) do
|
||||||
with false <- is_public?(activity),
|
with false <- is_public?(activity),
|
||||||
|
@ -114,6 +126,9 @@ def get_visibility(object) do
|
||||||
Pleroma.Constants.as_public() in cc ->
|
Pleroma.Constants.as_public() in cc ->
|
||||||
"unlisted"
|
"unlisted"
|
||||||
|
|
||||||
|
Pleroma.Constants.as_local_public() in to ->
|
||||||
|
"local"
|
||||||
|
|
||||||
# this should use the sql for the object's activity
|
# this should use the sql for the object's activity
|
||||||
Enum.any?(to, &String.contains?(&1, "/followers")) ->
|
Enum.any?(to, &String.contains?(&1, "/followers")) ->
|
||||||
"private"
|
"private"
|
||||||
|
|
|
@ -9,6 +9,6 @@ defmodule Pleroma.Web.ApiSpec.Schemas.VisibilityScope do
|
||||||
title: "VisibilityScope",
|
title: "VisibilityScope",
|
||||||
description: "Status visibility",
|
description: "Status visibility",
|
||||||
type: :string,
|
type: :string,
|
||||||
enum: ["public", "unlisted", "private", "direct", "list"]
|
enum: ["public", "unlisted", "local", "private", "direct", "list"]
|
||||||
})
|
})
|
||||||
end
|
end
|
||||||
|
|
|
@ -15,6 +15,7 @@ defmodule Pleroma.Web.CommonAPI do
|
||||||
alias Pleroma.Web.ActivityPub.Pipeline
|
alias Pleroma.Web.ActivityPub.Pipeline
|
||||||
alias Pleroma.Web.ActivityPub.Utils
|
alias Pleroma.Web.ActivityPub.Utils
|
||||||
alias Pleroma.Web.ActivityPub.Visibility
|
alias Pleroma.Web.ActivityPub.Visibility
|
||||||
|
alias Pleroma.Web.CommonAPI.ActivityDraft
|
||||||
|
|
||||||
import Pleroma.Web.Gettext
|
import Pleroma.Web.Gettext
|
||||||
import Pleroma.Web.CommonAPI.Utils
|
import Pleroma.Web.CommonAPI.Utils
|
||||||
|
@ -358,7 +359,7 @@ def public_announce?(object, _) do
|
||||||
def get_visibility(_, _, %Participation{}), do: {"direct", "direct"}
|
def get_visibility(_, _, %Participation{}), do: {"direct", "direct"}
|
||||||
|
|
||||||
def get_visibility(%{visibility: visibility}, in_reply_to, _)
|
def get_visibility(%{visibility: visibility}, in_reply_to, _)
|
||||||
when visibility in ~w{public unlisted private direct},
|
when visibility in ~w{public local unlisted private direct},
|
||||||
do: {visibility, get_replied_to_visibility(in_reply_to)}
|
do: {visibility, get_replied_to_visibility(in_reply_to)}
|
||||||
|
|
||||||
def get_visibility(%{visibility: "list:" <> list_id}, in_reply_to, _) do
|
def get_visibility(%{visibility: "list:" <> list_id}, in_reply_to, _) do
|
||||||
|
@ -399,31 +400,13 @@ def check_expiry_date(expiry_str) do
|
||||||
end
|
end
|
||||||
|
|
||||||
def listen(user, data) do
|
def listen(user, data) do
|
||||||
visibility = Map.get(data, :visibility, "public")
|
with {:ok, draft} <- ActivityDraft.listen(user, data) do
|
||||||
|
ActivityPub.listen(draft.changes)
|
||||||
with {to, cc} <- get_to_and_cc(user, [], nil, visibility, nil),
|
|
||||||
listen_data <-
|
|
||||||
data
|
|
||||||
|> Map.take([:album, :artist, :title, :length])
|
|
||||||
|> Map.new(fn {key, value} -> {to_string(key), value} end)
|
|
||||||
|> Map.put("type", "Audio")
|
|
||||||
|> Map.put("to", to)
|
|
||||||
|> Map.put("cc", cc)
|
|
||||||
|> Map.put("actor", user.ap_id),
|
|
||||||
{:ok, activity} <-
|
|
||||||
ActivityPub.listen(%{
|
|
||||||
actor: user,
|
|
||||||
to: to,
|
|
||||||
object: listen_data,
|
|
||||||
context: Utils.generate_context_id(),
|
|
||||||
additional: %{"cc" => cc}
|
|
||||||
}) do
|
|
||||||
{:ok, activity}
|
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
def post(user, %{status: _} = data) do
|
def post(user, %{status: _} = data) do
|
||||||
with {:ok, draft} <- Pleroma.Web.CommonAPI.ActivityDraft.create(user, data) do
|
with {:ok, draft} <- ActivityDraft.create(user, data) do
|
||||||
ActivityPub.create(draft.changes, draft.preview?)
|
ActivityPub.create(draft.changes, draft.preview?)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
|
@ -22,7 +22,7 @@ defmodule Pleroma.Web.CommonAPI.ActivityDraft do
|
||||||
in_reply_to_conversation: nil,
|
in_reply_to_conversation: nil,
|
||||||
visibility: nil,
|
visibility: nil,
|
||||||
expires_at: nil,
|
expires_at: nil,
|
||||||
poll: nil,
|
extra: nil,
|
||||||
emoji: %{},
|
emoji: %{},
|
||||||
content_html: nil,
|
content_html: nil,
|
||||||
mentions: [],
|
mentions: [],
|
||||||
|
@ -35,9 +35,14 @@ defmodule Pleroma.Web.CommonAPI.ActivityDraft do
|
||||||
preview?: false,
|
preview?: false,
|
||||||
changes: %{}
|
changes: %{}
|
||||||
|
|
||||||
def create(user, params) do
|
def new(user, params) do
|
||||||
%__MODULE__{user: user}
|
%__MODULE__{user: user}
|
||||||
|> put_params(params)
|
|> put_params(params)
|
||||||
|
end
|
||||||
|
|
||||||
|
def create(user, params) do
|
||||||
|
user
|
||||||
|
|> new(params)
|
||||||
|> status()
|
|> status()
|
||||||
|> summary()
|
|> summary()
|
||||||
|> with_valid(&attachments/1)
|
|> with_valid(&attachments/1)
|
||||||
|
@ -57,6 +62,30 @@ def create(user, params) do
|
||||||
|> validate()
|
|> validate()
|
||||||
end
|
end
|
||||||
|
|
||||||
|
def listen(user, params) do
|
||||||
|
user
|
||||||
|
|> new(params)
|
||||||
|
|> visibility()
|
||||||
|
|> to_and_cc()
|
||||||
|
|> context()
|
||||||
|
|> listen_object()
|
||||||
|
|> with_valid(&changes/1)
|
||||||
|
|> validate()
|
||||||
|
end
|
||||||
|
|
||||||
|
defp listen_object(draft) do
|
||||||
|
object =
|
||||||
|
draft.params
|
||||||
|
|> Map.take([:album, :artist, :title, :length])
|
||||||
|
|> Map.new(fn {key, value} -> {to_string(key), value} end)
|
||||||
|
|> Map.put("type", "Audio")
|
||||||
|
|> Map.put("to", draft.to)
|
||||||
|
|> Map.put("cc", draft.cc)
|
||||||
|
|> Map.put("actor", draft.user.ap_id)
|
||||||
|
|
||||||
|
%__MODULE__{draft | object: object}
|
||||||
|
end
|
||||||
|
|
||||||
defp put_params(draft, params) do
|
defp put_params(draft, params) do
|
||||||
params = Map.put_new(params, :in_reply_to_status_id, params[:in_reply_to_id])
|
params = Map.put_new(params, :in_reply_to_status_id, params[:in_reply_to_id])
|
||||||
%__MODULE__{draft | params: params}
|
%__MODULE__{draft | params: params}
|
||||||
|
@ -121,7 +150,7 @@ defp expires_at(draft) do
|
||||||
defp poll(draft) do
|
defp poll(draft) do
|
||||||
case Utils.make_poll_data(draft.params) do
|
case Utils.make_poll_data(draft.params) do
|
||||||
{:ok, {poll, poll_emoji}} ->
|
{:ok, {poll, poll_emoji}} ->
|
||||||
%__MODULE__{draft | poll: poll, emoji: Map.merge(draft.emoji, poll_emoji)}
|
%__MODULE__{draft | extra: poll, emoji: Map.merge(draft.emoji, poll_emoji)}
|
||||||
|
|
||||||
{:error, message} ->
|
{:error, message} ->
|
||||||
add_error(draft, message)
|
add_error(draft, message)
|
||||||
|
@ -129,32 +158,18 @@ defp poll(draft) do
|
||||||
end
|
end
|
||||||
|
|
||||||
defp content(draft) do
|
defp content(draft) do
|
||||||
{content_html, mentions, tags} =
|
{content_html, mentioned_users, tags} = Utils.make_content_html(draft)
|
||||||
Utils.make_content_html(
|
|
||||||
draft.status,
|
mentions =
|
||||||
draft.attachments,
|
mentioned_users
|
||||||
draft.params,
|
|> Enum.map(fn {_, mentioned_user} -> mentioned_user.ap_id end)
|
||||||
draft.visibility
|
|> Utils.get_addressed_users(draft.params[:to])
|
||||||
)
|
|
||||||
|
|
||||||
%__MODULE__{draft | content_html: content_html, mentions: mentions, tags: tags}
|
%__MODULE__{draft | content_html: content_html, mentions: mentions, tags: tags}
|
||||||
end
|
end
|
||||||
|
|
||||||
defp to_and_cc(draft) do
|
defp to_and_cc(draft) do
|
||||||
addressed_users =
|
{to, cc} = Utils.get_to_and_cc(draft)
|
||||||
draft.mentions
|
|
||||||
|> Enum.map(fn {_, mentioned_user} -> mentioned_user.ap_id end)
|
|
||||||
|> Utils.get_addressed_users(draft.params[:to])
|
|
||||||
|
|
||||||
{to, cc} =
|
|
||||||
Utils.get_to_and_cc(
|
|
||||||
draft.user,
|
|
||||||
addressed_users,
|
|
||||||
draft.in_reply_to,
|
|
||||||
draft.visibility,
|
|
||||||
draft.in_reply_to_conversation
|
|
||||||
)
|
|
||||||
|
|
||||||
%__MODULE__{draft | to: to, cc: cc}
|
%__MODULE__{draft | to: to, cc: cc}
|
||||||
end
|
end
|
||||||
|
|
||||||
|
@ -172,19 +187,7 @@ defp object(draft) do
|
||||||
emoji = Map.merge(Pleroma.Emoji.Formatter.get_emoji_map(draft.full_payload), draft.emoji)
|
emoji = Map.merge(Pleroma.Emoji.Formatter.get_emoji_map(draft.full_payload), draft.emoji)
|
||||||
|
|
||||||
object =
|
object =
|
||||||
Utils.make_note_data(
|
Utils.make_note_data(draft)
|
||||||
draft.user.ap_id,
|
|
||||||
draft.to,
|
|
||||||
draft.context,
|
|
||||||
draft.content_html,
|
|
||||||
draft.attachments,
|
|
||||||
draft.in_reply_to,
|
|
||||||
draft.tags,
|
|
||||||
draft.summary,
|
|
||||||
draft.cc,
|
|
||||||
draft.sensitive,
|
|
||||||
draft.poll
|
|
||||||
)
|
|
||||||
|> Map.put("emoji", emoji)
|
|> Map.put("emoji", emoji)
|
||||||
|> Map.put("source", draft.status)
|
|> Map.put("source", draft.status)
|
||||||
|
|
||||||
|
|
|
@ -16,6 +16,7 @@ defmodule Pleroma.Web.CommonAPI.Utils do
|
||||||
alias Pleroma.User
|
alias Pleroma.User
|
||||||
alias Pleroma.Web.ActivityPub.Utils
|
alias Pleroma.Web.ActivityPub.Utils
|
||||||
alias Pleroma.Web.ActivityPub.Visibility
|
alias Pleroma.Web.ActivityPub.Visibility
|
||||||
|
alias Pleroma.Web.CommonAPI.ActivityDraft
|
||||||
alias Pleroma.Web.MediaProxy
|
alias Pleroma.Web.MediaProxy
|
||||||
alias Pleroma.Web.Plugs.AuthenticationPlug
|
alias Pleroma.Web.Plugs.AuthenticationPlug
|
||||||
|
|
||||||
|
@ -50,67 +51,62 @@ def attachments_from_ids_descs(ids, descs_str) do
|
||||||
{_, descs} = Jason.decode(descs_str)
|
{_, descs} = Jason.decode(descs_str)
|
||||||
|
|
||||||
Enum.map(ids, fn media_id ->
|
Enum.map(ids, fn media_id ->
|
||||||
case Repo.get(Object, media_id) do
|
with %Object{data: data} <- Repo.get(Object, media_id) do
|
||||||
%Object{data: data} ->
|
|
||||||
Map.put(data, "name", descs[media_id])
|
Map.put(data, "name", descs[media_id])
|
||||||
|
|
||||||
_ ->
|
|
||||||
nil
|
|
||||||
end
|
end
|
||||||
end)
|
end)
|
||||||
|> Enum.reject(&is_nil/1)
|
|> Enum.reject(&is_nil/1)
|
||||||
end
|
end
|
||||||
|
|
||||||
@spec get_to_and_cc(
|
@spec get_to_and_cc(ActivityDraft.t()) :: {list(String.t()), list(String.t())}
|
||||||
User.t(),
|
|
||||||
list(String.t()),
|
|
||||||
Activity.t() | nil,
|
|
||||||
String.t(),
|
|
||||||
Participation.t() | nil
|
|
||||||
) :: {list(String.t()), list(String.t())}
|
|
||||||
|
|
||||||
def get_to_and_cc(_, _, _, _, %Participation{} = participation) do
|
def get_to_and_cc(%{in_reply_to_conversation: %Participation{} = participation}) do
|
||||||
participation = Repo.preload(participation, :recipients)
|
participation = Repo.preload(participation, :recipients)
|
||||||
{Enum.map(participation.recipients, & &1.ap_id), []}
|
{Enum.map(participation.recipients, & &1.ap_id), []}
|
||||||
end
|
end
|
||||||
|
|
||||||
def get_to_and_cc(user, mentioned_users, inReplyTo, "public", _) do
|
def get_to_and_cc(%{visibility: visibility} = draft) when visibility in ["public", "local"] do
|
||||||
to = [Pleroma.Constants.as_public() | mentioned_users]
|
to =
|
||||||
cc = [user.follower_address]
|
case visibility do
|
||||||
|
"public" -> [Pleroma.Constants.as_public() | draft.mentions]
|
||||||
|
"local" -> [Pleroma.Constants.as_local_public() | draft.mentions]
|
||||||
|
end
|
||||||
|
|
||||||
if inReplyTo do
|
cc = [draft.user.follower_address]
|
||||||
{Enum.uniq([inReplyTo.data["actor"] | to]), cc}
|
|
||||||
|
if draft.in_reply_to do
|
||||||
|
{Enum.uniq([draft.in_reply_to.data["actor"] | to]), cc}
|
||||||
else
|
else
|
||||||
{to, cc}
|
{to, cc}
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
def get_to_and_cc(user, mentioned_users, inReplyTo, "unlisted", _) do
|
def get_to_and_cc(%{visibility: "unlisted"} = draft) do
|
||||||
to = [user.follower_address | mentioned_users]
|
to = [draft.user.follower_address | draft.mentions]
|
||||||
cc = [Pleroma.Constants.as_public()]
|
cc = [Pleroma.Constants.as_public()]
|
||||||
|
|
||||||
if inReplyTo do
|
if draft.in_reply_to do
|
||||||
{Enum.uniq([inReplyTo.data["actor"] | to]), cc}
|
{Enum.uniq([draft.in_reply_to.data["actor"] | to]), cc}
|
||||||
else
|
else
|
||||||
{to, cc}
|
{to, cc}
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
def get_to_and_cc(user, mentioned_users, inReplyTo, "private", _) do
|
def get_to_and_cc(%{visibility: "private"} = draft) do
|
||||||
{to, cc} = get_to_and_cc(user, mentioned_users, inReplyTo, "direct", nil)
|
{to, cc} = get_to_and_cc(struct(draft, visibility: "direct"))
|
||||||
{[user.follower_address | to], cc}
|
{[draft.user.follower_address | to], cc}
|
||||||
end
|
end
|
||||||
|
|
||||||
def get_to_and_cc(_user, mentioned_users, inReplyTo, "direct", _) do
|
def get_to_and_cc(%{visibility: "direct"} = draft) do
|
||||||
# If the OP is a DM already, add the implicit actor.
|
# If the OP is a DM already, add the implicit actor.
|
||||||
if inReplyTo && Visibility.is_direct?(inReplyTo) do
|
if draft.in_reply_to && Visibility.is_direct?(draft.in_reply_to) do
|
||||||
{Enum.uniq([inReplyTo.data["actor"] | mentioned_users]), []}
|
{Enum.uniq([draft.in_reply_to.data["actor"] | draft.mentions]), []}
|
||||||
else
|
else
|
||||||
{mentioned_users, []}
|
{draft.mentions, []}
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
def get_to_and_cc(_user, mentions, _inReplyTo, {:list, _}, _), do: {mentions, []}
|
def get_to_and_cc(%{visibility: {:list, _}, mentions: mentions}), do: {mentions, []}
|
||||||
|
|
||||||
def get_addressed_users(_, to) when is_list(to) do
|
def get_addressed_users(_, to) when is_list(to) do
|
||||||
User.get_ap_ids_by_nicknames(to)
|
User.get_ap_ids_by_nicknames(to)
|
||||||
|
@ -203,30 +199,25 @@ defp validate_poll_expiration(expires_in, %{min_expiration: min, max_expiration:
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
def make_content_html(
|
def make_content_html(%ActivityDraft{} = draft) do
|
||||||
status,
|
|
||||||
attachments,
|
|
||||||
data,
|
|
||||||
visibility
|
|
||||||
) do
|
|
||||||
attachment_links =
|
attachment_links =
|
||||||
data
|
draft.params
|
||||||
|> Map.get("attachment_links", Config.get([:instance, :attachment_links]))
|
|> Map.get("attachment_links", Config.get([:instance, :attachment_links]))
|
||||||
|> truthy_param?()
|
|> truthy_param?()
|
||||||
|
|
||||||
content_type = get_content_type(data[:content_type])
|
content_type = get_content_type(draft.params[:content_type])
|
||||||
|
|
||||||
options =
|
options =
|
||||||
if visibility == "direct" && Config.get([:instance, :safe_dm_mentions]) do
|
if draft.visibility == "direct" && Config.get([:instance, :safe_dm_mentions]) do
|
||||||
[safe_mention: true]
|
[safe_mention: true]
|
||||||
else
|
else
|
||||||
[]
|
[]
|
||||||
end
|
end
|
||||||
|
|
||||||
status
|
draft.status
|
||||||
|> format_input(content_type, options)
|
|> format_input(content_type, options)
|
||||||
|> maybe_add_attachments(attachments, attachment_links)
|
|> maybe_add_attachments(draft.attachments, attachment_links)
|
||||||
|> maybe_add_nsfw_tag(data)
|
|> maybe_add_nsfw_tag(draft.params)
|
||||||
end
|
end
|
||||||
|
|
||||||
defp get_content_type(content_type) do
|
defp get_content_type(content_type) do
|
||||||
|
@ -308,33 +299,21 @@ def format_input(text, "text/markdown", options) do
|
||||||
|> Formatter.html_escape("text/html")
|
|> Formatter.html_escape("text/html")
|
||||||
end
|
end
|
||||||
|
|
||||||
def make_note_data(
|
def make_note_data(%ActivityDraft{} = draft) do
|
||||||
actor,
|
|
||||||
to,
|
|
||||||
context,
|
|
||||||
content_html,
|
|
||||||
attachments,
|
|
||||||
in_reply_to,
|
|
||||||
tags,
|
|
||||||
summary \\ nil,
|
|
||||||
cc \\ [],
|
|
||||||
sensitive \\ false,
|
|
||||||
extra_params \\ %{}
|
|
||||||
) do
|
|
||||||
%{
|
%{
|
||||||
"type" => "Note",
|
"type" => "Note",
|
||||||
"to" => to,
|
"to" => draft.to,
|
||||||
"cc" => cc,
|
"cc" => draft.cc,
|
||||||
"content" => content_html,
|
"content" => draft.content_html,
|
||||||
"summary" => summary,
|
"summary" => draft.summary,
|
||||||
"sensitive" => truthy_param?(sensitive),
|
"sensitive" => draft.sensitive,
|
||||||
"context" => context,
|
"context" => draft.context,
|
||||||
"attachment" => attachments,
|
"attachment" => draft.attachments,
|
||||||
"actor" => actor,
|
"actor" => draft.user.ap_id,
|
||||||
"tag" => Keyword.values(tags) |> Enum.uniq()
|
"tag" => Keyword.values(draft.tags) |> Enum.uniq()
|
||||||
}
|
}
|
||||||
|> add_in_reply_to(in_reply_to)
|
|> add_in_reply_to(draft.in_reply_to)
|
||||||
|> Map.merge(extra_params)
|
|> Map.merge(draft.extra)
|
||||||
end
|
end
|
||||||
|
|
||||||
defp add_in_reply_to(object, nil), do: object
|
defp add_in_reply_to(object, nil), do: object
|
||||||
|
|
|
@ -213,6 +213,23 @@ test "it returns a json representation of the activity with accept application/j
|
||||||
end
|
end
|
||||||
|
|
||||||
describe "/objects/:uuid" do
|
describe "/objects/:uuid" do
|
||||||
|
test "it doesn't return a local-only object", %{conn: conn} do
|
||||||
|
user = insert(:user)
|
||||||
|
{:ok, post} = CommonAPI.post(user, %{status: "test", visibility: "local"})
|
||||||
|
|
||||||
|
assert Pleroma.Web.ActivityPub.Visibility.is_local_public?(post)
|
||||||
|
|
||||||
|
object = Object.normalize(post, false)
|
||||||
|
uuid = String.split(object.data["id"], "/") |> List.last()
|
||||||
|
|
||||||
|
conn =
|
||||||
|
conn
|
||||||
|
|> put_req_header("accept", "application/json")
|
||||||
|
|> get("/objects/#{uuid}")
|
||||||
|
|
||||||
|
assert json_response(conn, 404)
|
||||||
|
end
|
||||||
|
|
||||||
test "it returns a json representation of the object with accept application/json", %{
|
test "it returns a json representation of the object with accept application/json", %{
|
||||||
conn: conn
|
conn: conn
|
||||||
} do
|
} do
|
||||||
|
@ -326,6 +343,22 @@ test "cached purged after object deletion", %{conn: conn} do
|
||||||
end
|
end
|
||||||
|
|
||||||
describe "/activities/:uuid" do
|
describe "/activities/:uuid" do
|
||||||
|
test "it doesn't return a local-only activity", %{conn: conn} do
|
||||||
|
user = insert(:user)
|
||||||
|
{:ok, post} = CommonAPI.post(user, %{status: "test", visibility: "local"})
|
||||||
|
|
||||||
|
assert Pleroma.Web.ActivityPub.Visibility.is_local_public?(post)
|
||||||
|
|
||||||
|
uuid = String.split(post.data["id"], "/") |> List.last()
|
||||||
|
|
||||||
|
conn =
|
||||||
|
conn
|
||||||
|
|> put_req_header("accept", "application/json")
|
||||||
|
|> get("/activities/#{uuid}")
|
||||||
|
|
||||||
|
assert json_response(conn, 404)
|
||||||
|
end
|
||||||
|
|
||||||
test "it returns a json representation of the activity", %{conn: conn} do
|
test "it returns a json representation of the activity", %{conn: conn} do
|
||||||
activity = insert(:note_activity)
|
activity = insert(:note_activity)
|
||||||
uuid = String.split(activity.data["id"], "/") |> List.last()
|
uuid = String.split(activity.data["id"], "/") |> List.last()
|
||||||
|
|
|
@ -6,6 +6,7 @@ defmodule Pleroma.Web.CommonAPI.UtilsTest do
|
||||||
alias Pleroma.Builders.UserBuilder
|
alias Pleroma.Builders.UserBuilder
|
||||||
alias Pleroma.Object
|
alias Pleroma.Object
|
||||||
alias Pleroma.Web.CommonAPI
|
alias Pleroma.Web.CommonAPI
|
||||||
|
alias Pleroma.Web.CommonAPI.ActivityDraft
|
||||||
alias Pleroma.Web.CommonAPI.Utils
|
alias Pleroma.Web.CommonAPI.Utils
|
||||||
use Pleroma.DataCase
|
use Pleroma.DataCase
|
||||||
|
|
||||||
|
@ -235,9 +236,9 @@ test "when date is a random string" do
|
||||||
test "for public posts, not a reply" do
|
test "for public posts, not a reply" do
|
||||||
user = insert(:user)
|
user = insert(:user)
|
||||||
mentioned_user = insert(:user)
|
mentioned_user = insert(:user)
|
||||||
mentions = [mentioned_user.ap_id]
|
draft = %ActivityDraft{user: user, mentions: [mentioned_user.ap_id], visibility: "public"}
|
||||||
|
|
||||||
{to, cc} = Utils.get_to_and_cc(user, mentions, nil, "public", nil)
|
{to, cc} = Utils.get_to_and_cc(draft)
|
||||||
|
|
||||||
assert length(to) == 2
|
assert length(to) == 2
|
||||||
assert length(cc) == 1
|
assert length(cc) == 1
|
||||||
|
@ -252,9 +253,15 @@ test "for public posts, a reply" do
|
||||||
mentioned_user = insert(:user)
|
mentioned_user = insert(:user)
|
||||||
third_user = insert(:user)
|
third_user = insert(:user)
|
||||||
{:ok, activity} = CommonAPI.post(third_user, %{status: "uguu"})
|
{:ok, activity} = CommonAPI.post(third_user, %{status: "uguu"})
|
||||||
mentions = [mentioned_user.ap_id]
|
|
||||||
|
|
||||||
{to, cc} = Utils.get_to_and_cc(user, mentions, activity, "public", nil)
|
draft = %ActivityDraft{
|
||||||
|
user: user,
|
||||||
|
mentions: [mentioned_user.ap_id],
|
||||||
|
visibility: "public",
|
||||||
|
in_reply_to: activity
|
||||||
|
}
|
||||||
|
|
||||||
|
{to, cc} = Utils.get_to_and_cc(draft)
|
||||||
|
|
||||||
assert length(to) == 3
|
assert length(to) == 3
|
||||||
assert length(cc) == 1
|
assert length(cc) == 1
|
||||||
|
@ -268,9 +275,9 @@ test "for public posts, a reply" do
|
||||||
test "for unlisted posts, not a reply" do
|
test "for unlisted posts, not a reply" do
|
||||||
user = insert(:user)
|
user = insert(:user)
|
||||||
mentioned_user = insert(:user)
|
mentioned_user = insert(:user)
|
||||||
mentions = [mentioned_user.ap_id]
|
draft = %ActivityDraft{user: user, mentions: [mentioned_user.ap_id], visibility: "unlisted"}
|
||||||
|
|
||||||
{to, cc} = Utils.get_to_and_cc(user, mentions, nil, "unlisted", nil)
|
{to, cc} = Utils.get_to_and_cc(draft)
|
||||||
|
|
||||||
assert length(to) == 2
|
assert length(to) == 2
|
||||||
assert length(cc) == 1
|
assert length(cc) == 1
|
||||||
|
@ -285,9 +292,15 @@ test "for unlisted posts, a reply" do
|
||||||
mentioned_user = insert(:user)
|
mentioned_user = insert(:user)
|
||||||
third_user = insert(:user)
|
third_user = insert(:user)
|
||||||
{:ok, activity} = CommonAPI.post(third_user, %{status: "uguu"})
|
{:ok, activity} = CommonAPI.post(third_user, %{status: "uguu"})
|
||||||
mentions = [mentioned_user.ap_id]
|
|
||||||
|
|
||||||
{to, cc} = Utils.get_to_and_cc(user, mentions, activity, "unlisted", nil)
|
draft = %ActivityDraft{
|
||||||
|
user: user,
|
||||||
|
mentions: [mentioned_user.ap_id],
|
||||||
|
visibility: "unlisted",
|
||||||
|
in_reply_to: activity
|
||||||
|
}
|
||||||
|
|
||||||
|
{to, cc} = Utils.get_to_and_cc(draft)
|
||||||
|
|
||||||
assert length(to) == 3
|
assert length(to) == 3
|
||||||
assert length(cc) == 1
|
assert length(cc) == 1
|
||||||
|
@ -301,9 +314,9 @@ test "for unlisted posts, a reply" do
|
||||||
test "for private posts, not a reply" do
|
test "for private posts, not a reply" do
|
||||||
user = insert(:user)
|
user = insert(:user)
|
||||||
mentioned_user = insert(:user)
|
mentioned_user = insert(:user)
|
||||||
mentions = [mentioned_user.ap_id]
|
draft = %ActivityDraft{user: user, mentions: [mentioned_user.ap_id], visibility: "private"}
|
||||||
|
|
||||||
{to, cc} = Utils.get_to_and_cc(user, mentions, nil, "private", nil)
|
{to, cc} = Utils.get_to_and_cc(draft)
|
||||||
assert length(to) == 2
|
assert length(to) == 2
|
||||||
assert Enum.empty?(cc)
|
assert Enum.empty?(cc)
|
||||||
|
|
||||||
|
@ -316,9 +329,15 @@ test "for private posts, a reply" do
|
||||||
mentioned_user = insert(:user)
|
mentioned_user = insert(:user)
|
||||||
third_user = insert(:user)
|
third_user = insert(:user)
|
||||||
{:ok, activity} = CommonAPI.post(third_user, %{status: "uguu"})
|
{:ok, activity} = CommonAPI.post(third_user, %{status: "uguu"})
|
||||||
mentions = [mentioned_user.ap_id]
|
|
||||||
|
|
||||||
{to, cc} = Utils.get_to_and_cc(user, mentions, activity, "private", nil)
|
draft = %ActivityDraft{
|
||||||
|
user: user,
|
||||||
|
mentions: [mentioned_user.ap_id],
|
||||||
|
visibility: "private",
|
||||||
|
in_reply_to: activity
|
||||||
|
}
|
||||||
|
|
||||||
|
{to, cc} = Utils.get_to_and_cc(draft)
|
||||||
|
|
||||||
assert length(to) == 2
|
assert length(to) == 2
|
||||||
assert Enum.empty?(cc)
|
assert Enum.empty?(cc)
|
||||||
|
@ -330,9 +349,9 @@ test "for private posts, a reply" do
|
||||||
test "for direct posts, not a reply" do
|
test "for direct posts, not a reply" do
|
||||||
user = insert(:user)
|
user = insert(:user)
|
||||||
mentioned_user = insert(:user)
|
mentioned_user = insert(:user)
|
||||||
mentions = [mentioned_user.ap_id]
|
draft = %ActivityDraft{user: user, mentions: [mentioned_user.ap_id], visibility: "direct"}
|
||||||
|
|
||||||
{to, cc} = Utils.get_to_and_cc(user, mentions, nil, "direct", nil)
|
{to, cc} = Utils.get_to_and_cc(draft)
|
||||||
|
|
||||||
assert length(to) == 1
|
assert length(to) == 1
|
||||||
assert Enum.empty?(cc)
|
assert Enum.empty?(cc)
|
||||||
|
@ -345,9 +364,15 @@ test "for direct posts, a reply" do
|
||||||
mentioned_user = insert(:user)
|
mentioned_user = insert(:user)
|
||||||
third_user = insert(:user)
|
third_user = insert(:user)
|
||||||
{:ok, activity} = CommonAPI.post(third_user, %{status: "uguu"})
|
{:ok, activity} = CommonAPI.post(third_user, %{status: "uguu"})
|
||||||
mentions = [mentioned_user.ap_id]
|
|
||||||
|
|
||||||
{to, cc} = Utils.get_to_and_cc(user, mentions, activity, "direct", nil)
|
draft = %ActivityDraft{
|
||||||
|
user: user,
|
||||||
|
mentions: [mentioned_user.ap_id],
|
||||||
|
visibility: "direct",
|
||||||
|
in_reply_to: activity
|
||||||
|
}
|
||||||
|
|
||||||
|
{to, cc} = Utils.get_to_and_cc(draft)
|
||||||
|
|
||||||
assert length(to) == 1
|
assert length(to) == 1
|
||||||
assert Enum.empty?(cc)
|
assert Enum.empty?(cc)
|
||||||
|
@ -356,7 +381,14 @@ test "for direct posts, a reply" do
|
||||||
|
|
||||||
{:ok, direct_activity} = CommonAPI.post(third_user, %{status: "uguu", visibility: "direct"})
|
{:ok, direct_activity} = CommonAPI.post(third_user, %{status: "uguu", visibility: "direct"})
|
||||||
|
|
||||||
{to, cc} = Utils.get_to_and_cc(user, mentions, direct_activity, "direct", nil)
|
draft = %ActivityDraft{
|
||||||
|
user: user,
|
||||||
|
mentions: [mentioned_user.ap_id],
|
||||||
|
visibility: "direct",
|
||||||
|
in_reply_to: direct_activity
|
||||||
|
}
|
||||||
|
|
||||||
|
{to, cc} = Utils.get_to_and_cc(draft)
|
||||||
|
|
||||||
assert length(to) == 2
|
assert length(to) == 2
|
||||||
assert Enum.empty?(cc)
|
assert Enum.empty?(cc)
|
||||||
|
@ -532,26 +564,26 @@ test "returns original params when list not found" do
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
describe "make_note_data/11" do
|
describe "make_note_data/1" do
|
||||||
test "returns note data" do
|
test "returns note data" do
|
||||||
user = insert(:user)
|
user = insert(:user)
|
||||||
note = insert(:note)
|
note = insert(:note)
|
||||||
user2 = insert(:user)
|
user2 = insert(:user)
|
||||||
user3 = insert(:user)
|
user3 = insert(:user)
|
||||||
|
|
||||||
assert Utils.make_note_data(
|
draft = %ActivityDraft{
|
||||||
user.ap_id,
|
user: user,
|
||||||
[user2.ap_id],
|
to: [user2.ap_id],
|
||||||
"2hu",
|
context: "2hu",
|
||||||
"<h1>This is :moominmamma: note</h1>",
|
content_html: "<h1>This is :moominmamma: note</h1>",
|
||||||
[],
|
in_reply_to: note.id,
|
||||||
note.id,
|
tags: [name: "jimm"],
|
||||||
[name: "jimm"],
|
summary: "test summary",
|
||||||
"test summary",
|
cc: [user3.ap_id],
|
||||||
[user3.ap_id],
|
extra: %{"custom_tag" => "test"}
|
||||||
false,
|
}
|
||||||
%{"custom_tag" => "test"}
|
|
||||||
) == %{
|
assert Utils.make_note_data(draft) == %{
|
||||||
"actor" => user.ap_id,
|
"actor" => user.ap_id,
|
||||||
"attachment" => [],
|
"attachment" => [],
|
||||||
"cc" => [user3.ap_id],
|
"cc" => [user3.ap_id],
|
||||||
|
|
|
@ -1277,4 +1277,128 @@ test "fallback" do
|
||||||
} = CommonAPI.get_user("")
|
} = CommonAPI.get_user("")
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
describe "with `local` visibility" do
|
||||||
|
setup do: clear_config([:instance, :federating], true)
|
||||||
|
|
||||||
|
test "post" do
|
||||||
|
user = insert(:user)
|
||||||
|
|
||||||
|
with_mock Pleroma.Web.Federator, publish: fn _ -> :ok end do
|
||||||
|
{:ok, activity} = CommonAPI.post(user, %{status: "#2hu #2HU", visibility: "local"})
|
||||||
|
|
||||||
|
assert Visibility.is_local_public?(activity)
|
||||||
|
assert_not_called(Pleroma.Web.Federator.publish(activity))
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
test "delete" do
|
||||||
|
user = insert(:user)
|
||||||
|
|
||||||
|
{:ok, %Activity{id: activity_id}} =
|
||||||
|
CommonAPI.post(user, %{status: "#2hu #2HU", visibility: "local"})
|
||||||
|
|
||||||
|
with_mock Pleroma.Web.Federator, publish: fn _ -> :ok end do
|
||||||
|
assert {:ok, %Activity{data: %{"deleted_activity_id" => ^activity_id}} = activity} =
|
||||||
|
CommonAPI.delete(activity_id, user)
|
||||||
|
|
||||||
|
assert Visibility.is_local_public?(activity)
|
||||||
|
assert_not_called(Pleroma.Web.Federator.publish(activity))
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
test "repeat" do
|
||||||
|
user = insert(:user)
|
||||||
|
other_user = insert(:user)
|
||||||
|
|
||||||
|
{:ok, %Activity{id: activity_id}} =
|
||||||
|
CommonAPI.post(other_user, %{status: "cofe", visibility: "local"})
|
||||||
|
|
||||||
|
with_mock Pleroma.Web.Federator, publish: fn _ -> :ok end do
|
||||||
|
assert {:ok, %Activity{data: %{"type" => "Announce"}} = activity} =
|
||||||
|
CommonAPI.repeat(activity_id, user)
|
||||||
|
|
||||||
|
assert Visibility.is_local_public?(activity)
|
||||||
|
refute called(Pleroma.Web.Federator.publish(activity))
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
test "unrepeat" do
|
||||||
|
user = insert(:user)
|
||||||
|
other_user = insert(:user)
|
||||||
|
|
||||||
|
{:ok, %Activity{id: activity_id}} =
|
||||||
|
CommonAPI.post(other_user, %{status: "cofe", visibility: "local"})
|
||||||
|
|
||||||
|
assert {:ok, _} = CommonAPI.repeat(activity_id, user)
|
||||||
|
|
||||||
|
with_mock Pleroma.Web.Federator, publish: fn _ -> :ok end do
|
||||||
|
assert {:ok, %Activity{data: %{"type" => "Undo"}} = activity} =
|
||||||
|
CommonAPI.unrepeat(activity_id, user)
|
||||||
|
|
||||||
|
assert Visibility.is_local_public?(activity)
|
||||||
|
refute called(Pleroma.Web.Federator.publish(activity))
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
test "favorite" do
|
||||||
|
user = insert(:user)
|
||||||
|
other_user = insert(:user)
|
||||||
|
|
||||||
|
{:ok, activity} = CommonAPI.post(other_user, %{status: "cofe", visibility: "local"})
|
||||||
|
|
||||||
|
with_mock Pleroma.Web.Federator, publish: fn _ -> :ok end do
|
||||||
|
assert {:ok, %Activity{data: %{"type" => "Like"}} = activity} =
|
||||||
|
CommonAPI.favorite(user, activity.id)
|
||||||
|
|
||||||
|
assert Visibility.is_local_public?(activity)
|
||||||
|
refute called(Pleroma.Web.Federator.publish(activity))
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
test "unfavorite" do
|
||||||
|
user = insert(:user)
|
||||||
|
other_user = insert(:user)
|
||||||
|
|
||||||
|
{:ok, activity} = CommonAPI.post(other_user, %{status: "cofe", visibility: "local"})
|
||||||
|
|
||||||
|
{:ok, %Activity{}} = CommonAPI.favorite(user, activity.id)
|
||||||
|
|
||||||
|
with_mock Pleroma.Web.Federator, publish: fn _ -> :ok end do
|
||||||
|
assert {:ok, activity} = CommonAPI.unfavorite(activity.id, user)
|
||||||
|
assert Visibility.is_local_public?(activity)
|
||||||
|
refute called(Pleroma.Web.Federator.publish(activity))
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
test "react_with_emoji" do
|
||||||
|
user = insert(:user)
|
||||||
|
other_user = insert(:user)
|
||||||
|
{:ok, activity} = CommonAPI.post(other_user, %{status: "cofe", visibility: "local"})
|
||||||
|
|
||||||
|
with_mock Pleroma.Web.Federator, publish: fn _ -> :ok end do
|
||||||
|
assert {:ok, %Activity{data: %{"type" => "EmojiReact"}} = activity} =
|
||||||
|
CommonAPI.react_with_emoji(activity.id, user, "👍")
|
||||||
|
|
||||||
|
assert Visibility.is_local_public?(activity)
|
||||||
|
refute called(Pleroma.Web.Federator.publish(activity))
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
test "unreact_with_emoji" do
|
||||||
|
user = insert(:user)
|
||||||
|
other_user = insert(:user)
|
||||||
|
{:ok, activity} = CommonAPI.post(other_user, %{status: "cofe", visibility: "local"})
|
||||||
|
|
||||||
|
{:ok, _reaction} = CommonAPI.react_with_emoji(activity.id, user, "👍")
|
||||||
|
|
||||||
|
with_mock Pleroma.Web.Federator, publish: fn _ -> :ok end do
|
||||||
|
assert {:ok, %Activity{data: %{"type" => "Undo"}} = activity} =
|
||||||
|
CommonAPI.unreact_with_emoji(activity.id, user, "👍")
|
||||||
|
|
||||||
|
assert Visibility.is_local_public?(activity)
|
||||||
|
refute called(Pleroma.Web.Federator.publish(activity))
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
||||||
end
|
end
|
||||||
|
|
|
@ -1740,4 +1740,23 @@ test "expires_at is nil for another user" do
|
||||||
|> get("/api/v1/statuses/#{activity.id}")
|
|> get("/api/v1/statuses/#{activity.id}")
|
||||||
|> json_response_and_validate_schema(:ok)
|
|> json_response_and_validate_schema(:ok)
|
||||||
end
|
end
|
||||||
|
|
||||||
|
test "posting a local only status" do
|
||||||
|
%{user: _user, conn: conn} = oauth_access(["write:statuses"])
|
||||||
|
|
||||||
|
conn_one =
|
||||||
|
conn
|
||||||
|
|> put_req_header("content-type", "application/json")
|
||||||
|
|> post("/api/v1/statuses", %{
|
||||||
|
"status" => "cofe",
|
||||||
|
"visibility" => "local"
|
||||||
|
})
|
||||||
|
|
||||||
|
local = Pleroma.Constants.as_local_public()
|
||||||
|
|
||||||
|
assert %{"content" => "cofe", "id" => id, "visibility" => "local"} =
|
||||||
|
json_response(conn_one, 200)
|
||||||
|
|
||||||
|
assert %Activity{id: ^id, data: %{"to" => [^local]}} = Activity.get_by_id(id)
|
||||||
|
end
|
||||||
end
|
end
|
||||||
|
|
Loading…
Reference in New Issue