Add a setting for users to autofollow on sign up.

This commit is contained in:
lain 2019-01-08 09:55:33 +01:00
parent 4e5b156047
commit 0fae04c4e3
4 changed files with 38 additions and 2 deletions

View File

@ -137,7 +137,8 @@ config :pleroma, :instance,
"text/markdown"
],
finmoji_enabled: true,
mrf_transparency: true
mrf_transparency: true,
autofollowed_nicknames: []
config :pleroma, :markup,
# XXX - unfortunately, inline images must be enabled by default right now, because

View File

@ -93,6 +93,7 @@ config :pleroma, Pleroma.Mailer,
* `always_show_subject_input`: When set to false, auto-hide the subject field when it's empty.
* `extended_nickname_format`: Set to `true` to use extended local nicknames format (allows underscores/dashes). This will break federation with
older software for theses nicknames.
* `autofollowed_nicknames`: Set to nicknames of (local) users that every new user should automatically follow.
## :logger
* `backends`: `:console` is used to send logs to stdout, `{ExSyslogger, :ex_syslogger}` to log to syslog

View File

@ -229,10 +229,27 @@ defmodule Pleroma.User do
end
end
defp autofollow_users(user) do
candidates = Pleroma.Config.get([:instance, :autofollowed_nicknames])
autofollowed_users =
from(u in User,
where: u.local == true,
where: u.nickname in ^candidates
)
|> Repo.all()
autofollowed_users
|> Enum.reduce({:ok, user}, fn other_user, {:ok, user} ->
follow(user, other_user)
end)
end
@doc "Inserts provided changeset, performs post-registration actions (confirmation email sending etc.)"
def register(%Ecto.Changeset{} = changeset) do
with {:ok, user} <- Repo.insert(changeset),
{:ok, _} = try_send_confirmation_email(user) do
{:ok, _} <- try_send_confirmation_email(user),
{:ok, user} <- autofollow_users(user) do
{:ok, user}
end
end

View File

@ -142,6 +142,23 @@ defmodule Pleroma.UserTest do
email: "email@example.com"
}
test "it autofollows accounts that are set for it" do
user = insert(:user)
remote_user = insert(:user, %{local: false})
Pleroma.Config.put([:instance, :autofollowed_nicknames], [
user.nickname,
remote_user.nickname
])
cng = User.register_changeset(%User{}, @full_user_data)
{:ok, registered_user} = User.register(cng)
assert User.following?(registered_user, user)
refute User.following?(registered_user, remote_user)
end
test "it requires an email, name, nickname and password, bio is optional" do
@full_user_data
|> Map.keys()