Merge branch 'autofollow' into 'develop'
Add a setting for users to autofollow on sign up. See merge request pleroma/pleroma!639
This commit is contained in:
commit
3aee8bb67b
@ -137,7 +137,8 @@
|
||||
"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
|
||||
|
@ -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
|
||||
|
@ -229,10 +229,27 @@ def register_changeset(struct, params \\ %{}, opts \\ []) 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
|
||||
|
@ -142,6 +142,23 @@ test "test if a user is following another user" 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()
|
||||
|
Loading…
Reference in New Issue
Block a user