Add logic for keeping follow_request_count up-to-date on the follow,

`approve_friend_request`, and `deny_friend_request` actions.
Add follow_request_count to the user view.
This commit is contained in:
eugenijm 2019-02-10 02:26:29 +03:00
commit ecdf0657ba
9 changed files with 91 additions and 18 deletions

View file

@ -570,7 +570,7 @@ defmodule Pleroma.Web.TwitterAPI.Controller do
{:ok, _activity} <-
ActivityPub.accept(%{
to: [follower.ap_id],
actor: followed.ap_id,
actor: followed,
object: follow_activity.data["id"],
type: "Accept"
}) do
@ -590,7 +590,7 @@ defmodule Pleroma.Web.TwitterAPI.Controller do
{:ok, _activity} <-
ActivityPub.reject(%{
to: [follower.ap_id],
actor: followed.ap_id,
actor: followed,
object: follow_activity.data["id"],
type: "Reject"
}) do

View file

@ -113,10 +113,12 @@ defmodule Pleroma.Web.TwitterAPI.UserView do
"fields" => fields,
# Pleroma extension
"pleroma" => %{
"confirmation_pending" => user_info.confirmation_pending,
"tags" => user.tags
}
"pleroma" =>
%{
"confirmation_pending" => user_info.confirmation_pending,
"tags" => user.tags
}
|> maybe_with_follow_request_count(user, for_user)
}
data =
@ -132,6 +134,14 @@ defmodule Pleroma.Web.TwitterAPI.UserView do
end
end
defp maybe_with_follow_request_count(data, %User{id: id, info: %{locked: true}} = user, %User{
id: id
}) do
Map.put(data, "follow_request_count", user.info.follow_request_count)
end
defp maybe_with_follow_request_count(data, _, _), do: data
defp maybe_with_role(data, %User{id: id} = user, %User{id: id}) do
Map.merge(data, %{"role" => role(user), "show_role" => user.info.show_role})
end