forked from mirrors/akkoma
Remove user recommendation by third party engine
This commit is contained in:
parent
0b582d415b
commit
dabd535e43
|
@ -8,6 +8,7 @@ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/).
|
|||
- **Breaking**: Removed 1.0+ deprecated configurations `Pleroma.Upload, :strip_exif` and `:instance, :dedupe_media`
|
||||
- **Breaking**: OStatus protocol support
|
||||
- **Breaking**: MDII uploader
|
||||
- **Breaking**: Using third party engines for user recommendation
|
||||
|
||||
### Changed
|
||||
- **Breaking:** Pleroma won't start if it detects unapplied migrations
|
||||
|
|
|
@ -425,14 +425,6 @@
|
|||
],
|
||||
unfurl_nsfw: false
|
||||
|
||||
config :pleroma, :suggestions,
|
||||
enabled: false,
|
||||
third_party_engine:
|
||||
"http://vinayaka.distsn.org/cgi-bin/vinayaka-user-match-suggestions-api.cgi?{{host}}+{{user}}",
|
||||
timeout: 300_000,
|
||||
limit: 40,
|
||||
web: "https://vinayaka.distsn.org"
|
||||
|
||||
config :pleroma, :http_security,
|
||||
enabled: true,
|
||||
sts: false,
|
||||
|
|
|
@ -2748,43 +2748,6 @@
|
|||
}
|
||||
]
|
||||
},
|
||||
%{
|
||||
group: :pleroma,
|
||||
key: :suggestions,
|
||||
type: :group,
|
||||
children: [
|
||||
%{
|
||||
key: :enabled,
|
||||
type: :boolean,
|
||||
description: "Enables suggestions"
|
||||
},
|
||||
%{
|
||||
key: :third_party_engine,
|
||||
type: :string,
|
||||
description: "URL for third party engine",
|
||||
suggestions: [
|
||||
"http://vinayaka.distsn.org/cgi-bin/vinayaka-user-match-suggestions-api.cgi?{{host}}+{{user}}"
|
||||
]
|
||||
},
|
||||
%{
|
||||
key: :timeout,
|
||||
type: :integer,
|
||||
description: "Request timeout to third party engine",
|
||||
suggestions: [300_000]
|
||||
},
|
||||
%{
|
||||
key: :limit,
|
||||
type: :integer,
|
||||
description: "Limit for suggestions",
|
||||
suggestions: [40]
|
||||
},
|
||||
%{
|
||||
key: :web,
|
||||
type: :string,
|
||||
suggestions: ["https://vinayaka.distsn.org"]
|
||||
}
|
||||
]
|
||||
},
|
||||
%{
|
||||
group: :prometheus,
|
||||
key: Pleroma.Web.Endpoint.MetricsExporter,
|
||||
|
|
|
@ -1,31 +0,0 @@
|
|||
# How to activate user recommendation (Who to follow panel)
|
||||
![who-to-follow-panel-small](/uploads/9de1b1300436c32461d272945f1bc23e/who-to-follow-panel-small.png)
|
||||
|
||||
To show the *who to follow* panel, edit `config/prod.secret.exs` in the Pleroma backend. Following code activates the *who to follow* panel:
|
||||
|
||||
```elixir
|
||||
config :pleroma, :suggestions,
|
||||
enabled: true,
|
||||
third_party_engine:
|
||||
"http://vinayaka.distsn.org/cgi-bin/vinayaka-user-match-suggestions-api.cgi?{{host}}+{{user}}",
|
||||
timeout: 300_000,
|
||||
limit: 40,
|
||||
web: "https://vinayaka.distsn.org"
|
||||
|
||||
```
|
||||
|
||||
`config/config.exs` already includes this code, but `enabled:` is `false`.
|
||||
|
||||
`/api/v1/suggestions` is also provided when *who to follow* panel is enabled.
|
||||
|
||||
For advanced customization, following code shows the newcomers of the fediverse at the *who to follow* panel:
|
||||
|
||||
```elixir
|
||||
config :pleroma, :suggestions,
|
||||
enabled: true,
|
||||
third_party_engine:
|
||||
"http://vinayaka.distsn.org/cgi-bin/vinayaka-user-new-suggestions-api.cgi?{{host}}+{{user}}",
|
||||
timeout: 60_000,
|
||||
limit: 40,
|
||||
web: "https://vinayaka.distsn.org/user-new.html"
|
||||
```
|
|
@ -7,62 +7,8 @@ defmodule Pleroma.Web.MastodonAPI.SuggestionController do
|
|||
|
||||
require Logger
|
||||
|
||||
alias Pleroma.Config
|
||||
alias Pleroma.Plugs.OAuthScopesPlug
|
||||
alias Pleroma.User
|
||||
alias Pleroma.Web.MediaProxy
|
||||
|
||||
action_fallback(Pleroma.Web.MastodonAPI.FallbackController)
|
||||
|
||||
plug(OAuthScopesPlug, %{scopes: ["read"]} when action == :index)
|
||||
|
||||
plug(Pleroma.Plugs.EnsurePublicOrAuthenticatedPlug)
|
||||
|
||||
@doc "GET /api/v1/suggestions"
|
||||
def index(%{assigns: %{user: user}} = conn, _) do
|
||||
if Config.get([:suggestions, :enabled], false) do
|
||||
with {:ok, data} <- fetch_suggestions(user) do
|
||||
limit = Config.get([:suggestions, :limit], 23)
|
||||
|
||||
data =
|
||||
data
|
||||
|> Enum.slice(0, limit)
|
||||
|> Enum.map(fn x ->
|
||||
x
|
||||
|> Map.put("id", fetch_suggestion_id(x))
|
||||
|> Map.put("avatar", MediaProxy.url(x["avatar"]))
|
||||
|> Map.put("avatar_static", MediaProxy.url(x["avatar_static"]))
|
||||
end)
|
||||
|
||||
json(conn, data)
|
||||
end
|
||||
else
|
||||
json(conn, [])
|
||||
end
|
||||
end
|
||||
|
||||
defp fetch_suggestions(user) do
|
||||
api = Config.get([:suggestions, :third_party_engine], "")
|
||||
timeout = Config.get([:suggestions, :timeout], 5000)
|
||||
host = Config.get([Pleroma.Web.Endpoint, :url, :host])
|
||||
|
||||
url =
|
||||
api
|
||||
|> String.replace("{{host}}", host)
|
||||
|> String.replace("{{user}}", user.nickname)
|
||||
|
||||
with {:ok, %{status: 200, body: body}} <-
|
||||
Pleroma.HTTP.get(url, [], adapter: [recv_timeout: timeout, pool: :default]) do
|
||||
Jason.decode(body)
|
||||
else
|
||||
e -> Logger.error("Could not retrieve suggestions at fetch #{url}, #{inspect(e)}")
|
||||
end
|
||||
end
|
||||
|
||||
defp fetch_suggestion_id(attrs) do
|
||||
case User.get_or_fetch(attrs["acct"]) do
|
||||
{:ok, %User{id: id}} -> id
|
||||
_ -> 0
|
||||
end
|
||||
def index(conn, _) do
|
||||
json(conn, [])
|
||||
end
|
||||
end
|
||||
|
|
|
@ -69,9 +69,6 @@ def raw_nodeinfo do
|
|||
if Config.get([:chat, :enabled]) do
|
||||
"chat"
|
||||
end,
|
||||
if Config.get([:suggestions, :enabled]) do
|
||||
"suggestions"
|
||||
end,
|
||||
if Config.get([:instance, :allow_relay]) do
|
||||
"relay"
|
||||
end,
|
||||
|
@ -104,11 +101,7 @@ def raw_nodeinfo do
|
|||
nodeDescription: Config.get([:instance, :description]),
|
||||
private: !Config.get([:instance, :public], true),
|
||||
suggestions: %{
|
||||
enabled: Config.get([:suggestions, :enabled], false),
|
||||
thirdPartyEngine: Config.get([:suggestions, :third_party_engine], ""),
|
||||
timeout: Config.get([:suggestions, :timeout], 5000),
|
||||
limit: Config.get([:suggestions, :limit], 23),
|
||||
web: Config.get([:suggestions, :web], "")
|
||||
enabled: false
|
||||
},
|
||||
staffAccounts: staff_accounts,
|
||||
federation: federation_response,
|
||||
|
|
|
@ -36,11 +36,7 @@ defmodule Pleroma.Web.MastodonAPI.SuggestionControllerTest do
|
|||
[other_user: other_user]
|
||||
end
|
||||
|
||||
clear_config(:suggestions)
|
||||
|
||||
test "returns empty result when suggestions disabled", %{conn: conn} do
|
||||
Config.put([:suggestions, :enabled], false)
|
||||
|
||||
test "returns empty result", %{conn: conn} do
|
||||
res =
|
||||
conn
|
||||
|> get("/api/v1/suggestions")
|
||||
|
@ -48,43 +44,4 @@ test "returns empty result when suggestions disabled", %{conn: conn} do
|
|||
|
||||
assert res == []
|
||||
end
|
||||
|
||||
test "returns error", %{conn: conn} do
|
||||
Config.put([:suggestions, :enabled], true)
|
||||
Config.put([:suggestions, :third_party_engine], "http://test500?{{host}}&{{user}}")
|
||||
|
||||
assert capture_log(fn ->
|
||||
res =
|
||||
conn
|
||||
|> get("/api/v1/suggestions")
|
||||
|> json_response(500)
|
||||
|
||||
assert res == "Something went wrong"
|
||||
end) =~ "Could not retrieve suggestions"
|
||||
end
|
||||
|
||||
test "returns suggestions", %{conn: conn, other_user: other_user} do
|
||||
Config.put([:suggestions, :enabled], true)
|
||||
Config.put([:suggestions, :third_party_engine], "http://test200?{{host}}&{{user}}")
|
||||
|
||||
res =
|
||||
conn
|
||||
|> get("/api/v1/suggestions")
|
||||
|> json_response(200)
|
||||
|
||||
assert res == [
|
||||
%{
|
||||
"acct" => "yj455",
|
||||
"avatar" => "https://social.heldscal.la/avatar/201.jpeg",
|
||||
"avatar_static" => "https://social.heldscal.la/avatar/s/201.jpeg",
|
||||
"id" => 0
|
||||
},
|
||||
%{
|
||||
"acct" => other_user.ap_id,
|
||||
"avatar" => "https://social.heldscal.la/avatar/202.jpeg",
|
||||
"avatar_static" => "https://social.heldscal.la/avatar/s/202.jpeg",
|
||||
"id" => other_user.id
|
||||
}
|
||||
]
|
||||
end
|
||||
end
|
||||
|
|
Loading…
Reference in a new issue