forked from AkkomaGang/akkoma
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 @@ def get_friends(user) do
|
|||
{:ok, Repo.all(q)}
|
||||
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
|
||||
note_count = (user.info["note_count"] || 0) + 1
|
||||
new_info = Map.put(user.info, "note_count", note_count)
|
||||
|
|
|
@ -219,7 +219,7 @@ def remove_like_from_object(%Activity{data: %{"actor" => actor}}, object) do
|
|||
@doc """
|
||||
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 = %{
|
||||
"type" => "Follow",
|
||||
"actor" => follower_id,
|
||||
|
@ -229,6 +229,7 @@ def make_follow_data(%User{ap_id: follower_id}, %User{ap_id: followed_id}, activ
|
|||
}
|
||||
|
||||
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
|
||||
|
||||
def fetch_latest_follow(%User{ap_id: follower_id}, %User{ap_id: followed_id}) do
|
||||
|
|
|
@ -476,6 +476,12 @@ def following(conn, %{"id" => id}) do
|
|||
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
|
||||
with %User{} = followed <- Repo.get(User, id),
|
||||
{:ok, follower} <- User.maybe_direct_follow(follower, followed),
|
||||
|
|
|
@ -97,11 +97,13 @@ def user_fetcher(username) do
|
|||
post("/accounts/:id/mute", MastodonAPIController, :relationship_noop)
|
||||
post("/accounts/:id/unmute", MastodonAPIController, :relationship_noop)
|
||||
|
||||
get("/follow_requests", MastodonAPIController, :follow_requests)
|
||||
|
||||
post("/follows", MastodonAPIController, :follow)
|
||||
|
||||
get("/blocks", MastodonAPIController, :blocks)
|
||||
|
||||
get("/follow_requests", MastodonAPIController, :empty_array)
|
||||
get("/domain_blocks", MastodonAPIController, :empty_array)
|
||||
get("/mutes", MastodonAPIController, :empty_array)
|
||||
|
||||
get("/timelines/home", MastodonAPIController, :home_timeline)
|
||||
|
|
Loading…
Reference in a new issue