field(:also_known_as, {:array, ObjectValidators.ObjectID}, default: [])
field(:inbox, :string)
field(:shared_inbox, :string)
- field(:accepts_chat_messages, :boolean, default: nil)
field(:last_active_at, :naive_datetime)
field(:disclose_client, :boolean, default: true)
field(:pinned_objects, :map, default: %{})
has_many(incoming_relation_source, through: [incoming_relation, :source])
end
- # `:blocks` is deprecated (replaced with `blocked_users` relation)
- field(:blocks, {:array, :string}, default: [])
- # `:mutes` is deprecated (replaced with `muted_users` relation)
- field(:mutes, {:array, :string}, default: [])
- # `:muted_reblogs` is deprecated (replaced with `reblog_muted_users` relation)
- field(:muted_reblogs, {:array, :string}, default: [])
- # `:muted_notifications` is deprecated (replaced with `notification_muted_users` relation)
- field(:muted_notifications, {:array, :string}, default: [])
- # `:subscribers` is deprecated (replaced with `subscriber_users` relation)
- field(:subscribers, {:array, :string}, default: [])
-
embeds_one(
:multi_factor_authentication_settings,
MFA.Settings,
:invisible,
:actor_type,
:also_known_as,
- :accepts_chat_messages,
:pinned_objects
]
)
:pleroma_settings_store,
:is_discoverable,
:actor_type,
- :accepts_chat_messages,
:disclose_client
]
)
# Used to auto-register LDAP accounts which won't have a password hash stored locally
def register_changeset_ldap(struct, params = %{password: password})
when is_nil(password) do
- params = Map.put_new(params, :accepts_chat_messages, true)
-
params =
if Map.has_key?(params, :email) do
Map.put_new(params, :email, params[:email])
|> cast(params, [
:name,
:nickname,
- :email,
- :accepts_chat_messages
+ :email
])
|> validate_required([:name, :nickname])
|> unique_constraint(:nickname)
|> validate_exclusion(:nickname, Config.get([User, :restricted_nicknames]))
|> validate_format(:nickname, local_nickname_regex())
|> put_ap_id()
+ |> put_keys()
|> unique_constraint(:ap_id)
|> put_following_and_follower_and_featured_address()
end
bio_limit = Config.get([:instance, :user_bio_length], 5000)
name_limit = Config.get([:instance, :user_name_length], 100)
reason_limit = Config.get([:instance, :registration_reason_length], 500)
- params = Map.put_new(params, :accepts_chat_messages, true)
confirmed? =
if is_nil(opts[:confirmed]) do
:password,
:password_confirmation,
:emoji,
- :accepts_chat_messages,
:registration_reason,
:language
])
|> validate_length(:registration_reason, max: reason_limit)
|> maybe_validate_required_email(opts[:external])
|> put_password_hash
+ |> put_keys()
|> put_ap_id()
|> unique_constraint(:ap_id)
|> put_following_and_follower_and_featured_address()
end
end
- defp put_ap_id(changeset) do
+ def put_keys(changeset) do
+ {:ok, pem} = Keys.generate_rsa_pem()
+ put_change(changeset, :keys, pem)
+ end
+
+ def put_ap_id(changeset) do
ap_id = ap_id(%User{nickname: get_field(changeset, :nickname)})
put_change(changeset, :ap_id, ap_id)
end
- defp put_following_and_follower_and_featured_address(changeset) do
+ def put_following_and_follower_and_featured_address(changeset) do
user = %User{nickname: get_field(changeset, :nickname)}
followers = ap_followers(user)
following = ap_following(user)
{:ok, user} <- set_cache(user),
{:ok, _} <- maybe_send_registration_email(user),
{:ok, _} <- maybe_send_welcome_email(user),
- {:ok, _} <- maybe_send_welcome_message(user),
- {:ok, _} <- maybe_send_welcome_chat_message(user) do
+ {:ok, _} <- maybe_send_welcome_message(user) do
{:ok, user}
end
end
end
end
- defp maybe_send_welcome_chat_message(user) do
- if User.WelcomeChatMessage.enabled?() do
- User.WelcomeChatMessage.post_message(user)
- {:ok, :enqueued}
- else
- {:ok, :noop}
- end
- end
-
defp maybe_send_welcome_email(%User{email: email} = user) when is_binary(email) do
if User.WelcomeEmail.enabled?() do
User.WelcomeEmail.send_email(user)
blocker
end
- # clear any requested follows as well
+ # clear any requested follows from both sides as well
blocked =
case CommonAPI.reject_follow_request(blocked, blocker) do
{:ok, %User{} = updated_blocked} -> updated_blocked
nil -> blocked
end
+ blocker =
+ case CommonAPI.reject_follow_request(blocker, blocked) do
+ {:ok, %User{} = updated_blocker} -> updated_blocker
+ nil -> blocker
+ end
+
unsubscribe(blocked, blocker)
unfollowing_blocked = Config.get([:activitypub, :unfollow_blocked], true)
|> Enum.map(&String.downcase/1)
end
- defp local_nickname_regex do
+ def local_nickname_regex do
if Config.get([:instance, :extended_nickname_format]) do
@extended_local_nickname_regex
else
|> update_and_set_cache()
end
+ def alias_users(user) do
+ user.also_known_as
+ |> Enum.map(&User.get_cached_by_ap_id/1)
+ |> Enum.filter(fn user -> user != nil end)
+ end
+
+ def add_alias(user, new_alias_user) do
+ current_aliases = user.also_known_as || []
+ new_alias_ap_id = new_alias_user.ap_id
+
+ if new_alias_ap_id in current_aliases do
+ {:ok, user}
+ else
+ user
+ |> cast(%{also_known_as: current_aliases ++ [new_alias_ap_id]}, [:also_known_as])
+ |> update_and_set_cache()
+ end
+ end
+
+ def delete_alias(user, alias_user) do
+ current_aliases = user.also_known_as || []
+ alias_ap_id = alias_user.ap_id
+
+ if alias_ap_id in current_aliases do
+ user
+ |> cast(%{also_known_as: current_aliases -- [alias_ap_id]}, [:also_known_as])
+ |> update_and_set_cache()
+ else
+ {:error, :no_such_alias}
+ end
+ end
+
# Internal function; public one is `deactivate/2`
defp set_activation_status(user, status) do
user