follow works on pleroma now
This commit is contained in:
parent
60456cc0ba
commit
fcbd2e9472
|
@ -11,10 +11,15 @@ defmodule Vonbraun.ActivityPub.Handler.Follow do
|
||||||
def type, do: @verb
|
def type, do: @verb
|
||||||
|
|
||||||
def handle(
|
def handle(
|
||||||
%{"type" => @verb, "actor" => follow_requester_id, "object" => follow_target},
|
%{
|
||||||
|
"id" => activity_id,
|
||||||
|
"type" => @verb,
|
||||||
|
"actor" => follow_requester_id,
|
||||||
|
"object" => follow_target
|
||||||
|
},
|
||||||
actor = %{}
|
actor = %{}
|
||||||
)
|
)
|
||||||
when is_binary(follow_requester_id) and is_binary(follow_target) do
|
when is_binary(follow_requester_id) and is_binary(follow_target) and is_binary(activity_id) do
|
||||||
with {:valid_target, true} <- {:valid_target, Object.my_id() == follow_target},
|
with {:valid_target, true} <- {:valid_target, Object.my_id() == follow_target},
|
||||||
{:add, {:ok, %Actor{:blocked => nil, :follows_me_state => follows_me_state}}}
|
{:add, {:ok, %Actor{:blocked => nil, :follows_me_state => follows_me_state}}}
|
||||||
when not is_nil(follows_me_state) <-
|
when not is_nil(follows_me_state) <-
|
||||||
|
@ -33,7 +38,8 @@ defmodule Vonbraun.ActivityPub.Handler.Follow do
|
||||||
|
|
||||||
if activity_type do
|
if activity_type do
|
||||||
payload =
|
payload =
|
||||||
Object.accept_follow_activity(follow_requester_id, activity_type) |> Jason.encode!()
|
Object.accept_follow_activity(follow_requester_id, activity_id, activity_type)
|
||||||
|
|> Jason.encode!()
|
||||||
|
|
||||||
Logger.debug("Replying to follow request with: #{activity_type}")
|
Logger.debug("Replying to follow request with: #{activity_type}")
|
||||||
Logger.debug("And payload: `#{payload}`")
|
Logger.debug("And payload: `#{payload}`")
|
||||||
|
|
|
@ -56,8 +56,8 @@ defmodule Vonbraun.ActivityPub.Object do
|
||||||
def follow_activity(to_follow_id) when is_binary(to_follow_id),
|
def follow_activity(to_follow_id) when is_binary(to_follow_id),
|
||||||
do: activity("Follow", my_follow_activity_id(to_follow_id), to_follow_id, to: to_follow_id)
|
do: activity("Follow", my_follow_activity_id(to_follow_id), to_follow_id, to: to_follow_id)
|
||||||
|
|
||||||
def accept_follow_activity(followee_id, type \\ :accept)
|
def accept_follow_activity(followee_id, activity_id, type \\ :accept)
|
||||||
when is_binary(followee_id) and type in [:accept, :reject] do
|
when is_binary(followee_id) and is_binary(activity_id) and type in [:accept, :reject] do
|
||||||
activity_type =
|
activity_type =
|
||||||
if type == :accept do
|
if type == :accept do
|
||||||
"Accept"
|
"Accept"
|
||||||
|
@ -66,6 +66,7 @@ defmodule Vonbraun.ActivityPub.Object do
|
||||||
end
|
end
|
||||||
|
|
||||||
object = %{
|
object = %{
|
||||||
|
"id" => activity_id,
|
||||||
"type" => "Follow",
|
"type" => "Follow",
|
||||||
"actor" => followee_id
|
"actor" => followee_id
|
||||||
}
|
}
|
||||||
|
|
|
@ -28,7 +28,8 @@ defmodule Vonbraun.ActivityPubReq do
|
||||||
when is_binary(body) do
|
when is_binary(body) do
|
||||||
headers = %{
|
headers = %{
|
||||||
"host" => host,
|
"host" => host,
|
||||||
"accept" => "application/ld+json; profile=\"https://www.w3.org/ns/activitystreams\""
|
"accept" => "application/ld+json; profile=\"https://www.w3.org/ns/activitystreams\"",
|
||||||
|
"content-type" => "application/activity+json"
|
||||||
}
|
}
|
||||||
|
|
||||||
target =
|
target =
|
||||||
|
|
|
@ -15,7 +15,8 @@ defmodule Vonbraun.Ecto.Schema.Pair do
|
||||||
|> Changeset.cast(params, [:value])
|
|> Changeset.cast(params, [:value])
|
||||||
end
|
end
|
||||||
|
|
||||||
def set(key, value) do
|
@spec set(String.t(), String.t()) :: {:ok, String.t() | nil} | {:error, any()}
|
||||||
|
def set(key, value) when is_binary(key) and (is_binary(value) or is_nil(value)) do
|
||||||
case Repo.get(__MODULE__, key) do
|
case Repo.get(__MODULE__, key) do
|
||||||
nil ->
|
nil ->
|
||||||
changeset(%__MODULE__{key: key}, %{value: value})
|
changeset(%__MODULE__{key: key}, %{value: value})
|
||||||
|
@ -27,7 +28,17 @@ defmodule Vonbraun.Ecto.Schema.Pair do
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
def get(key) do
|
@spec get(String.t()) :: String.t() | nil
|
||||||
Repo.get(__MODULE__, key)
|
def get(key) when is_binary(key) do
|
||||||
|
case Repo.get(__MODULE__, key) do
|
||||||
|
%__MODULE__{:value => value} -> value
|
||||||
|
_ -> nil
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
@spec delete(String.t()) :: any()
|
||||||
|
def delete(key) when is_binary(key) do
|
||||||
|
Repo.delete(%__MODULE__{key: key})
|
||||||
|
:ok
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
|
@ -220,7 +220,7 @@ defmodule Vonbraun.MyRouter do
|
||||||
nil ->
|
nil ->
|
||||||
send_resp(conn, 404, "fuck off")
|
send_resp(conn, 404, "fuck off")
|
||||||
|
|
||||||
%{:value => value} ->
|
value ->
|
||||||
send_resp(conn, 200, value)
|
send_resp(conn, 200, value)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
Loading…
Reference in New Issue