implement tracking of follow requests
This commit is contained in:
parent
6041380774
commit
9c88933422
4 changed files with 41 additions and 2 deletions
|
@ -353,6 +353,36 @@ defmodule Pleroma.User do
|
||||||
{:ok, Repo.all(q)}
|
{:ok, Repo.all(q)}
|
||||||
end
|
end
|
||||||
|
|
||||||
|
def get_follow_requests_query(%User{} = user) do
|
||||||
|
from(
|
||||||
|
a in Activity,
|
||||||
|
where: fragment(
|
||||||
|
"? ->> 'type' = 'Follow'",
|
||||||
|
a.data
|
||||||
|
),
|
||||||
|
where: fragment(
|
||||||
|
"? ->> 'state' = 'pending'",
|
||||||
|
a.data
|
||||||
|
),
|
||||||
|
where: fragment(
|
||||||
|
"? @> ?",
|
||||||
|
a.data,
|
||||||
|
^%{"object" => user.ap_id}
|
||||||
|
)
|
||||||
|
)
|
||||||
|
end
|
||||||
|
|
||||||
|
def get_follow_requests(%User{} = user) do
|
||||||
|
q = get_follow_requests_query(user)
|
||||||
|
reqs = Repo.all(q)
|
||||||
|
|
||||||
|
users =
|
||||||
|
Enum.map(reqs, fn (req) -> req.actor end)
|
||||||
|
|> Enum.map(fn (ap_id) -> get_by_ap_id(ap_id) end)
|
||||||
|
|
||||||
|
{:ok, users}
|
||||||
|
end
|
||||||
|
|
||||||
def increase_note_count(%User{} = user) do
|
def increase_note_count(%User{} = user) do
|
||||||
note_count = (user.info["note_count"] || 0) + 1
|
note_count = (user.info["note_count"] || 0) + 1
|
||||||
new_info = Map.put(user.info, "note_count", note_count)
|
new_info = Map.put(user.info, "note_count", note_count)
|
||||||
|
|
|
@ -219,7 +219,7 @@ defmodule Pleroma.Web.ActivityPub.Utils do
|
||||||
@doc """
|
@doc """
|
||||||
Makes a follow activity data for the given follower and followed
|
Makes a follow activity data for the given follower and followed
|
||||||
"""
|
"""
|
||||||
def make_follow_data(%User{ap_id: follower_id}, %User{ap_id: followed_id}, activity_id) do
|
def make_follow_data(%User{ap_id: follower_id}, %User{ap_id: followed_id} = followed, activity_id) do
|
||||||
data = %{
|
data = %{
|
||||||
"type" => "Follow",
|
"type" => "Follow",
|
||||||
"actor" => follower_id,
|
"actor" => follower_id,
|
||||||
|
@ -229,6 +229,7 @@ defmodule Pleroma.Web.ActivityPub.Utils do
|
||||||
}
|
}
|
||||||
|
|
||||||
if activity_id, do: Map.put(data, "id", activity_id), else: data
|
if activity_id, do: Map.put(data, "id", activity_id), else: data
|
||||||
|
if User.locked?(followed), do: Map.put(data, "state", "pending"), else: data
|
||||||
end
|
end
|
||||||
|
|
||||||
def fetch_latest_follow(%User{ap_id: follower_id}, %User{ap_id: followed_id}) do
|
def fetch_latest_follow(%User{ap_id: follower_id}, %User{ap_id: followed_id}) do
|
||||||
|
|
|
@ -476,6 +476,12 @@ defmodule Pleroma.Web.MastodonAPI.MastodonAPIController do
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
def follow_requests(%{assigns: %{user: followed}} = conn, _params) do
|
||||||
|
with {:ok, follow_requests} <- User.get_follow_requests(followed) do
|
||||||
|
render(conn, AccountView, "accounts.json", %{users: follow_requests, as: :user})
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
def follow(%{assigns: %{user: follower}} = conn, %{"id" => id}) do
|
def follow(%{assigns: %{user: follower}} = conn, %{"id" => id}) do
|
||||||
with %User{} = followed <- Repo.get(User, id),
|
with %User{} = followed <- Repo.get(User, id),
|
||||||
{:ok, follower} <- User.maybe_direct_follow(follower, followed),
|
{:ok, follower} <- User.maybe_direct_follow(follower, followed),
|
||||||
|
|
|
@ -97,11 +97,13 @@ defmodule Pleroma.Web.Router do
|
||||||
post("/accounts/:id/mute", MastodonAPIController, :relationship_noop)
|
post("/accounts/:id/mute", MastodonAPIController, :relationship_noop)
|
||||||
post("/accounts/:id/unmute", MastodonAPIController, :relationship_noop)
|
post("/accounts/:id/unmute", MastodonAPIController, :relationship_noop)
|
||||||
|
|
||||||
|
get("/follow_requests", MastodonAPIController, :follow_requests)
|
||||||
|
|
||||||
post("/follows", MastodonAPIController, :follow)
|
post("/follows", MastodonAPIController, :follow)
|
||||||
|
|
||||||
get("/blocks", MastodonAPIController, :blocks)
|
get("/blocks", MastodonAPIController, :blocks)
|
||||||
|
|
||||||
get("/follow_requests", MastodonAPIController, :empty_array)
|
get("/domain_blocks", MastodonAPIController, :empty_array)
|
||||||
get("/mutes", MastodonAPIController, :empty_array)
|
get("/mutes", MastodonAPIController, :empty_array)
|
||||||
|
|
||||||
get("/timelines/home", MastodonAPIController, :home_timeline)
|
get("/timelines/home", MastodonAPIController, :home_timeline)
|
||||||
|
|
Loading…
Reference in a new issue