Commit 0d96384f authored by Alex Castaño's avatar Alex Castaño

Doc in activity pub finished

parent f8e672ea
Pipeline #33025415 failed with stages
in 3 minutes and 4 seconds
......@@ -256,12 +256,15 @@ defmodule Pleroma.Web.ActivityPub.Transmogrifier do
end
end
# A follow message was received by the server
def handle_incoming(
%{"type" => "Follow", "object" => followed, "actor" => follower, "id" => id} = data
) do
with %User{local: true} = followed <- User.get_cached_by_ap_id(followed),
%User{} = follower <- User.get_or_fetch_by_ap_id(follower),
{:ok, activity} <- ActivityPub.follow(follower, followed, id, false) do
# It accepts automatically if is not a "private" account.
# Mastodon stuff again
if not User.locked?(followed) do
ActivityPub.accept(%{
to: [follower.ap_id],
......@@ -305,6 +308,11 @@ defmodule Pleroma.Web.ActivityPub.Transmogrifier do
end
end
# An accept message was received by the server
# It assumes the accept is for a follow activity.
# However this has not to be the case in ActivityPub,
# you can accept more things in general.
# Fortunelly it makes some verification at least.
def handle_incoming(
%{"type" => "Accept", "object" => follow_object, "actor" => actor, "id" => id} = data
) do
......@@ -329,12 +337,17 @@ defmodule Pleroma.Web.ActivityPub.Transmogrifier do
end
end
# Again it assumes the reject is for a follow activity.
# And again it is doing some checks :)
def handle_incoming(
%{"type" => "Reject", "object" => follow_object, "actor" => actor, "id" => id} = data
) do
with %User{} = followed <- User.get_or_fetch_by_ap_id(actor),
{:ok, follow_activity} <- get_follow_activity(follow_object, followed),
%User{local: true} = follower <- User.get_cached_by_ap_id(follow_activity.data["actor"]),
# I don't understand why it creates an accept activity
# for a reject activity :S
# Probably a bug
{:ok, activity} <-
ActivityPub.accept(%{
to: follow_activity.data["to"],
......@@ -351,6 +364,7 @@ defmodule Pleroma.Web.ActivityPub.Transmogrifier do
end
end
# A like activity is received
def handle_incoming(
%{"type" => "Like", "object" => object_id, "actor" => actor, "id" => id} = _data
) do
......@@ -364,6 +378,7 @@ defmodule Pleroma.Web.ActivityPub.Transmogrifier do
end
end
# A retweet is received
def handle_incoming(
%{"type" => "Announce", "object" => object_id, "actor" => actor, "id" => id} = _data
) do
......@@ -377,6 +392,8 @@ defmodule Pleroma.Web.ActivityPub.Transmogrifier do
end
end
# An updated activity received by the server.
# Just for account profile
def handle_incoming(
%{"type" => "Update", "object" => %{"type" => object_type} = object, "actor" => actor_id} =
data
......@@ -764,6 +781,11 @@ defmodule Pleroma.Web.ActivityPub.Transmogrifier do
Repo.update_all(q, [])
end
# This updates an external user fetching it again from the external server
# IMPORTANT Because the followers are save in array this is really slow
# Or maybe it is changing the id... I don't know
# Exactly it seems like a mix task to fix something previous
# but it is also used in ActivityPub so it is really confusing!
def upgrade_user_from_ap_id(ap_id, async \\ true) do
with %User{local: false} = user <- User.get_by_ap_id(ap_id),
{:ok, data} <- ActivityPub.fetch_and_prepare_user_from_ap_id(ap_id) do
......
......@@ -174,6 +174,7 @@ defmodule Pleroma.Web.ActivityPub.Utils do
# could probably be taken from cache.
relevant_activities = Activity.all_by_object_ap_id(id)
# IMPORTANT: This is really slow!!
Enum.map(relevant_activities, fn activity ->
new_activity_data = activity.data |> Map.put("object", object.data)
changeset = Changeset.change(activity, data: new_activity_data)
......@@ -187,6 +188,7 @@ defmodule Pleroma.Web.ActivityPub.Utils do
Returns an existing like if a user already liked an object
"""
def get_existing_like(actor, %{data: %{"id" => id}}) do
# Does it perform ok? It has the needed indexes?
query =
from(
activity in Activity,
......@@ -235,6 +237,8 @@ defmodule Pleroma.Web.ActivityPub.Utils do
end
def add_like_to_object(%Activity{data: %{"actor" => actor}}, object) do
# likes array is slow for a lot of likes
# should be a table itself
likes = if is_list(object.data["likes"]), do: object.data["likes"], else: []
with likes <- [actor | likes] |> Enum.uniq() do
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment