Add a setting for users to autofollow on sign up.
authorlain <lain@soykaf.club>
Tue, 8 Jan 2019 08:55:33 +0000 (09:55 +0100)
committerlain <lain@soykaf.club>
Tue, 8 Jan 2019 08:57:53 +0000 (09:57 +0100)
config/config.exs
docs/config.md
lib/pleroma/user.ex
test/user_test.exs

index e084d1a883a69afb295689aed489afc4870d63a9..4f4e2368a4970749910c7910a2516b2c6250b760 100644 (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
index e3b2fb35cf82f09938cd7486d405df87f9ebf32a..1a9706f5b8fe1dbddfca60b15fe7a74b300d42d0 100644 (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
index 85d0f9fce297d8ba6b97c35d3cf7c93615a16b4e..8edf1c73065979dc5fc075ed5e3875715d8e12ff 100644 (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
index 74accb7c8a99ecd8458ea9350c62c2f994131090..f8ef2b1dc30a21dadaebded55c6e960374c155bd 100644 (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()