alias Pleroma.User
alias Pleroma.Web.ActivityPub.MRF
alias Pleroma.Web.ActivityPub.Transmogrifier
+ alias Pleroma.Web.ActivityPub.Utils
alias Pleroma.Web.Streamer
alias Pleroma.Web.WebFinger
alias Pleroma.Workers.BackgroundWorker
end
end
+ def listen(%{to: to, actor: actor, context: context, object: object} = params) do
+ additional = params[:additional] || %{}
+ # only accept false as false value
+ local = !(params[:local] == false)
+ published = params[:published]
+
+ with listen_data <-
+ make_listen_data(
+ %{to: to, actor: actor, published: published, context: context, object: object},
+ additional
+ ),
+ {:ok, activity} <- insert(listen_data, local),
+ :ok <- maybe_federate(activity) do
+ {:ok, activity}
+ else
+ {:error, message} ->
+ {:error, message}
+ end
+ end
+
def accept(%{to: to, actor: actor, object: object} = params) do
# only accept false as false value
local = !(params[:local] == false)
end
def update(%{to: to, cc: cc, actor: actor, object: object} = params) do
- # only accept false as false value
local = !(params[:local] == false)
+ activity_id = params[:activity_id]
with data <- %{
"to" => to,
"actor" => actor,
"object" => object
},
+ data <- Utils.maybe_put(data, "id", activity_id),
{:ok, activity} <- insert(data, local),
:ok <- maybe_federate(activity) do
{:ok, activity}
local \\ true,
public \\ true
) do
- with true <- is_public?(object),
+ with true <- is_announceable?(object, user, public),
announce_data <- make_announce_data(user, object, activity_id, public),
{:ok, activity} <- insert(announce_data, local),
{:ok, object} <- add_announce_to_object(activity, object),
end
end
- def delete(%Object{data: %{"id" => id, "actor" => actor}} = object, local \\ true) do
+ def delete(%Object{data: %{"id" => id, "actor" => actor}} = object, options \\ []) do
+ local = Keyword.get(options, :local, true)
+ activity_id = Keyword.get(options, :activity_id, nil)
+ actor = Keyword.get(options, :actor, actor)
+
user = User.get_cached_by_ap_id(actor)
to = (object.data["to"] || []) ++ (object.data["cc"] || [])
with {:ok, object, activity} <- Object.delete(object),
- data <- %{
- "type" => "Delete",
- "actor" => actor,
- "object" => id,
- "to" => to,
- "deleted_activity_id" => activity && activity.id
- },
+ data <-
+ %{
+ "type" => "Delete",
+ "actor" => actor,
+ "object" => id,
+ "to" => to,
+ "deleted_activity_id" => activity && activity.id
+ }
+ |> maybe_put("id", activity_id),
{:ok, activity} <- insert(data, local, false),
stream_out_participations(object, user),
_ <- decrease_replies_count_if_reply(object),
end
@spec fetch_latest_activity_id_for_context(String.t(), keyword() | map()) ::
- Pleroma.FlakeId.t() | nil
+ FlakeId.Ecto.CompatType.t() | nil
def fetch_latest_activity_id_for_context(context, opts \\ %{}) do
context
|> fetch_activities_for_context_query(Map.merge(%{"skip_preload" => true}, opts))
|> Repo.one()
end
- def fetch_public_activities(opts \\ %{}) do
+ def fetch_public_activities(opts \\ %{}, pagination \\ :keyset) do
opts = Map.drop(opts, ["user"])
[Pleroma.Constants.as_public()]
|> fetch_activities_query(opts)
|> restrict_unlisted()
- |> Pagination.fetch_paginated(opts)
+ |> Pagination.fetch_paginated(opts, pagination)
|> Enum.reverse()
end
defp restrict_thread_visibility(query, _, _), do: query
+ def fetch_user_abstract_activities(user, reading_user, params \\ %{}) do
+ params =
+ params
+ |> Map.put("user", reading_user)
+ |> Map.put("actor_id", user.ap_id)
+ |> Map.put("whole_db", true)
+
+ recipients =
+ user_activities_recipients(%{
+ "godmode" => params["godmode"],
+ "reading_user" => reading_user
+ })
+
+ fetch_activities(recipients, params)
+ |> Enum.reverse()
+ end
+
def fetch_user_activities(user, reading_user, params \\ %{}) do
params =
params
defp restrict_replies(query, %{"exclude_replies" => val}) when val == "true" or val == "1" do
from(
- activity in query,
- where: fragment("?->'object'->>'inReplyTo' is null", activity.data)
+ [_activity, object] in query,
+ where: fragment("?->>'inReplyTo' is null", object.data)
)
end
defp restrict_muted_reblogs(query, _), do: query
- defp exclude_poll_votes(query, %{"include_poll_votes" => "true"}), do: query
+ defp exclude_poll_votes(query, %{"include_poll_votes" => true}), do: query
defp exclude_poll_votes(query, _) do
if has_named_binding?(query, :object) do
|> exclude_poll_votes(opts)
end
- def fetch_activities(recipients, opts \\ %{}) do
+ def fetch_activities(recipients, opts \\ %{}, pagination \\ :keyset) do
list_memberships = Pleroma.List.memberships(opts["user"])
fetch_activities_query(recipients ++ list_memberships, opts)
- |> Pagination.fetch_paginated(opts)
+ |> Pagination.fetch_paginated(opts, pagination)
|> Enum.reverse()
|> maybe_update_cc(list_memberships, opts["user"])
end
)
end
- def fetch_activities_bounded(recipients, recipients_with_public, opts \\ %{}) do
+ def fetch_activities_bounded(
+ recipients,
+ recipients_with_public,
+ opts \\ %{},
+ pagination \\ :keyset
+ ) do
fetch_activities_query([], opts)
|> fetch_activities_bounded_query(recipients, recipients_with_public)
- |> Pagination.fetch_paginated(opts)
+ |> Pagination.fetch_paginated(opts, pagination)
|> Enum.reverse()
end
locked = data["manuallyApprovesFollowers"] || false
data = Transmogrifier.maybe_fix_user_object(data)
+ discoverable = data["discoverable"] || false
user_data = %{
ap_id: data["id"],
source_data: data,
banner: banner,
fields: fields,
- locked: locked
+ locked: locked,
+ discoverable: discoverable
},
avatar: avatar,
name: data["name"],