projects
/
akkoma
/ blobdiff
commit
grep
author
committer
pickaxe
?
search:
re
summary
|
shortlog
|
log
|
commit
|
commitdiff
|
tree
raw
|
inline
| side by side
For existing users, just replace info.
[akkoma]
/
lib
/
pleroma
/
web
/
activity_pub
/
activity_pub.ex
diff --git
a/lib/pleroma/web/activity_pub/activity_pub.ex
b/lib/pleroma/web/activity_pub/activity_pub.ex
index 8f660a3340a0e0131249ec9d547294c5f7e2d682..4e46e80ea1128b4a2b15745be32ebdc7c678c374 100644
(file)
--- a/
lib/pleroma/web/activity_pub/activity_pub.ex
+++ b/
lib/pleroma/web/activity_pub/activity_pub.ex
@@
-84,7
+84,8
@@
defmodule Pleroma.Web.ActivityPub.ActivityPub do
end
def announce(%User{ap_id: _} = user, %Object{data: %{"id" => _}} = object, activity_id \\ nil, local \\ true) do
end
def announce(%User{ap_id: _} = user, %Object{data: %{"id" => _}} = object, activity_id \\ nil, local \\ true) do
- with announce_data <- make_announce_data(user, object, activity_id),
+ with true <- is_public?(object),
+ announce_data <- make_announce_data(user, object, activity_id),
{:ok, activity} <- insert(announce_data, local),
{:ok, object} <- add_announce_to_object(activity, object),
:ok <- maybe_federate(activity) do
{:ok, activity} <- insert(announce_data, local),
{:ok, object} <- add_announce_to_object(activity, object),
:ok <- maybe_federate(activity) do
@@
-128,12
+129,17
@@
defmodule Pleroma.Web.ActivityPub.ActivityPub do
end
def fetch_activities_for_context(context, opts \\ %{}) do
end
def fetch_activities_for_context(context, opts \\ %{}) do
- query = from activity in Activity,
- where: fragment("?->>'type' = ? and ?->>'context' = ?", activity.data, "Create", activity.data, ^context),
- order_by: [desc: :id]
+ public = ["https://www.w3.org/ns/activitystreams#Public"]
+ recipients = if opts["user"], do: [opts["user"].ap_id | opts["user"].following] ++ public, else: public
+
+ query = from activity in Activity
query = query
|> restrict_blocked(opts)
query = query
|> restrict_blocked(opts)
- |> restrict_recipients(["https://www.w3.org/ns/activitystreams#Public"], opts["user"])
+ |> restrict_recipients(recipients, opts["user"])
+
+ query = from activity in query,
+ where: fragment("?->>'type' = ? and ?->>'context' = ?", activity.data, "Create", activity.data, ^context),
+ order_by: [desc: :id]
Repo.all(query)
end
Repo.all(query)
end
@@
-267,6
+273,12
@@
defmodule Pleroma.Web.ActivityPub.ActivityPub do
}
User.insert_or_update_user(user_data)
}
User.insert_or_update_user(user_data)
+ if user = User.get_by_ap_id(ap_id) do
+ User.info_changeset(user, user_data}
+ |> Repo.update
+ else
+ User.insert_or_update_user(user_data)
+ end
end
end
end
end
@@
-277,22
+289,27
@@
defmodule Pleroma.Web.ActivityPub.ActivityPub do
end
def publish(actor, activity) do
end
def publish(actor, activity) do
- {:ok, followers} = User.get_followers(actor)
+ followers = if actor.follower_address in activity.recipients do
+ {:ok, followers} = User.get_followers(actor)
+ followers
+ else
+ []
+ end
- remote_inboxes =
Pleroma.Web.Salmon.remote_users(activity) ++ followers
+ remote_inboxes =
(Pleroma.Web.Salmon.remote_users(activity) ++ followers)
|> Enum.filter(fn (user) -> User.ap_enabled?(user) end)
|> Enum.map(fn (%{info: %{"source_data" => data}}) ->
|> Enum.filter(fn (user) -> User.ap_enabled?(user) end)
|> Enum.map(fn (%{info: %{"source_data" => data}}) ->
- (data["endpoints"] && data["endpoints"]["sharedInbox"]) ||data["inbox"]
+ (data["endpoints"] && data["endpoints"]["sharedInbox"]) ||
data["inbox"]
end)
|> Enum.uniq
{:ok, data} = Transmogrifier.prepare_outgoing(activity.data)
end)
|> Enum.uniq
{:ok, data} = Transmogrifier.prepare_outgoing(activity.data)
-
+ json = Poison.encode!(data)
Enum.each remote_inboxes, fn(inbox) ->
Logger.info("Federating #{activity.data["id"]} to #{inbox}")
host = URI.parse(inbox).host
Enum.each remote_inboxes, fn(inbox) ->
Logger.info("Federating #{activity.data["id"]} to #{inbox}")
host = URI.parse(inbox).host
- signature = Pleroma.Web.HTTPSignatures.sign(actor, %{host: host})
- @httpoison.post(inbox,
Poison.encode!(data)
, [{"Content-Type", "application/activity+json"}, {"signature", signature}])
+ signature = Pleroma.Web.HTTPSignatures.sign(actor, %{host: host
, "content-length": byte_size(json)
})
+ @httpoison.post(inbox,
json
, [{"Content-Type", "application/activity+json"}, {"signature", signature}])
end
end
end
end
@@
-316,9
+333,13
@@
defmodule Pleroma.Web.ActivityPub.ActivityPub do
end
end
end
end
- def
visible_for_user?(activity, nil
) do
+ def
is_public?(activity
) do
"https://www.w3.org/ns/activitystreams#Public" in (activity.data["to"] ++ (activity.data["cc"] || []))
end
"https://www.w3.org/ns/activitystreams#Public" in (activity.data["to"] ++ (activity.data["cc"] || []))
end
+
+ def visible_for_user?(activity, nil) do
+ is_public?(activity)
+ end
def visible_for_user?(activity, user) do
x = [user.ap_id | user.following]
y = (activity.data["to"] ++ (activity.data["cc"] || []))
def visible_for_user?(activity, user) do
x = [user.ap_id | user.following]
y = (activity.data["to"] ++ (activity.data["cc"] || []))