X-Git-Url: http://git.squeep.com/?a=blobdiff_plain;f=lib%2Fpleroma%2Fweb%2Factivity_pub%2Factivity_pub.ex;h=29055668bd327a04ef346fad85de1dd00fcfd8ec;hb=0f132b802dde7f217ecb07767e0d34e3edb517b7;hp=f3e55c79cdd777d5bf2aa3ea5b6d0b1092e5a309;hpb=ca2bd8b72b1c6d83938066520a4f63ba1d814fa4;p=akkoma diff --git a/lib/pleroma/web/activity_pub/activity_pub.ex b/lib/pleroma/web/activity_pub/activity_pub.ex index f3e55c79c..29055668b 100644 --- a/lib/pleroma/web/activity_pub/activity_pub.ex +++ b/lib/pleroma/web/activity_pub/activity_pub.ex @@ -3,6 +3,7 @@ # SPDX-License-Identifier: AGPL-3.0-only defmodule Pleroma.Web.ActivityPub.ActivityPub do + alias Akkoma.Collections alias Pleroma.Activity alias Pleroma.Activity.Ir.Topics alias Pleroma.Config @@ -81,6 +82,10 @@ defmodule Pleroma.Web.ActivityPub.ActivityPub do if is_public?(object), do: User.decrease_note_count(actor), else: {:ok, actor} end + def update_last_status_at_if_public(actor, object) do + if is_public?(object), do: User.update_last_status_at(actor), else: {:ok, actor} + end + defp increase_replies_count_if_reply(%{ "object" => %{"inReplyTo" => reply_ap_id} = object, "type" => "Create" @@ -92,7 +97,7 @@ defmodule Pleroma.Web.ActivityPub.ActivityPub do defp increase_replies_count_if_reply(_create_data), do: :noop - @object_types ~w[ChatMessage Question Answer Audio Video Event Article Note Page] + @object_types ~w[Question Answer Audio Video Event Article Note Page] @impl true def persist(%{"type" => type} = object, meta) when type in @object_types do with {:ok, object} <- Object.create(object) do @@ -136,6 +141,9 @@ defmodule Pleroma.Web.ActivityPub.ActivityPub do Task.start(fn -> Pleroma.Web.RichMedia.Helpers.fetch_data_for_activity(activity) end) end) + # Add local posts to search index + if local, do: Pleroma.Search.add_to_index(activity) + {:ok, activity} else %Activity{} = activity -> @@ -288,6 +296,7 @@ defmodule Pleroma.Web.ActivityPub.ActivityPub do _ <- increase_replies_count_if_reply(create_data), {:quick_insert, false, activity} <- {:quick_insert, quick_insert?, activity}, {:ok, _actor} <- increase_note_count_if_public(actor, activity), + {:ok, _actor} <- update_last_status_at_if_public(actor, activity), _ <- notify_and_stream(activity), :ok <- maybe_schedule_poll_notifications(activity), :ok <- maybe_federate(activity) do @@ -309,26 +318,6 @@ defmodule Pleroma.Web.ActivityPub.ActivityPub do :ok end - @spec listen(map()) :: {:ok, Activity.t()} | {:error, any()} - 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] - - listen_data = - make_listen_data( - %{to: to, actor: actor, published: published, context: context, object: object}, - additional - ) - - with {:ok, activity} <- insert(listen_data, local), - _ <- notify_and_stream(activity), - :ok <- maybe_federate(activity) do - {:ok, activity} - end - end - @spec unfollow(User.t(), User.t(), String.t() | nil, boolean()) :: {:ok, Activity.t()} | nil | {:error, any()} def unfollow(follower, followed, activity_id \\ nil, local \\ true) do @@ -408,7 +397,8 @@ defmodule Pleroma.Web.ActivityPub.ActivityPub do "type" => "Move", "actor" => origin.ap_id, "object" => origin.ap_id, - "target" => target.ap_id + "target" => target.ap_id, + "to" => [origin.follower_address] } with true <- origin.ap_id in target.also_known_as, @@ -494,15 +484,6 @@ defmodule Pleroma.Web.ActivityPub.ActivityPub do |> maybe_update_cc(list_memberships, opts[:user]) end - def fetch_activities_secret(recipients, opts \\ %{}, pagination \\ :keyset) do - list_memberships = Pleroma.List.memberships(opts[:user]) - - fetch_activities_query_secret(recipients ++ list_memberships, opts) - |> fetch_paginated_optimized(opts, pagination) - |> Enum.reverse() - end - - @spec fetch_public_or_unlisted_activities(map(), Pagination.type()) :: [Activity.t()] def fetch_public_or_unlisted_activities(opts \\ %{}, pagination \\ :keyset) do opts = Map.delete(opts, :user) @@ -1207,18 +1188,6 @@ defmodule Pleroma.Web.ActivityPub.ActivityPub do end end - defp exclude_chat_messages(query, %{include_chat_messages: true}), do: query - - defp exclude_chat_messages(query, _) do - if has_named_binding?(query, :object) do - from([activity, object: o] in query, - where: fragment("not(?->>'type' = ?)", o.data, "ChatMessage") - ) - else - query - end - end - defp exclude_invisible_actors(query, %{invisible_actors: true}), do: query defp exclude_invisible_actors(query, _opts) do @@ -1318,63 +1287,6 @@ defmodule Pleroma.Web.ActivityPub.ActivityPub do {restrict_blocked_opts, restrict_muted_opts, restrict_muted_reblogs_opts} end - def fetch_activities_query_secret(recipients, opts \\ %{}) do - opts = normalize_fetch_activities_query_opts(opts) - - {restrict_blocked_opts, restrict_muted_opts, restrict_muted_reblogs_opts} = - fetch_activities_query_ap_ids_ops(opts) - - config = %{ - skip_thread_containment: true - } - - query = - Activity - |> maybe_preload_objects(opts) - |> maybe_preload_bookmarks(opts) - |> maybe_preload_report_notes(opts) - |> maybe_set_thread_muted_field(opts) - |> maybe_order(opts) - |> restrict_recipients(recipients, opts[:user]) - |> restrict_replies(opts) - |> restrict_since(opts) - |> restrict_local(opts) - |> restrict_remote(opts) - |> restrict_actor(opts) - |> restrict_type(opts) - |> restrict_state(opts) - |> restrict_favorited_by(opts) - |> restrict_blocked(restrict_blocked_opts) - |> restrict_blockers_visibility(opts) - |> restrict_muted(restrict_muted_opts) - |> restrict_filtered(opts) - |> restrict_media(opts) - |> restrict_visibility(opts) - |> restrict_thread_visibility(opts, config) - |> restrict_reblogs(opts) - |> restrict_pinned(opts) - |> restrict_muted_reblogs(restrict_muted_reblogs_opts) - |> restrict_instance(opts) - |> restrict_announce_object_actor(opts) - |> restrict_filtered(opts) - |> exclude_poll_votes(opts) - |> exclude_chat_messages(opts) - |> exclude_invisible_actors(opts) - |> exclude_visibility(opts) - - if Config.feature_enabled?(:improved_hashtag_timeline) do - query - |> restrict_hashtag_any(opts) - |> restrict_hashtag_all(opts) - |> restrict_hashtag_reject_any(opts) - else - query - |> restrict_embedded_tag_any(opts) - |> restrict_embedded_tag_all(opts) - |> restrict_embedded_tag_reject_any(opts) - end - end - def fetch_activities_query(recipients, opts \\ %{}) do opts = normalize_fetch_activities_query_opts(opts) @@ -1382,7 +1294,7 @@ defmodule Pleroma.Web.ActivityPub.ActivityPub do fetch_activities_query_ap_ids_ops(opts) config = %{ - skip_thread_containment: true + skip_thread_containment: Config.get([:instance, :skip_thread_containment]) } query = @@ -1414,8 +1326,8 @@ defmodule Pleroma.Web.ActivityPub.ActivityPub do |> restrict_instance(opts) |> restrict_announce_object_actor(opts) |> restrict_filtered(opts) + |> Activity.restrict_deactivated_users() |> exclude_poll_votes(opts) - |> exclude_chat_messages(opts) |> exclude_invisible_actors(opts) |> exclude_visibility(opts) @@ -1537,8 +1449,6 @@ defmodule Pleroma.Web.ActivityPub.ActivityPub do end) is_locked = data["manuallyApprovesFollowers"] || false - capabilities = data["capabilities"] || %{} - accepts_chat_messages = capabilities["acceptsChatMessages"] data = Transmogrifier.maybe_fix_user_object(data) is_discoverable = data["discoverable"] || false invisible = data["invisible"] || false @@ -1582,7 +1492,6 @@ defmodule Pleroma.Web.ActivityPub.ActivityPub do public_key: public_key, inbox: data["inbox"], shared_inbox: shared_inbox, - accepts_chat_messages: accepts_chat_messages, pinned_objects: pinned_objects } @@ -1720,10 +1629,27 @@ defmodule Pleroma.Web.ActivityPub.ActivityPub do end def pin_data_from_featured_collection(%{ - "type" => type, - "orderedItems" => objects - }) + "type" => "OrderedCollection", + "first" => first + }) do + with {:ok, page} <- Fetcher.fetch_and_contain_remote_object_from_id(first) do + page + |> Map.get("orderedItems") + |> Map.new(fn %{"id" => object_ap_id} -> {object_ap_id, NaiveDateTime.utc_now()} end) + else + e -> + Logger.error("Could not decode featured collection at fetch #{first}, #{inspect(e)}") + {:ok, %{}} + end + end + + def pin_data_from_featured_collection( + %{ + "type" => type + } = collection + ) when type in ["OrderedCollection", "Collection"] do + {:ok, objects} = Collections.Fetcher.fetch_collection(collection) Map.new(objects, fn %{"id" => object_ap_id} -> {object_ap_id, NaiveDateTime.utc_now()} end) end