aboutsummaryrefslogtreecommitdiff
path: root/lib
diff options
context:
space:
mode:
authorfeld <feld@feld.me>2019-10-23 17:34:42 +0000
committerfeld <feld@feld.me>2019-10-23 17:34:42 +0000
commit17c237ba808d4356bb1e202e459680563b79ef99 (patch)
tree62faffc1033054e2aa1414d85bc0009c004c6910 /lib
parent54077677eaad44ea355c7f0db7ea5e94183d5a30 (diff)
parentc0246309a5013b17a405644a0918ec0d3569eaf1 (diff)
downloadpleroma-17c237ba808d4356bb1e202e459680563b79ef99.tar.gz
Merge branch '1304-user-info-deprecation' into 'develop'
[#1304] User.Info deprecation Closes #1304 See merge request pleroma/pleroma!1851
Diffstat (limited to 'lib')
-rw-r--r--lib/mix/tasks/pleroma/user.ex28
-rw-r--r--lib/pleroma/daemons/digest_email_daemon.ex2
-rw-r--r--lib/pleroma/emails/user_email.ex2
-rw-r--r--lib/pleroma/formatter.ex2
-rw-r--r--lib/pleroma/notification.ex16
-rw-r--r--lib/pleroma/plugs/admin_secret_authentication_plug.ex2
-rw-r--r--lib/pleroma/plugs/oauth_plug.ex2
-rw-r--r--lib/pleroma/plugs/user_enabled_plug.ex2
-rw-r--r--lib/pleroma/plugs/user_is_admin_plug.ex2
-rw-r--r--lib/pleroma/stats.ex7
-rw-r--r--lib/pleroma/user.ex749
-rw-r--r--lib/pleroma/user/info.ex482
-rw-r--r--lib/pleroma/user/query.ex21
-rw-r--r--lib/pleroma/user/search.ex4
-rw-r--r--lib/pleroma/web/activity_pub/activity_pub.ex42
-rw-r--r--lib/pleroma/web/activity_pub/activity_pub_controller.ex6
-rw-r--r--lib/pleroma/web/activity_pub/mrf/anti_link_spam_policy.ex2
-rw-r--r--lib/pleroma/web/activity_pub/publisher.ex8
-rw-r--r--lib/pleroma/web/activity_pub/relay.ex2
-rw-r--r--lib/pleroma/web/activity_pub/transmogrifier.ex15
-rw-r--r--lib/pleroma/web/activity_pub/views/user_view.ex28
-rw-r--r--lib/pleroma/web/admin_api/admin_api_controller.ex35
-rw-r--r--lib/pleroma/web/admin_api/views/account_view.ex5
-rw-r--r--lib/pleroma/web/common_api/common_api.ex20
-rw-r--r--lib/pleroma/web/masto_fe_controller.ex2
-rw-r--r--lib/pleroma/web/mastodon_api/controllers/account_controller.ex64
-rw-r--r--lib/pleroma/web/mastodon_api/controllers/domain_block_controller.ex4
-rw-r--r--lib/pleroma/web/mastodon_api/views/account_view.ex68
-rw-r--r--lib/pleroma/web/mastodon_api/views/status_view.ex2
-rw-r--r--lib/pleroma/web/oauth/oauth_controller.ex4
-rw-r--r--lib/pleroma/web/pleroma_api/controllers/account_controller.ex16
-rw-r--r--lib/pleroma/web/pleroma_api/controllers/mascot_controller.ex4
-rw-r--r--lib/pleroma/web/streamer/worker.ex10
-rw-r--r--lib/pleroma/web/twitter_api/twitter_api_controller.ex11
-rw-r--r--lib/pleroma/web/views/masto_fe_view.ex8
35 files changed, 797 insertions, 880 deletions
diff --git a/lib/mix/tasks/pleroma/user.ex b/lib/mix/tasks/pleroma/user.ex
index 134b5bccc..d7bdc2310 100644
--- a/lib/mix/tasks/pleroma/user.ex
+++ b/lib/mix/tasks/pleroma/user.ex
@@ -5,6 +5,7 @@
defmodule Mix.Tasks.Pleroma.User do
use Mix.Task
import Mix.Pleroma
+ alias Ecto.Changeset
alias Pleroma.User
alias Pleroma.UserInviteToken
alias Pleroma.Web.OAuth
@@ -109,10 +110,10 @@ defmodule Mix.Tasks.Pleroma.User do
start_pleroma()
with %User{} = user <- User.get_cached_by_nickname(nickname) do
- {:ok, user} = User.deactivate(user, !user.info.deactivated)
+ {:ok, user} = User.deactivate(user, !user.deactivated)
shell_info(
- "Activation status of #{nickname}: #{if(user.info.deactivated, do: "de", else: "")}activated"
+ "Activation status of #{nickname}: #{if(user.deactivated, do: "de", else: "")}activated"
)
else
_ ->
@@ -340,7 +341,7 @@ defmodule Mix.Tasks.Pleroma.User do
with %User{} = user <- User.get_cached_by_nickname(nickname) do
{:ok, user} = User.toggle_confirmation(user)
- message = if user.info.confirmation_pending, do: "needs", else: "doesn't need"
+ message = if user.confirmation_pending, do: "needs", else: "doesn't need"
shell_info("#{nickname} #{message} confirmation.")
else
@@ -364,23 +365,32 @@ defmodule Mix.Tasks.Pleroma.User do
end
defp set_moderator(user, value) do
- {:ok, user} = User.update_info(user, &User.Info.admin_api_update(&1, %{is_moderator: value}))
+ {:ok, user} =
+ user
+ |> Changeset.change(%{is_moderator: value})
+ |> User.update_and_set_cache()
- shell_info("Moderator status of #{user.nickname}: #{user.info.is_moderator}")
+ shell_info("Moderator status of #{user.nickname}: #{user.is_moderator}")
user
end
defp set_admin(user, value) do
- {:ok, user} = User.update_info(user, &User.Info.admin_api_update(&1, %{is_admin: value}))
+ {:ok, user} =
+ user
+ |> Changeset.change(%{is_admin: value})
+ |> User.update_and_set_cache()
- shell_info("Admin status of #{user.nickname}: #{user.info.is_admin}")
+ shell_info("Admin status of #{user.nickname}: #{user.is_admin}")
user
end
defp set_locked(user, value) do
- {:ok, user} = User.update_info(user, &User.Info.user_upgrade(&1, %{locked: value}))
+ {:ok, user} =
+ user
+ |> Changeset.change(%{locked: value})
+ |> User.update_and_set_cache()
- shell_info("Locked status of #{user.nickname}: #{user.info.locked}")
+ shell_info("Locked status of #{user.nickname}: #{user.locked}")
user
end
end
diff --git a/lib/pleroma/daemons/digest_email_daemon.ex b/lib/pleroma/daemons/digest_email_daemon.ex
index 462ad2c55..b4c8eaad9 100644
--- a/lib/pleroma/daemons/digest_email_daemon.ex
+++ b/lib/pleroma/daemons/digest_email_daemon.ex
@@ -17,7 +17,7 @@ defmodule Pleroma.Daemons.DigestEmailDaemon do
now = NaiveDateTime.truncate(NaiveDateTime.utc_now(), :second)
from(u in inactive_users_query,
- where: fragment(~s(? #> '{"email_notifications","digest"}' @> 'true'), u.info),
+ where: fragment(~s(? ->'digest' @> 'true'), u.email_notifications),
where: u.last_digest_emailed_at < datetime_add(^now, ^negative_interval, "day"),
select: u
)
diff --git a/lib/pleroma/emails/user_email.ex b/lib/pleroma/emails/user_email.ex
index 40b67ff56..a10f88f93 100644
--- a/lib/pleroma/emails/user_email.ex
+++ b/lib/pleroma/emails/user_email.ex
@@ -72,7 +72,7 @@ defmodule Pleroma.Emails.UserEmail do
Endpoint,
:confirm_email,
user.id,
- to_string(user.info.confirmation_token)
+ to_string(user.confirmation_token)
)
html_body = """
diff --git a/lib/pleroma/formatter.ex b/lib/pleroma/formatter.ex
index 931b9af2b..19b9af46c 100644
--- a/lib/pleroma/formatter.ex
+++ b/lib/pleroma/formatter.ex
@@ -127,7 +127,7 @@ defmodule Pleroma.Formatter do
end
end
- defp get_ap_id(%User{info: %{source_data: %{"url" => url}}}) when is_binary(url), do: url
+ defp get_ap_id(%User{source_data: %{"url" => url}}) when is_binary(url), do: url
defp get_ap_id(%User{ap_id: ap_id}), do: ap_id
defp get_nickname_text(nickname, %{mentions_format: :full}), do: User.full_nickname(nickname)
diff --git a/lib/pleroma/notification.ex b/lib/pleroma/notification.ex
index e5da1492b..b7ecf51e4 100644
--- a/lib/pleroma/notification.ex
+++ b/lib/pleroma/notification.ex
@@ -40,7 +40,7 @@ defmodule Pleroma.Notification do
|> where(
[n, a],
fragment(
- "? not in (SELECT ap_id FROM users WHERE info->'deactivated' @> 'true')",
+ "? not in (SELECT ap_id FROM users WHERE deactivated = 'true')",
a.actor
)
)
@@ -61,10 +61,10 @@ defmodule Pleroma.Notification do
defp exclude_blocked(query, user) do
query
- |> where([n, a], a.actor not in ^user.info.blocks)
+ |> where([n, a], a.actor not in ^user.blocks)
|> where(
[n, a],
- fragment("substring(? from '.*://([^/]*)')", a.actor) not in ^user.info.domain_blocks
+ fragment("substring(? from '.*://([^/]*)')", a.actor) not in ^user.domain_blocks
)
end
@@ -74,7 +74,7 @@ defmodule Pleroma.Notification do
defp exclude_muted(query, user, _opts) do
query
- |> where([n, a], a.actor not in ^user.info.muted_notifications)
+ |> where([n, a], a.actor not in ^user.muted_notifications)
|> join(:left, [n, a], tm in Pleroma.ThreadMute,
on: tm.user_id == ^user.id and tm.context == fragment("?->>'context'", a.data)
)
@@ -314,7 +314,7 @@ defmodule Pleroma.Notification do
def skip?(
:followers,
activity,
- %{info: %{notification_settings: %{"followers" => false}}} = user
+ %{notification_settings: %{"followers" => false}} = user
) do
actor = activity.data["actor"]
follower = User.get_cached_by_ap_id(actor)
@@ -324,14 +324,14 @@ defmodule Pleroma.Notification do
def skip?(
:non_followers,
activity,
- %{info: %{notification_settings: %{"non_followers" => false}}} = user
+ %{notification_settings: %{"non_followers" => false}} = user
) do
actor = activity.data["actor"]
follower = User.get_cached_by_ap_id(actor)
!User.following?(follower, user)
end
- def skip?(:follows, activity, %{info: %{notification_settings: %{"follows" => false}}} = user) do
+ def skip?(:follows, activity, %{notification_settings: %{"follows" => false}} = user) do
actor = activity.data["actor"]
followed = User.get_cached_by_ap_id(actor)
User.following?(user, followed)
@@ -340,7 +340,7 @@ defmodule Pleroma.Notification do
def skip?(
:non_follows,
activity,
- %{info: %{notification_settings: %{"non_follows" => false}}} = user
+ %{notification_settings: %{"non_follows" => false}} = user
) do
actor = activity.data["actor"]
followed = User.get_cached_by_ap_id(actor)
diff --git a/lib/pleroma/plugs/admin_secret_authentication_plug.ex b/lib/pleroma/plugs/admin_secret_authentication_plug.ex
index 5baf8a691..fdadd476e 100644
--- a/lib/pleroma/plugs/admin_secret_authentication_plug.ex
+++ b/lib/pleroma/plugs/admin_secret_authentication_plug.ex
@@ -19,7 +19,7 @@ defmodule Pleroma.Plugs.AdminSecretAuthenticationPlug do
def call(%{params: %{"admin_token" => admin_token}} = conn, _) do
if secret_token() && admin_token == secret_token() do
conn
- |> assign(:user, %User{info: %{is_admin: true}})
+ |> assign(:user, %User{is_admin: true})
else
conn
end
diff --git a/lib/pleroma/plugs/oauth_plug.ex b/lib/pleroma/plugs/oauth_plug.ex
index 86bc4aa3a..fd004fcd2 100644
--- a/lib/pleroma/plugs/oauth_plug.ex
+++ b/lib/pleroma/plugs/oauth_plug.ex
@@ -71,7 +71,7 @@ defmodule Pleroma.Plugs.OAuthPlug do
)
# credo:disable-for-next-line Credo.Check.Readability.MaxLineLength
- with %Token{user: %{info: %{deactivated: false} = _} = user} = token_record <- Repo.one(query) do
+ with %Token{user: %{deactivated: false} = user} = token_record <- Repo.one(query) do
{:ok, user, token_record}
end
end
diff --git a/lib/pleroma/plugs/user_enabled_plug.ex b/lib/pleroma/plugs/user_enabled_plug.ex
index da892c28b..fbb4bf115 100644
--- a/lib/pleroma/plugs/user_enabled_plug.ex
+++ b/lib/pleroma/plugs/user_enabled_plug.ex
@@ -10,7 +10,7 @@ defmodule Pleroma.Plugs.UserEnabledPlug do
options
end
- def call(%{assigns: %{user: %User{info: %{deactivated: true}}}} = conn, _) do
+ def call(%{assigns: %{user: %User{deactivated: true}}} = conn, _) do
conn
|> assign(:user, nil)
end
diff --git a/lib/pleroma/plugs/user_is_admin_plug.ex b/lib/pleroma/plugs/user_is_admin_plug.ex
index 4c4b3d610..ee808f31f 100644
--- a/lib/pleroma/plugs/user_is_admin_plug.ex
+++ b/lib/pleroma/plugs/user_is_admin_plug.ex
@@ -11,7 +11,7 @@ defmodule Pleroma.Plugs.UserIsAdminPlug do
options
end
- def call(%{assigns: %{user: %User{info: %{is_admin: true}}}} = conn, _) do
+ def call(%{assigns: %{user: %User{is_admin: true}}} = conn, _) do
conn
end
diff --git a/lib/pleroma/stats.ex b/lib/pleroma/stats.ex
index df80fbaa4..8154a09b7 100644
--- a/lib/pleroma/stats.ex
+++ b/lib/pleroma/stats.ex
@@ -68,12 +68,7 @@ defmodule Pleroma.Stats do
domain_count = Enum.count(peers)
- status_query =
- from(u in User.Query.build(%{local: true}),
- select: fragment("sum((?->>'note_count')::int)", u.info)
- )
-
- status_count = Repo.one(status_query)
+ status_count = Repo.aggregate(User.Query.build(%{local: true}), :sum, :note_count)
user_count = Repo.aggregate(User.Query.build(%{local: true, active: true}), :count, :id)
diff --git a/lib/pleroma/user.ex b/lib/pleroma/user.ex
index 2bbfaa55b..7bef6e281 100644
--- a/lib/pleroma/user.ex
+++ b/lib/pleroma/user.ex
@@ -61,15 +61,70 @@ defmodule Pleroma.User do
field(:tags, {:array, :string}, default: [])
field(:last_refreshed_at, :naive_datetime_usec)
field(:last_digest_emailed_at, :naive_datetime)
+
+ field(:banner, :map, default: %{})
+ field(:background, :map, default: %{})
+ field(:source_data, :map, default: %{})
+ field(:note_count, :integer, default: 0)
+ field(:follower_count, :integer, default: 0)
+ # Should be filled in only for remote users
+ field(:following_count, :integer, default: nil)
+ field(:locked, :boolean, default: false)
+ field(:confirmation_pending, :boolean, default: false)
+ field(:password_reset_pending, :boolean, default: false)
+ field(:confirmation_token, :string, default: nil)
+ field(:default_scope, :string, default: "public")
+ field(:blocks, {:array, :string}, default: [])
+ field(:domain_blocks, {:array, :string}, default: [])
+ field(:mutes, {:array, :string}, default: [])
+ field(:muted_reblogs, {:array, :string}, default: [])
+ field(:muted_notifications, {:array, :string}, default: [])
+ field(:subscribers, {:array, :string}, default: [])
+ field(:deactivated, :boolean, default: false)
+ field(:no_rich_text, :boolean, default: false)
+ field(:ap_enabled, :boolean, default: false)
+ field(:is_moderator, :boolean, default: false)
+ field(:is_admin, :boolean, default: false)
+ field(:show_role, :boolean, default: true)
+ field(:settings, :map, default: nil)
+ field(:magic_key, :string, default: nil)
+ field(:uri, :string, default: nil)
+ field(:hide_followers_count, :boolean, default: false)
+ field(:hide_follows_count, :boolean, default: false)
+ field(:hide_followers, :boolean, default: false)
+ field(:hide_follows, :boolean, default: false)
+ field(:hide_favorites, :boolean, default: true)
+ field(:unread_conversation_count, :integer, default: 0)
+ field(:pinned_activities, {:array, :string}, default: [])
+ field(:email_notifications, :map, default: %{"digest" => false})
+ field(:mascot, :map, default: nil)
+ field(:emoji, {:array, :map}, default: [])
+ field(:pleroma_settings_store, :map, default: %{})
+ field(:fields, {:array, :map}, default: [])
+ field(:raw_fields, {:array, :map}, default: [])
+ field(:discoverable, :boolean, default: false)
+ field(:invisible, :boolean, default: false)
+ field(:skip_thread_containment, :boolean, default: false)
+
+ field(:notification_settings, :map,
+ default: %{
+ "followers" => true,
+ "follows" => true,
+ "non_follows" => true,
+ "non_followers" => true
+ }
+ )
+
has_many(:notifications, Notification)
has_many(:registrations, Registration)
has_many(:deliveries, Delivery)
- embeds_one(:info, User.Info)
+
+ field(:info, :map, default: %{})
timestamps()
end
- def auth_active?(%User{info: %User.Info{confirmation_pending: true}}),
+ def auth_active?(%User{confirmation_pending: true}),
do: !Pleroma.Config.get([:instance, :account_activation_required])
def auth_active?(%User{}), do: true
@@ -84,11 +139,11 @@ defmodule Pleroma.User do
def visible_for?(_, _), do: false
- def superuser?(%User{local: true, info: %User.Info{is_admin: true}}), do: true
- def superuser?(%User{local: true, info: %User.Info{is_moderator: true}}), do: true
+ def superuser?(%User{local: true, is_admin: true}), do: true
+ def superuser?(%User{local: true, is_moderator: true}), do: true
def superuser?(_), do: false
- def invisible?(%User{info: %User.Info{invisible: true}}), do: true
+ def invisible?(%User{invisible: true}), do: true
def invisible?(_), do: false
def avatar_url(user, options \\ []) do
@@ -99,13 +154,13 @@ defmodule Pleroma.User do
end
def banner_url(user, options \\ []) do
- case user.info.banner do
+ case user.banner do
%{"url" => [%{"href" => href} | _]} -> href
_ -> !options[:no_default] && "#{Web.base_url()}/images/banner.png"
end
end
- def profile_url(%User{info: %{source_data: %{"url" => url}}}), do: url
+ def profile_url(%User{source_data: %{"url" => url}}), do: url
def profile_url(%User{ap_id: ap_id}), do: ap_id
def profile_url(_), do: nil
@@ -120,15 +175,15 @@ defmodule Pleroma.User do
def user_info(%User{} = user, args \\ %{}) do
following_count =
- Map.get(args, :following_count, user.info.following_count || following_count(user))
+ Map.get(args, :following_count, user.following_count || following_count(user))
- follower_count = Map.get(args, :follower_count, user.info.follower_count)
+ follower_count = Map.get(args, :follower_count, user.follower_count)
%{
- note_count: user.info.note_count,
- locked: user.info.locked,
- confirmation_pending: user.info.confirmation_pending,
- default_scope: user.info.default_scope
+ note_count: user.note_count,
+ locked: user.locked,
+ confirmation_pending: user.confirmation_pending,
+ default_scope: user.default_scope
}
|> Map.put(:following_count, following_count)
|> Map.put(:follower_count, follower_count)
@@ -158,9 +213,7 @@ defmodule Pleroma.User do
@spec restrict_deactivated(Ecto.Query.t()) :: Ecto.Query.t()
def restrict_deactivated(query) do
- from(u in query,
- where: not fragment("? \\? 'deactivated' AND ?->'deactivated' @> 'true'", u.info, u.info)
- )
+ from(u in query, where: u.deactivated != ^true)
end
def following_count(%User{following: []}), do: 0
@@ -171,6 +224,62 @@ defmodule Pleroma.User do
|> Repo.aggregate(:count, :id)
end
+ @info_fields [
+ :banner,
+ :background,
+ :source_data,
+ :note_count,
+ :follower_count,
+ :following_count,
+ :locked,
+ :confirmation_pending,
+ :password_reset_pending,
+ :confirmation_token,
+ :default_scope,
+ :blocks,
+ :domain_blocks,
+ :mutes,
+ :muted_reblogs,
+ :muted_notifications,
+ :subscribers,
+ :deactivated,
+ :no_rich_text,
+ :ap_enabled,
+ :is_moderator,
+ :is_admin,
+ :show_role,
+ :settings,
+ :magic_key,
+ :uri,
+ :hide_followers_count,
+ :hide_follows_count,
+ :hide_followers,
+ :hide_follows,
+ :hide_favorites,
+ :unread_conversation_count,
+ :pinned_activities,
+ :email_notifications,
+ :mascot,
+ :emoji,
+ :pleroma_settings_store,
+ :fields,
+ :raw_fields,
+ :discoverable,
+ :invisible,
+ :skip_thread_containment,
+ :notification_settings
+ ]
+
+ def info_fields, do: @info_fields
+
+ defp truncate_fields_param(params) do
+ if Map.has_key?(params, :fields) do
+ Map.put(params, :fields, Enum.map(params[:fields], &truncate_field/1))
+ else
+ params
+ end
+ end
+
defp truncate_if_exists(params, key, max_length) do
if Map.has_key?(params, key) and is_binary(params[key]) do
{value, _chopped} = String.split_at(params[key], max_length)
@@ -189,18 +298,43 @@ defmodule Pleroma.User do
|> Map.put(:info, params[:info] || %{})
|> truncate_if_exists(:name, name_limit)
|> truncate_if_exists(:bio, bio_limit)
+ |> truncate_fields_param()
changeset =
%User{local: false}
- |> cast(params, [:bio, :name, :ap_id, :nickname, :avatar])
+ |> cast(
+ params,
+ [
+ :bio,
+ :name,
+ :ap_id,
+ :nickname,
+ :avatar,
+ :ap_enabled,
+ :source_data,
+ :banner,
+ :locked,
+ :magic_key,
+ :uri,
+ :hide_followers,
+ :hide_follows,
+ :hide_followers_count,
+ :hide_follows_count,
+ :follower_count,
+ :fields,
+ :following_count,
+ :discoverable,
+ :invisible
+ ]
+ )
|> validate_required([:name, :ap_id])
|> unique_constraint(:nickname)
|> validate_format(:nickname, @email_regex)
|> validate_length(:bio, max: bio_limit)
|> validate_length(:name, max: name_limit)
- |> change_info(&User.Info.remote_user_creation(&1, params[:info]))
+ |> validate_fields(true)
- case params[:info][:source_data] do
+ case params[:source_data] do
%{"followers" => followers, "following" => following} ->
changeset
|> put_change(:follower_address, followers)
@@ -217,11 +351,36 @@ defmodule Pleroma.User do
name_limit = Pleroma.Config.get([:instance, :user_name_length], 100)
struct
- |> cast(params, [:bio, :name, :avatar, :following])
+ |> cast(
+ params,
+ [
+ :bio,
+ :name,
+ :avatar,
+ :following,
+ :locked,
+ :no_rich_text,
+ :default_scope,
+ :banner,
+ :hide_follows,
+ :hide_followers,
+ :hide_followers_count,
+ :hide_follows_count,
+ :hide_favorites,
+ :background,
+ :show_role,
+ :skip_thread_containment,
+ :fields,
+ :raw_fields,
+ :pleroma_settings_store,
+ :discoverable
+ ]
+ )
|> unique_constraint(:nickname)
|> validate_format(:nickname, local_nickname_regex())
|> validate_length(:bio, max: bio_limit)
|> validate_length(:name, min: 1, max: name_limit)
+ |> validate_fields(false)
end
def upgrade_changeset(struct, params \\ %{}, remote? \\ false) do
@@ -230,20 +389,38 @@ defmodule Pleroma.User do
params = Map.put(params, :last_refreshed_at, NaiveDateTime.utc_now())
+ params = if remote?, do: truncate_fields_param(params), else: params
+
struct
- |> cast(params, [
- :bio,
- :name,
- :follower_address,
- :following_address,
- :avatar,
- :last_refreshed_at
- ])
+ |> cast(
+ params,
+ [
+ :bio,
+ :name,
+ :follower_address,
+ :following_address,
+ :avatar,
+ :last_refreshed_at,
+ :ap_enabled,
+ :source_data,
+ :banner,
+ :locked,
+ :magic_key,
+ :follower_count,
+ :following_count,
+ :hide_follows,
+ :fields,
+ :hide_followers,
+ :discoverable,
+ :hide_followers_count,
+ :hide_follows_count
+ ]
+ )
|> unique_constraint(:nickname)
|> validate_format(:nickname, local_nickname_regex())
|> validate_length(:bio, max: bio_limit)
|> validate_length(:name, max: name_limit)
- |> change_info(&User.Info.user_upgrade(&1, params[:info], remote?))
+ |> validate_fields(remote?)
end
def password_update_changeset(struct, params) do
@@ -251,8 +428,8 @@ defmodule Pleroma.User do
|> cast(params, [:password, :password_confirmation])
|> validate_required([:password, :password_confirmation])
|> validate_confirmation(:password)
- |> put_password_hash
- |> put_embed(:info, User.Info.set_password_reset_pending(struct.info, false))
+ |> put_password_hash()
+ |> put_change(:password_reset_pending, false)
end
@spec reset_password(User.t(), map) :: {:ok, User.t()} | {:error, Ecto.Changeset.t()}
@@ -269,19 +446,19 @@ defmodule Pleroma.User do
end
end
+ def update_password_reset_pending(user, value) do
+ user
+ |> change()
+ |> put_change(:password_reset_pending, value)
+ |> update_and_set_cache()
+ end
+
def force_password_reset_async(user) do
BackgroundWorker.enqueue("force_password_reset", %{"user_id" => user.id})
end
@spec force_password_reset(User.t()) :: {:ok, User.t()} | {:error, Ecto.Changeset.t()}
- def force_password_reset(user) do
- info_cng = User.Info.set_password_reset_pending(user.info, true)
-
- user
- |> change()
- |> put_embed(:info, info_cng)
- |> update_and_set_cache()
- end
+ def force_password_reset(user), do: update_password_reset_pending(user, true)
def register_changeset(struct, params \\ %{}, opts \\ []) do
bio_limit = Pleroma.Config.get([:instance, :user_bio_length], 5000)
@@ -295,6 +472,7 @@ defmodule Pleroma.User do
end
struct
+ |> confirmation_changeset(need_confirmation: need_confirmation?)
|> cast(params, [:bio, :email, :name, :nickname, :password, :password_confirmation])
|> validate_required([:name, :nickname, :password, :password_confirmation])
|> validate_confirmation(:password)
@@ -305,7 +483,6 @@ defmodule Pleroma.User do
|> validate_format(:email, @email_regex)
|> validate_length(:bio, max: bio_limit)
|> validate_length(:name, min: 1, max: name_limit)
- |> change_info(&User.Info.confirmation_changeset(&1, need_confirmation: need_confirmation?))
|> maybe_validate_required_email(opts[:external])
|> put_password_hash
|> put_ap_id()
@@ -356,7 +533,7 @@ defmodule Pleroma.User do
end
def try_send_confirmation_email(%User{} = user) do
- if user.info.confirmation_pending &&
+ if user.confirmation_pending &&
Pleroma.Config.get([:instance, :account_activation_required]) do
user
|> Pleroma.Emails.UserEmail.account_confirmation_email()
@@ -379,7 +556,7 @@ defmodule Pleroma.User do
def needs_update?(_), do: true
@spec maybe_direct_follow(User.t(), User.t()) :: {:ok, User.t()} | {:error, String.t()}
- def maybe_direct_follow(%User{} = follower, %User{local: true, info: %{locked: true}}) do
+ def maybe_direct_follow(%User{} = follower, %User{local: true, locked: true}) do
{:ok, follower}
end
@@ -426,13 +603,13 @@ defmodule Pleroma.User do
set_cache(follower)
end
- def follow(%User{} = follower, %User{info: info} = followed) do
+ def follow(%User{} = follower, %User{} = followed) do
deny_follow_blocked = Pleroma.Config.get([:user, :deny_follow_blocked])
ap_followers = followed.follower_address
cond do
- info.deactivated ->
- {:error, "Could not follow user: You are deactivated."}
+ followed.deactivated ->
+ {:error, "Could not follow user: #{followed.nickname} is deactivated."}
deny_follow_blocked and blocks?(followed, follower) ->
{:error, "Could not follow user: #{followed.nickname} blocked you."}
@@ -486,7 +663,7 @@ defmodule Pleroma.User do
end
def locked?(%User{} = user) do
- user.info.locked || false
+ user.locked || false
end
def get_by_id(id) do
@@ -529,6 +706,12 @@ defmodule Pleroma.User do
{:ok, user}
end
+ def update_and_set_cache(struct, params) do
+ struct
+ |> update_changeset(params)
+ |> update_and_set_cache()
+ end
+
def update_and_set_cache(changeset) do
with {:ok, user} <- Repo.update(changeset, stale_error_field: :id) do
set_cache(user)
@@ -713,16 +896,7 @@ defmodule Pleroma.User do
def increase_note_count(%User{} = user) do
User
|> where(id: ^user.id)
- |> update([u],
- set: [
- info:
- fragment(
- "safe_jsonb_set(?, '{note_count}', ((?->>'note_count')::int + 1)::varchar::jsonb, true)",
- u.info,
- u.info
- )
- ]
- )
+ |> update([u], inc: [note_count: 1])
|> select([u], u)
|> Repo.update_all([])
|> case do
@@ -736,12 +910,7 @@ defmodule Pleroma.User do
|> where(id: ^user.id)
|> update([u],
set: [
- info:
- fragment(
- "safe_jsonb_set(?, '{note_count}', (greatest(0, (?->>'note_count')::int - 1))::varchar::jsonb, true)",
- u.info,
- u.info
- )
+ note_count: fragment("greatest(0, note_count - 1)")
]
)
|> select([u], u)
@@ -752,28 +921,18 @@ defmodule Pleroma.User do
end
end
- def update_note_count(%User{} = user) do
+ def update_note_count(%User{} = user, note_count \\ nil) do
note_count =
- from(
- a in Object,
- where: fragment("?->>'actor' = ? and ?->>'type' = 'Note'", a.data, ^user.ap_id, a.data),
- select: count(a.id)
- )
- |> Repo.one()
-
- update_info(user, &User.Info.set_note_count(&1, note_count))
- end
-
- def update_mascot(user, url) do
- info_changeset =
- User.Info.mascot_update(
- user.info,
- url
- )
+ note_count ||
+ from(
+ a in Object,
+ where: fragment("?->>'actor' = ? and ?->>'type' = 'Note'", a.data, ^user.ap_id, a.data),
+ select: count(a.id)
+ )
+ |> Repo.one()
user
- |> change()
- |> put_embed(:info, info_changeset)
+ |> cast(%{note_count: note_count}, [:note_count])
|> update_and_set_cache()
end
@@ -791,10 +950,24 @@ defmodule Pleroma.User do
def fetch_follow_information(user) do
with {:ok, info} <- ActivityPub.fetch_follow_information_for_user(user) do
- update_info(user, &User.Info.follow_information_update(&1, info))
+ user
+ |> follow_information_changeset(info)
+ |> update_and_set_cache()
end
end
+ defp follow_information_changeset(user, params) do
+ user
+ |> cast(params, [
+ :hide_followers,
+ :hide_follows,
+ :follower_count,
+ :following_count,
+ :hide_followers_count,
+ :hide_follows_count
+ ])
+ end
+
def update_follower_count(%User{} = user) do
if user.local or !Pleroma.Config.get([:instance, :external_user_synchronization]) do
follower_count_query =
@@ -805,14 +978,7 @@ defmodule Pleroma.User do
|> where(id: ^user.id)
|> join(:inner, [u], s in subquery(follower_count_query))
|> update([u, s],
- set: [
- info:
- fragment(
- "safe_jsonb_set(?, '{follower_count}', ?::varchar::jsonb, true)",
- u.info,
- s.count
- )
- ]
+ set: [follower_count: s.count]
)
|> select([u], u)
|> Repo.update_all([])
@@ -842,14 +1008,7 @@ defmodule Pleroma.User do
User
|> join(:inner, [u], p in subquery(unread_query))
|> update([u, p],
- set: [
- info:
- fragment(
- "jsonb_set(?, '{unread_conversation_count}', ?::varchar::jsonb, true)",
- u.info,
- p.count
- )
- ]
+ set: [unread_conversation_count: p.count]
)
|> where([u], u.id == ^user.id)
|> select([u], u)
@@ -870,14 +1029,7 @@ defmodule Pleroma.User do
User
|> join(:inner, [u], p in subquery(unread_query))
|> update([u, p],
- set: [
- info:
- fragment(
- "jsonb_set(?, '{unread_conversation_count}', (coalesce((?->>'unread_conversation_count')::int, 0) + 1)::varchar::jsonb, true)",
- u.info,
- u.info
- )
- ]
+ inc: [unread_conversation_count: 1]
)
|> where([u], u.id == ^user.id)
|> where([u, p], p.count == 0)
@@ -920,11 +1072,11 @@ defmodule Pleroma.User do
@spec mute(User.t(), User.t(), boolean()) :: {:ok, User.t()} | {:error, String.t()}
def mute(muter, %User{ap_id: ap_id}, notifications? \\ true) do
- update_info(muter, &User.Info.add_to_mutes(&1, ap_id, notifications?))
+ add_to_mutes(muter, ap_id, notifications?)
end
def unmute(muter, %{ap_id: ap_id}) do
- update_info(muter, &User.Info.remove_from_mutes(&1, ap_id))
+ remove_from_mutes(muter, ap_id)
end
def subscribe(subscriber, %{ap_id: ap_id}) do
@@ -934,14 +1086,14 @@ defmodule Pleroma.User do
if blocks?(subscribed, subscriber) and deny_follow_blocked do
{:error, "Could not subscribe: #{subscribed.nickname} is blocking you"}
else
- update_info(subscribed, &User.Info.add_to_subscribers(&1, subscriber.ap_id))
+ User.add_to_subscribers(subscribed, subscriber.ap_id)
end
end
end
def unsubscribe(unsubscriber, %{ap_id: ap_id}) do
with %User{} = user <- get_cached_by_ap_id(ap_id) do
- update_info(user, &User.Info.remove_from_subscribers(&1, unsubscriber.ap_id))
+ User.remove_from_subscribers(user, unsubscriber.ap_id)
end
end
@@ -974,7 +1126,7 @@ defmodule Pleroma.User do
{:ok, blocker} = update_follower_count(blocker)
- update_info(blocker, &User.Info.add_to_block(&1, ap_id))
+ add_to_block(blocker, ap_id)
end
# helper to handle the block given only an actor's AP id
@@ -983,17 +1135,17 @@ defmodule Pleroma.User do
end
def unblock(blocker, %{ap_id: ap_id}) do
- update_info(blocker, &User.Info.remove_from_block(&1, ap_id))
+ remove_from_block(blocker, ap_id)
end
def mutes?(nil, _), do: false
- def mutes?(user, %{ap_id: ap_id}), do: Enum.member?(user.info.mutes, ap_id)
+ def mutes?(user, %{ap_id: ap_id}), do: Enum.member?(user.mutes, ap_id)
@spec muted_notifications?(User.t() | nil, User.t() | map()) :: boolean()
def muted_notifications?(nil, _), do: false
def muted_notifications?(user, %{ap_id: ap_id}),
- do: Enum.member?(user.info.muted_notifications, ap_id)
+ do: Enum.member?(user.muted_notifications, ap_id)
def blocks?(%User{} = user, %User{} = target) do
blocks_ap_id?(user, target) || blocks_domain?(user, target)
@@ -1002,13 +1154,13 @@ defmodule Pleroma.User do
def blocks?(nil, _), do: false
def blocks_ap_id?(%User{} = user, %User{} = target) do
- Enum.member?(user.info.blocks, target.ap_id)
+ Enum.member?(user.blocks, target.ap_id)
end
def blocks_ap_id?(_, _), do: false
def blocks_domain?(%User{} = user, %User{} = target) do
- domain_blocks = Pleroma.Web.ActivityPub.MRF.subdomains_regex(user.info.domain_blocks)
+ domain_blocks = Pleroma.Web.ActivityPub.MRF.subdomains_regex(user.domain_blocks)
%{host: host} = URI.parse(target.ap_id)
Pleroma.Web.ActivityPub.MRF.subdomain_match?(domain_blocks, host)
end
@@ -1017,36 +1169,28 @@ defmodule Pleroma.User do
def subscribed_to?(user, %{ap_id: ap_id}) do
with %User{} = target <- get_cached_by_ap_id(ap_id) do
- Enum.member?(target.info.subscribers, user.ap_id)
+ Enum.member?(target.subscribers, user.ap_id)
end
end
@spec muted_users(User.t()) :: [User.t()]
def muted_users(user) do
- User.Query.build(%{ap_id: user.info.mutes, deactivated: false})
+ User.Query.build(%{ap_id: user.mutes, deactivated: false})
|> Repo.all()
end
@spec blocked_users(User.t()) :: [User.t()]
def blocked_users(user) do
- User.Query.build(%{ap_id: user.info.blocks, deactivated: false})
+ User.Query.build(%{ap_id: user.blocks, deactivated: false})
|> Repo.all()
end
@spec subscribers(User.t()) :: [User.t()]
def subscribers(user) do
- User.Query.build(%{ap_id: user.info.subscribers, deactivated: false})
+ User.Query.build(%{ap_id: user.subscribers, deactivated: false})
|> Repo.all()
end
- def block_domain(user, domain) do
- update_info(user, &User.Info.add_to_domain_block(&1, domain))
- end
-
- def unblock_domain(user, domain) do
- update_info(user, &User.Info.remove_from_domain_block(&1, domain))
- end
-
def deactivate_async(user, status \\ true) do
BackgroundWorker.enqueue("deactivate_user", %{"user_id" => user.id, "status" => status})
end
@@ -1060,7 +1204,7 @@ defmodule Pleroma.User do
end
def deactivate(%User{} = user, status) do
- with {:ok, user} <- update_info(user, &User.Info.set_activation_status(&1, status)) do
+ with {:ok, user} <- set_activation_status(user, status) do
Enum.each(get_followers(user), &invalidate_cache/1)
Enum.each(get_friends(user), &update_follower_count/1)
@@ -1068,8 +1212,23 @@ defmodule Pleroma.User do
end
end
- def update_notification_settings(%User{} = user, settings \\ %{}) do
- update_info(user, &User.Info.update_notification_settings(&1, settings))
+ def update_notification_settings(%User{} = user, settings) do
+ settings =
+ settings
+ |> Enum.map(fn {k, v} -> {k, v in [true, "true", "True", "1"]} end)
+ |> Map.new()
+
+ notification_settings =
+ user.notification_settings
+ |> Map.merge(settings)
+ |> Map.take(["followers", "follows", "non_follows", "non_followers"])
+
+ params = %{notification_settings: notification_settings}
+
+ user
+ |> cast(params, [:notification_settings])
+ |> validate_required([:notification_settings])
+ |> update_and_set_cache()
end
def delete(users) when is_list(users) do
@@ -1111,7 +1270,7 @@ defmodule Pleroma.User do
pages = Pleroma.Config.get!([:fetch_initial_posts, :pages])
# Insert all the posts in reverse order, so they're in the right order on the timeline
- user.info.source_data["outbox"]
+ user.source_data["outbox"]
|> Utils.fetch_ordered_collection(pages)
|> Enum.reverse()
|> Enum.each(&Pleroma.Web.Federator.incoming_ap_doc/1)
@@ -1232,7 +1391,7 @@ defmodule Pleroma.User do
defp delete_activity(_activity), do: "Doing nothing"
- def html_filter_policy(%User{info: %{no_rich_text: true}}) do
+ def html_filter_policy(%User{no_rich_text: true}) do
Pleroma.HTML.Scrubber.TwitterText
end
@@ -1268,7 +1427,7 @@ defmodule Pleroma.User do
else
_ ->
{:ok, user} =
- %User{info: %User.Info{}}
+ %User{}
|> cast(%{}, [:ap_id, :nickname, :local])
|> put_change(:ap_id, uri)
|> put_change(:nickname, nickname)
@@ -1281,9 +1440,7 @@ defmodule Pleroma.User do
end
# AP style
- def public_key_from_info(%{
- source_data: %{"publicKey" => %{"publicKeyPem" => public_key_pem}}
- }) do
+ def public_key(%{source_data: %{"publicKey" => %{"publicKeyPem" => public_key_pem}}}) do
key =
public_key_pem
|> :public_key.pem_decode()
@@ -1293,11 +1450,11 @@ defmodule Pleroma.User do
{:ok, key}
end
- def public_key_from_info(_), do: {:error, "not found key"}
+ def public_key(_), do: {:error, "not found key"}
def get_public_key_for_ap_id(ap_id) do
with {:ok, %User{} = user} <- get_or_fetch_by_ap_id(ap_id),
- {:ok, public_key} <- public_key_from_info(user.info) do
+ {:ok, public_key} <- public_key(user) do
{:ok, public_key}
else
_ -> :error
@@ -1316,7 +1473,7 @@ defmodule Pleroma.User do
end
def ap_enabled?(%User{local: true}), do: true
- def ap_enabled?(%User{info: info}), do: info.ap_enabled
+ def ap_enabled?(%User{ap_enabled: ap_enabled}), do: ap_enabled
def ap_enabled?(_), do: false
@doc "Gets or fetch a user by uri or nickname."
@@ -1429,7 +1586,6 @@ defmodule Pleroma.User do
%User{
name: ap_id,
ap_id: ap_id,
- info: %User.Info{},
nickname: "erroruser@example.com",
inserted_at: NaiveDateTime.utc_now()
}
@@ -1442,7 +1598,7 @@ defmodule Pleroma.User do
end
def showing_reblogs?(%User{} = user, %User{} = target) do
- target.ap_id not in user.info.muted_reblogs
+ target.ap_id not in user.muted_reblogs
end
@doc """
@@ -1474,7 +1630,7 @@ defmodule Pleroma.User do
left_join: a in Pleroma.Activity,
on: u.ap_id == a.actor,
where: not is_nil(u.nickname),
- where: fragment("not (?->'deactivated' @> 'true')", u.info),
+ where: u.deactivated != ^true,
where: u.id not in ^has_read_notifications,
group_by: u.id,
having:
@@ -1488,16 +1644,16 @@ defmodule Pleroma.User do
## Examples
- iex> Pleroma.User.switch_email_notifications(Pleroma.User{info: %{email_notifications: %{"digest" => false}}}, "digest", true)
- Pleroma.User{info: %{email_notifications: %{"digest" => true}}}
+ iex> Pleroma.User.switch_email_notifications(Pleroma.User{email_notifications: %{"digest" => false}}, "digest", true)
+ Pleroma.User{email_notifications: %{"digest" => true}}
- iex> Pleroma.User.switch_email_notifications(Pleroma.User{info: %{email_notifications: %{"digest" => true}}}, "digest", false)
- Pleroma.User{info: %{email_notifications: %{"digest" => false}}}
+ iex> Pleroma.User.switch_email_notifications(Pleroma.User{email_notifications: %{"digest" => true}}, "digest", false)
+ Pleroma.User{email_notifications: %{"digest" => false}}
"""
@spec switch_email_notifications(t(), String.t(), boolean()) ::
{:ok, t()} | {:error, Ecto.Changeset.t()}
def switch_email_notifications(user, type, status) do
- update_info(user, &User.Info.update_email_notifications(&1, %{type => status}))
+ User.update_email_notifications(user, %{type => status})
end
@doc """
@@ -1517,17 +1673,16 @@ defmodule Pleroma.User do
@spec toggle_confirmation(User.t()) :: {:ok, User.t()} | {:error, Changeset.t()}
def toggle_confirmation(%User{} = user) do
- need_confirmation? = !user.info.confirmation_pending
-
user
- |> update_info(&User.Info.confirmation_changeset(&1, need_confirmation: need_confirmation?))
+ |> confirmation_changeset(need_confirmation: !user.confirmation_pending)
+ |> update_and_set_cache()
end
- def get_mascot(%{info: %{mascot: %{} = mascot}}) when not is_nil(mascot) do
+ def get_mascot(%{mascot: %{} = mascot}) when not is_nil(mascot) do
mascot
end
- def get_mascot(%{info: %{mascot: mascot}}) when is_nil(mascot) do
+ def get_mascot(%{mascot: mascot}) when is_nil(mascot) do
# use instance-default
config = Pleroma.Config.get([:assets, :mascots])
default_mascot = Pleroma.Config.get([:assets, :default_mascot])
@@ -1597,31 +1752,285 @@ defmodule Pleroma.User do
|> update_and_set_cache()
end
- @doc """
- Changes `user.info` and returns the user changeset.
+ # Internal function; public one is `deactivate/2`
+ defp set_activation_status(user, deactivated) do
+ user
+ |> cast(%{deactivated: deactivated}, [:deactivated])
+ |> update_and_set_cache()
+ end
- `fun` is called with the `user.info`.
- """
- def change_info(user, fun) do
- changeset = change(user)
- info = get_field(changeset, :info) || %User.Info{}
- put_embed(changeset, :info, fun.(info))
+ def update_banner(user, banner) do
+ user
+ |> cast(%{banner: banner}, [:banner])
+ |> update_and_set_cache()
end
- @doc """
- Updates `user.info` and sets cache.
+ def update_background(user, background) do
+ user
+ |> cast(%{background: background}, [:background])
+ |> update_and_set_cache()
+ end
- `fun` is called with the `user.info`.
- """
- def update_info(users, fun) when is_list(users) do
- Repo.transaction(fn ->
- for user <- users, do: update_info(user, fun)
+ def update_source_data(user, source_data) do
+ user
+ |> cast(%{source_data: source_data}, [:source_data])
+ |> update_and_set_cache()
+ end
+
+ def roles(%{is_moderator: is_moderator, is_admin: is_admin}) do
+ %{
+ admin: is_admin,
+ moderator: is_moderator
+ }
+ end
+
+ # ``fields`` is an array of mastodon profile field, containing ``{"name": "…", "value": "…"}``.
+ # For example: [{"name": "Pronoun", "value": "she/her"}, …]
+ def fields(%{fields: nil, source_data: %{"attachment" => attachment}}) do
+ limit = Pleroma.Config.get([:instance, :max_remote_account_fields], 0)
+
+ attachment
+ |> Enum.filter(fn %{"type" => t} -> t == "PropertyValue" end)
+ |> Enum.map(fn fields -> Map.take(fields, ["name", "value"]) end)
+ |> Enum.take(limit)
+ end
+
+ def fields(%{fields: nil}), do: []
+
+ def fields(%{fields: fields}), do: fields
+
+ def validate_fields(changeset, remote? \\ false) do
+ limit_name = if remote?, do: :max_remote_account_fields, else: :max_account_fields
+ limit = Pleroma.Config.get([:instance, limit_name], 0)
+
+ changeset
+ |> validate_length(:fields, max: limit)
+ |> validate_change(:fields, fn :fields, fields ->
+ if Enum.all?(fields, &valid_field?/1) do
+ []
+ else
+ [fields: "invalid"]
+ end
end)
end
- def update_info(user, fun) do
+ defp valid_field?(%{"name" => name, "value" => value}) do
+ name_limit = Pleroma.Config.get([:instance, :account_field_name_length], 255)
+ value_limit = Pleroma.Config.get([:instance, :account_field_value_length], 255)
+
+ is_binary(name) && is_binary(value) && String.length(name) <= name_limit &&
+ String.length(value) <= value_limit
+ end
+
+ defp valid_field?(_), do: false
+
+ defp truncate_field(%{"name" => name, "value" => value}) do
+ {name, _chopped} =
+ String.split_at(name, Pleroma.Config.get([:instance, :account_field_name_length], 255))
+
+ {value, _chopped} =
+ String.split_at(value, Pleroma.Config.get([:instance, :account_field_value_length], 255))
+
+ %{"name" => name, "value" => value}
+ end
+
+ def admin_api_update(user, params) do
+ user
+ |> cast(params, [
+ :is_moderator,
+ :is_admin,
+ :show_role
+ ])
+ |> update_and_set_cache()
+ end
+
+ def mascot_update(user, url) do
+ user
+ |> cast(%{mascot: url}, [:mascot])
+ |> validate_required([:mascot])
+ |> update_and_set_cache()
+ end
+
+ def mastodon_settings_update(user, settings) do
+ user
+ |> cast(%{settings: settings}, [:settings])
+ |> validate_required([:settings])
+ |> update_and_set_cache()
+ end
+
+ @spec confirmation_changeset(User.t(), keyword()) :: Changeset.t()
+ def confirmation_changeset(user, need_confirmation: need_confirmation?) do
+ params =
+ if need_confirmation? do
+ %{
+ confirmation_pending: true,
+ confirmation_token: :crypto.strong_rand_bytes(32) |> Base.url_encode64()
+ }
+ else
+ %{
+ confirmation_pending: false,
+ confirmation_token: nil
+ }
+ end
+
+ cast(user, params, [:confirmation_pending, :confirmation_token])
+ end
+
+ def add_pinnned_activity(user, %Pleroma.Activity{id: id}) do
+ if id not in user.pinned_activities do
+ max_pinned_statuses = Pleroma.Config.get([:instance, :max_pinned_statuses], 0)
+ params = %{pinned_activities: user.pinned_activities ++ [id]}
+
+ user
+ |> cast(params, [:pinned_activities])
+ |> validate_length(:pinned_activities,
+ max: max_pinned_statuses,
+ message: "You have already pinned the maximum number of statuses"
+ )
+ else
+ change(user)
+ end
+ |> update_and_set_cache()
+ end
+
+ def remove_pinnned_activity(user, %Pleroma.Activity{id: id}) do
+ params = %{pinned_activities: List.delete(user.pinned_activities, id)}
+
+ user
+ |> cast(params, [:pinned_activities])
+ |> update_and_set_cache()
+ end
+
+ def update_email_notifications(user, settings) do
+ email_notifications =
+ user.email_notifications
+ |> Map.merge(settings)
+ |> Map.take(["digest"])
+
+ params = %{email_notifications: email_notifications}
+ fields = [:email_notifications]
+
+ user
+ |> cast(params, fields)
+ |> validate_required(fields)
+ |> update_and_set_cache()
+ end
+
+ defp set_subscribers(user, subscribers) do
+ params = %{subscribers: subscribers}
+
+ user
+ |> cast(params, [:subscribers])
+ |> validate_required([:subscribers])
+ |> update_and_set_cache()
+ end
+
+ def add_to_subscribers(user, subscribed) do
+ set_subscribers(user, Enum.uniq([subscribed | user.subscribers]))
+ end
+
+ def remove_from_subscribers(user, subscribed) do
+ set_subscribers(user, List.delete(user.subscribers, subscribed))
+ end
+
+ defp set_domain_blocks(user, domain_blocks) do
+ params = %{domain_blocks: domain_blocks}
+
+ user
+ |> cast(params, [:domain_blocks])
+ |> validate_required([:domain_blocks])
+ |> update_and_set_cache()
+ end
+
+ def block_domain(user, domain_blocked) do
+ set_domain_blocks(user, Enum.uniq([domain_blocked | user.domain_blocks]))
+ end
+
+ def unblock_domain(user, domain_blocked) do
+ set_domain_blocks(user, List.delete(user.domain_blocks, domain_blocked))
+ end
+
+ defp set_blocks(user, blocks) do
+ params = %{blocks: blocks}
+
+ user
+ |> cast(params, [:blocks])
+ |> validate_required([:blocks])
+ |> update_and_set_cache()
+ end
+
+ def add_to_block(user, blocked) do
+ set_blocks(user, Enum.uniq([blocked | user.blocks]))
+ end
+
+ def remove_from_block(user, blocked) do
+ set_blocks(user, List.delete(user.blocks, blocked))
+ end
+
+ defp set_mutes(user, mutes) do
+ params = %{mutes: mutes}
+
+ user
+ |> cast(params, [:mutes])
+ |> validate_required([:mutes])
+ |> update_and_set_cache()
+ end
+
+ def add_to_mutes(user, muted, notifications?) do
+ with {:ok, user} <- set_mutes(user, Enum.uniq([muted | user.mutes])) do
+ set_notification_mutes(
+ user,
+ Enum.uniq([muted | user.muted_notifications]),
+ notifications?
+ )
+ end
+ end
+
+ def remove_from_mutes(user, muted) do
+ with {:ok, user} <- set_mutes(user, List.delete(user.mutes, muted)) do
+ set_notification_mutes(
+ user,
+ List.delete(user.muted_notifications, muted),
+ true
+ )
+ end
+ end
+
+ defp set_notification_mutes(user, _muted_notifications, false = _notifications?) do
+ {:ok, user}
+ end
+
+ defp set_notification_mutes(user, muted_notifications, true = _notifications?) do
+ params = %{muted_notifications: muted_notifications}
+
+ user
+ |> cast(params, [:muted_notifications])
+ |> validate_required([:muted_notifications])
+ |> update_and_set_cache()
+ end
+
+ def add_reblog_mute(user, ap_id) do
+ params = %{muted_reblogs: user.muted_reblogs ++ [ap_id]}
+
+ user
+ |> cast(params, [:muted_reblogs])
+ |> update_and_set_cache()
+ end
+
+ def remove_reblog_mute(user, ap_id) do
+ params = %{muted_reblogs: List.delete(user.muted_reblogs, ap_id)}
+
+ user
+ |> cast(params, [:muted_reblogs])
+ |> update_and_set_cache()
+ end
+
+ def set_invisible(user, invisible) do
+ params = %{invisible: invisible}
+
user
- |> change_info(fun)
+ |> cast(params, [:invisible])
+ |> validate_required([:invisible])
|> update_and_set_cache()
end
end
diff --git a/lib/pleroma/user/info.ex b/lib/pleroma/user/info.ex
deleted file mode 100644
index 982fb61c6..000000000
--- a/lib/pleroma/user/info.ex
+++ /dev/null
@@ -1,482 +0,0 @@
-# Pleroma: A lightweight social networking server
-# Copyright © 2017-2019 Pleroma Authors <https://pleroma.social/>
-# SPDX-License-Identifier: AGPL-3.0-only
-
-defmodule Pleroma.User.Info do
- use Ecto.Schema
- import Ecto.Changeset
-
- alias Pleroma.User.Info
-
- @type t :: %__MODULE__{}
-
- embedded_schema do
- field(:banner, :map, default: %{})
- field(:background, :map, default: %{})
- field(:source_data, :map, default: %{})
- field(:note_count, :integer, default: 0)
- field(:follower_count, :integer, default: 0)
- # Should be filled in only for remote users
- field(:following_count, :integer, default: nil)
- field(:locked, :boolean, default: false)
- field(:confirmation_pending, :boolean, default: false)
- field(:password_reset_pending, :boolean, default: false)
- field(:confirmation_token, :string, default: nil)
- field(:default_scope, :string, default: "public")
- field(:blocks, {:array, :string}, default: [])
- field(:domain_blocks, {:array, :string}, default: [])
- field(:mutes, {:array, :string}, default: [])
- field(:muted_reblogs, {:array, :string}, default: [])
- field(:muted_notifications, {:array, :string}, default: [])
- field(:subscribers, {:array, :string}, default: [])
- field(:deactivated, :boolean, default: false)
- field(:no_rich_text, :boolean, default: false)
- field(:ap_enabled, :boolean, default: false)
- field(:is_moderator, :boolean, default: false)
- field(:is_admin, :boolean, default: false)
- field(:show_role, :boolean, default: true)
- field(:keys, :string, default: nil)
- field(:settings, :map, default: nil)
- field(:magic_key, :string, default: nil)
- field(:uri, :string, default: nil)
- field(:hide_followers_count, :boolean, default: false)
- field(:hide_follows_count, :boolean, default: false)
- field(:hide_followers, :boolean, default: false)
- field(:hide_follows, :boolean, default: false)
- field(:hide_favorites, :boolean, default: true)
- field(:unread_conversation_count, :integer, default: 0)
- field(:pinned_activities, {:array, :string}, default: [])
- field(:email_notifications, :map, default: %{"digest" => false})
- field(:mascot, :map, default: nil)
- field(:emoji, {:array, :map}, default: [])
- field(:pleroma_settings_store, :map, default: %{})
- field(:fields, {:array, :map}, default: nil)
- field(:raw_fields, {:array, :map}, default: [])
- field(:discoverable, :boolean, default: false)
- field(:invisible, :boolean, default: false)
-
- field(:notification_settings, :map,
- default: %{
- "followers" => true,
- "follows" => true,
- "non_follows" => true,
- "non_followers" => true
- }
- )
-
- field(:skip_thread_containment, :boolean, default: false)
-
- # Found in the wild
- # ap_id -> Where is this used?
- # bio -> Where is this used?
- # avatar -> Where is this used?
- # fqn -> Where is this used?
- # host -> Where is this used?
- # subject _> Where is this used?
- end
-
- def set_activation_status(info, deactivated) do
- params = %{deactivated: deactivated}
-
- info
- |> cast(params, [:deactivated])
- |> validate_required([:deactivated])
- end
-
- def set_password_reset_pending(info, pending) do
- params = %{password_reset_pending: pending}
-
- info
- |> cast(params, [:password_reset_pending])
- |> validate_required([:password_reset_pending])
- end
-
- def update_notification_settings(info, settings) do
- settings =
- settings
- |> Enum.map(fn {k, v} -> {k, v in [true, "true", "True", "1"]} end)
- |> Map.new()
-
- notification_settings =
- info.notification_settings
- |> Map.merge(settings)
- |> Map.take(["followers", "follows", "non_follows", "non_followers"])
-
- params = %{notification_settings: notification_settings}
-
- info
- |> cast(params, [:notification_settings])
- |> validate_required([:notification_settings])
- end
-
- @doc """
- Update email notifications in the given User.Info struct.
-
- Examples:
-
- iex> update_email_notifications(%Pleroma.User.Info{email_notifications: %{"digest" => false}}, %{"digest" => true})
- %Pleroma.User.Info{email_notifications: %{"digest" => true}}
-
- """
- @spec update_email_notifications(t(), map()) :: Ecto.Changeset.t()
- def update_email_notifications(info, settings) do
- email_notifications =
- info.email_notifications
- |> Map.merge(settings)
- |> Map.take(["digest"])
-
- params = %{email_notifications: email_notifications}
- fields = [:email_notifications]
-
- info
- |> cast(params, fields)
- |> validate_required(fields)
- end
-
- def add_to_note_count(info, number) do
- set_note_count(info, info.note_count + number)
- end
-
- def set_note_count(info, number) do
- params = %{note_count: Enum.max([0, number])}
-
- info
- |> cast(params, [:note_count])
- |> validate_required([:note_count])
- end
-
- def set_follower_count(info, number) do
- params = %{follower_count: Enum.max([0, number])}
-
- info
- |> cast(params, [:follower_count])
- |> validate_required([:follower_count])
- end
-
- def set_mutes(info, mutes) do
- params = %{mutes: mutes}
-
- info
- |> cast(params, [:mutes])
- |> validate_required([:mutes])
- end
-
- @spec set_notification_mutes(Changeset.t(), [String.t()], boolean()) :: Changeset.t()
- def set_notification_mutes(changeset, muted_notifications, notifications?) do
- if notifications? do
- put_change(changeset, :muted_notifications, muted_notifications)
- |> validate_required([:muted_notifications])
- else
- changeset
- end
- end
-
- def set_blocks(info, blocks) do
- params = %{blocks: blocks}
-
- info
- |> cast(params, [:blocks])
- |> validate_required([:blocks])
- end
-
- def set_subscribers(info, subscribers) do
- params = %{subscribers: subscribers}
-
- info
- |> cast(params, [:subscribers])
- |> validate_required([:subscribers])
- end
-
- @spec add_to_mutes(Info.t(), String.t(), boolean()) :: Changeset.t()
- def add_to_mutes(info, muted, notifications?) do
- info
- |> set_mutes(Enum.uniq([muted | info.mutes]))
- |> set_notification_mutes(
- Enum.uniq([muted | info.muted_notifications]),
- notifications?
- )
- end
-
- @spec remove_from_mutes(Info.t(), String.t()) :: Changeset.t()
- def remove_from_mutes(info, muted) do
- info
- |> set_mutes(List.delete(info.mutes, muted))
- |> set_notification_mutes(List.delete(info.muted_notifications, muted), true)
- end
-
- def add_to_block(info, blocked) do
- set_blocks(info, Enum.uniq([blocked | info.blocks]))
- end
-
- def remove_from_block(info, blocked) do
- set_blocks(info, List.delete(info.blocks, blocked))
- end
-
- def add_to_subscribers(info, subscribed) do
- set_subscribers(info, Enum.uniq([subscribed | info.subscribers]))
- end
-
- def remove_from_subscribers(info, subscribed) do
- set_subscribers(info, List.delete(info.subscribers, subscribed))
- end
-
- def set_domain_blocks(info, domain_blocks) do
- params = %{domain_blocks: domain_blocks}
-
- info
- |> cast(params, [:domain_blocks])
- |> validate_required([:domain_blocks])
- end
-
- def add_to_domain_block(info, domain_blocked) do
- set_domain_blocks(info, Enum.uniq([domain_blocked | info.domain_blocks]))
- end
-
- def remove_from_domain_block(info, domain_blocked) do
- set_domain_blocks(info, List.delete(info.domain_blocks, domain_blocked))
- end
-
- def set_keys(info, keys) do
- params = %{keys: keys}
-
- info
- |> cast(params, [:keys])
- |> validate_required([:keys])
- end
-
- def remote_user_creation(info, params) do
- params =
- if Map.has_key?(params, :fields) do
- Map.put(params, :fields, Enum.map(params[:fields], &truncate_field/1))
- else
- params
- end
-
- info
- |> cast(params, [
- :ap_enabled,
- :source_data,
- :banner,
- :locked,
- :magic_key,
- :uri,
- :hide_followers,
- :hide_follows,
- :hide_followers_count,
- :hide_follows_count,
- :follower_count,
- :fields,
- :following_count,
- :discoverable,
- :invisible
- ])
- |> validate_fields(true)
- end
-
- def user_upgrade(info, params, remote? \\ false) do
- info
- |> cast(params, [
- :ap_enabled,
- :source_data,
- :banner,
- :locked,
- :magic_key,
- :follower_count,
- :following_count,
- :hide_follows,
- :fields,
- :hide_followers,
- :discoverable,
- :hide_followers_count,
- :hide_follows_count
- ])
- |> validate_fields(remote?)
- end
-
- def profile_update(info, params) do
- info
- |> cast(params, [
- :locked,
- :no_rich_text,
- :default_scope,
- :banner,
- :hide_follows,
- :hide_followers,
- :hide_followers_count,
- :hide_follows_count,
- :hide_favorites,
- :background,
- :show_role,
- :skip_thread_containment,
- :fields,
- :raw_fields,
- :pleroma_settings_store,
- :discoverable
- ])
- |> validate_fields()
- end
-
- def validate_fields(changeset, remote? \\ false) do
- limit_name = if remote?, do: :max_remote_account_fields, else: :max_account_fields
- limit = Pleroma.Config.get([:instance, limit_name], 0)
-
- changeset
- |> validate_length(:fields, max: limit)
- |> validate_change(:fields, fn :fields, fields ->
- if Enum.all?(fields, &valid_field?/1) do
- []
- else
- [fields: "invalid"]
- end
- end)
- end
-
- defp valid_field?(%{"name" => name, "value" => value}) do
- name_limit = Pleroma.Config.get([:instance, :account_field_name_length], 255)
- value_limit = Pleroma.Config.get([:instance, :account_field_value_length], 255)
-
- is_binary(name) && is_binary(value) && String.length(name) <= name_limit &&
- String.length(value) <= value_limit
- end
-
- defp valid_field?(_), do: false
-
- defp truncate_field(%{"name" => name, "value" => value}) do
- {name, _chopped} =
- String.split_at(name, Pleroma.Config.get([:instance, :account_field_name_length], 255))
-
- {value, _chopped} =
- String.split_at(value, Pleroma.Config.get([:instance, :account_field_value_length], 255))
-
- %{"name" => name, "value" => value}
- end
-
- @spec confirmation_changeset(Info.t(), keyword()) :: Changeset.t()
- def confirmation_changeset(info, opts) do
- need_confirmation? = Keyword.get(opts, :need_confirmation)
-
- params =
- if need_confirmation? do
- %{
- confirmation_pending: true,
- confirmation_token: :crypto.strong_rand_bytes(32) |> Base.url_encode64()
- }
- else
- %{
- confirmation_pending: false,
- confirmation_token: nil
- }
- end
-
- cast(info, params, [:confirmation_pending, :confirmation_token])
- end
-
- def mastodon_settings_update(info, settings) do
- params = %{settings: settings}
-
- info
- |> cast(params, [:settings])
- |> validate_required([:settings])
- end
-
- def mascot_update(info, url) do
- params = %{mascot: url}
-
- info
- |> cast(params, [:mascot])
- |> validate_required([:mascot])
- end
-
- def set_source_data(info, source_data) do
- params = %{source_data: source_data}
-
- info
- |> cast(params, [:source_data])
- |> validate_required([:source_data])
- end
-
- def set_invisible(info, invisible) do
- params = %{invisible: invisible}
-
- info
- |> cast(params, [:invisible])
- |> validate_required([:invisible])
- end
-
- def admin_api_update(info, params) do
- info
- |> cast(params, [
- :is_moderator,
- :is_admin,
- :show_role
- ])
- end
-
- def add_pinnned_activity(info, %Pleroma.Activity{id: id}) do
- if id not in info.pinned_activities do
- max_pinned_statuses = Pleroma.Config.get([:instance, :max_pinned_statuses], 0)
- params = %{pinned_activities: info.pinned_activities ++ [id]}
-
- info
- |> cast(params, [:pinned_activities])
- |> validate_length(:pinned_activities,
- max: max_pinned_statuses,
- message: "You have already pinned the maximum number of statuses"
- )
- else
- change(info)
- end
- end
-
- def remove_pinnned_activity(info, %Pleroma.Activity{id: id}) do
- params = %{pinned_activities: List.delete(info.pinned_activities, id)}
-
- cast(info, params, [:pinned_activities])
- end
-
- def roles(%Info{is_moderator: is_moderator, is_admin: is_admin}) do
- %{
- admin: is_admin,
- moderator: is_moderator
- }
- end
-
- def add_reblog_mute(info, ap_id) do
- params = %{muted_reblogs: info.muted_reblogs ++ [ap_id]}
-
- cast(info, params, [:muted_reblogs])
- end
-
- def remove_reblog_mute(info, ap_id) do
- params = %{muted_reblogs: List.delete(info.muted_reblogs, ap_id)}
-
- cast(info, params, [:muted_reblogs])
- end
-
- # ``fields`` is an array of mastodon profile field, containing ``{"name": "…", "value": "…"}``.
- # For example: [{"name": "Pronoun", "value": "she/her"}, …]
- def fields(%{fields: nil, source_data: %{"attachment" => attachment}}) do
- limit = Pleroma.Config.get([:instance, :max_remote_account_fields], 0)
-
- attachment
- |> Enum.filter(fn %{"type" => t} -> t == "PropertyValue" end)
- |> Enum.map(fn fields -> Map.take(fields, ["name", "value"]) end)
- |> Enum.take(limit)
- end
-
- def fields(%{fields: nil}), do: []
-
- def fields(%{fields: fields}), do: fields
-
- def follow_information_update(info, params) do
- info
- |> cast(params, [
- :hide_followers,
- :hide_follows,
- :follower_count,
- :following_count,
- :hide_followers_count,
- :hide_follows_count
- ])
- end
-end
diff --git a/lib/pleroma/user/query.ex b/lib/pleroma/user/query.ex
index 2baf016cf..7f5273c4e 100644
--- a/lib/pleroma/user/query.ex
+++ b/lib/pleroma/user/query.ex
@@ -56,7 +56,6 @@ defmodule Pleroma.User.Query do
@ilike_criteria [:nickname, :name, :query]
@equal_criteria [:email]
- @role_criteria [:is_admin, :is_moderator]
@contains_criteria [:ap_id, :nickname]
@spec build(criteria()) :: Query.t()
@@ -100,15 +99,19 @@ defmodule Pleroma.User.Query do
Enum.reduce(tags, query, &prepare_tag_criteria/2)
end
- defp compose_query({key, _}, query) when key in @role_criteria do
- where(query, [u], fragment("(?->? @> 'true')", u.info, ^to_string(key)))
+ defp compose_query({:is_admin, _}, query) do
+ where(query, [u], u.is_admin)
+ end
+
+ defp compose_query({:is_moderator, _}, query) do
+ where(query, [u], u.is_moderator)
end
defp compose_query({:super_users, _}, query) do
where(
query,
[u],
- fragment("?->'is_admin' @> 'true' OR ?->'is_moderator' @> 'true'", u.info, u.info)
+ u.is_admin or u.is_moderator
)
end
@@ -117,7 +120,13 @@ defmodule Pleroma.User.Query do
defp compose_query({:external, _}, query), do: location_query(query, false)
defp compose_query({:active, _}, query) do
- where(query, [u], fragment("not (?->'deactivated' @> 'true')", u.info))
+ User.restrict_deactivated(query)
+ |> where([u], not is_nil(u.nickname))
+ end
+
+ defp compose_query({:legacy_active, _}, query) do
+ query
+ |> where([u], fragment("not (?->'deactivated' @> 'true')", u.info))
|> where([u], not is_nil(u.nickname))
end
@@ -126,7 +135,7 @@ defmodule Pleroma.User.Query do
end
defp compose_query({:deactivated, true}, query) do
- where(query, [u], fragment("?->'deactivated' @> 'true'", u.info))
+ where(query, [u], u.deactivated == ^true)
|> where([u], not is_nil(u.nickname))
end
diff --git a/lib/pleroma/user/search.ex b/lib/pleroma/user/search.ex
index 0d697fe3d..bab8d92e2 100644
--- a/lib/pleroma/user/search.ex
+++ b/lib/pleroma/user/search.ex
@@ -108,14 +108,14 @@ defmodule Pleroma.User.Search do
defp base_query(_user, false), do: User
defp base_query(user, true), do: User.get_followers_query(user)
- defp filter_blocked_user(query, %User{info: %{blocks: blocks}})
+ defp filter_blocked_user(query, %User{blocks: blocks})
when length(blocks) > 0 do
from(q in query, where: not (q.ap_id in ^blocks))
end
defp filter_blocked_user(query, _), do: query
- defp filter_blocked_domains(query, %User{info: %{domain_blocks: domain_blocks}})
+ defp filter_blocked_domains(query, %User{domain_blocks: domain_blocks})
when length(domain_blocks) > 0 do
domains = Enum.join(domain_blocks, ",")
diff --git a/lib/pleroma/web/activity_pub/activity_pub.ex b/lib/pleroma/web/activity_pub/activity_pub.ex
index 9a0a3522a..07dde3537 100644
--- a/lib/pleroma/web/activity_pub/activity_pub.ex
+++ b/lib/pleroma/web/activity_pub/activity_pub.ex
@@ -69,7 +69,7 @@ defmodule Pleroma.Web.ActivityPub.ActivityPub do
defp check_actor_is_active(actor) do
if not is_nil(actor) do
with user <- User.get_cached_by_ap_id(actor),
- false <- user.info.deactivated do
+ false <- user.deactivated do
true
else
_e -> false
@@ -248,8 +248,6 @@ defmodule Pleroma.Web.ActivityPub.ActivityPub do
_ <- increase_replies_count_if_reply(create_data),
_ <- increase_poll_votes_if_vote(create_data),
{:quick_insert, false, activity} <- {:quick_insert, quick_insert?, activity},
- # Changing note count prior to enqueuing federation task in order to avoid
- # race conditions on updating user.info
{:ok, _actor} <- increase_note_count_if_public(actor, activity),
:ok <- maybe_federate(activity) do
{:ok, activity}
@@ -445,8 +443,6 @@ defmodule Pleroma.Web.ActivityPub.ActivityPub do
{:ok, activity} <- insert(data, local, false),
stream_out_participations(object, user),
_ <- decrease_replies_count_if_reply(object),
- # Changing note count prior to enqueuing federation task in order to avoid
- # race conditions on updating user.info
{:ok, _actor} <- decrease_note_count_if_public(user, object),
:ok <- maybe_federate(activity) do
{:ok, activity}
@@ -660,7 +656,7 @@ defmodule Pleroma.Web.ActivityPub.ActivityPub do
defp restrict_thread_visibility(
query,
- %{"user" => %User{info: %{skip_thread_containment: true}}},
+ %{"user" => %User{skip_thread_containment: true}},
_
),
do: query
@@ -698,7 +694,7 @@ defmodule Pleroma.Web.ActivityPub.ActivityPub do
|> Map.put("user", reading_user)
|> Map.put("actor_id", user.ap_id)
|> Map.put("whole_db", true)
- |> Map.put("pinned_activity_ids", user.info.pinned_activities)
+ |> Map.put("pinned_activity_ids", user.pinned_activities)
recipients =
user_activities_recipients(%{
@@ -859,8 +855,8 @@ defmodule Pleroma.Web.ActivityPub.ActivityPub do
defp restrict_muted(query, %{"with_muted" => val}) when val in [true, "true", "1"], do: query
- defp restrict_muted(query, %{"muting_user" => %User{info: info}} = opts) do
- mutes = info.mutes
+ defp restrict_muted(query, %{"muting_user" => %User{} = user} = opts) do
+ mutes = user.mutes
query =
from([activity] in query,
@@ -877,9 +873,9 @@ defmodule Pleroma.Web.ActivityPub.ActivityPub do
defp restrict_muted(query, _), do: query
- defp restrict_blocked(query, %{"blocking_user" => %User{info: info}}) do
- blocks = info.blocks || []
- domain_blocks = info.domain_blocks || []
+ defp restrict_blocked(query, %{"blocking_user" => %User{} = user}) do
+ blocks = user.blocks || []
+ domain_blocks = user.domain_blocks || []
query =
if has_named_binding?(query, :object), do: query, else: Activity.with_joined_object(query)
@@ -920,8 +916,8 @@ defmodule Pleroma.Web.ActivityPub.ActivityPub do
defp restrict_pinned(query, _), do: query
- defp restrict_muted_reblogs(query, %{"muting_user" => %User{info: info}}) do
- muted_reblogs = info.muted_reblogs || []
+ defp restrict_muted_reblogs(query, %{"muting_user" => %User{} = user}) do
+ muted_reblogs = user.muted_reblogs || []
from(
activity in query,
@@ -1110,15 +1106,13 @@ defmodule Pleroma.Web.ActivityPub.ActivityPub do
user_data = %{
ap_id: data["id"],
- info: %{
- ap_enabled: true,
- source_data: data,
- banner: banner,
- fields: fields,
- locked: locked,
- discoverable: discoverable,
- invisible: invisible
- },
+ ap_enabled: true,
+ source_data: data,
+ banner: banner,
+ fields: fields,
+ locked: locked,
+ discoverable: discoverable,
+ invisible: invisible,
avatar: avatar,
name: data["name"],
follower_address: data["followers"],
@@ -1170,7 +1164,7 @@ defmodule Pleroma.Web.ActivityPub.ActivityPub do
with {:enabled, true} <-
{:enabled, Pleroma.Config.get([:instance, :external_user_synchronization])},
{:ok, info} <- fetch_follow_information_for_user(data) do
- info = Map.merge(data.info, info)
+ info = Map.merge(data[:info] || %{}, info)
Map.put(data, :info, info)
else
{:enabled, false} ->
diff --git a/lib/pleroma/web/activity_pub/activity_pub_controller.ex b/lib/pleroma/web/activity_pub/activity_pub_controller.ex
index 080030eb5..568623318 100644
--- a/lib/pleroma/web/activity_pub/activity_pub_controller.ex
+++ b/lib/pleroma/web/activity_pub/activity_pub_controller.ex
@@ -137,7 +137,7 @@ defmodule Pleroma.Web.ActivityPub.ActivityPubController do
with %User{} = user <- User.get_cached_by_nickname(nickname),
{user, for_user} <- ensure_user_keys_present_and_maybe_refresh_for_user(user, for_user),
{:show_follows, true} <-
- {:show_follows, (for_user && for_user == user) || !user.info.hide_follows} do
+ {:show_follows, (for_user && for_user == user) || !user.hide_follows} do
{page, _} = Integer.parse(page)
conn
@@ -174,7 +174,7 @@ defmodule Pleroma.Web.ActivityPub.ActivityPubController do
with %User{} = user <- User.get_cached_by_nickname(nickname),
{user, for_user} <- ensure_user_keys_present_and_maybe_refresh_for_user(user, for_user),
{:show_followers, true} <-
- {:show_followers, (for_user && for_user == user) || !user.info.hide_followers} do
+ {:show_followers, (for_user && for_user == user) || !user.hide_followers} do
{page, _} = Integer.parse(page)
conn
@@ -387,7 +387,7 @@ defmodule Pleroma.Web.ActivityPub.ActivityPubController do
def handle_user_activity(user, %{"type" => "Delete"} = params) do
with %Object{} = object <- Object.normalize(params["object"]),
- true <- user.info.is_moderator || user.ap_id == object.data["actor"],
+ true <- user.is_moderator || user.ap_id == object.data["actor"],
{:ok, delete} <- ActivityPub.delete(object) do
{:ok, delete}
else
diff --git a/lib/pleroma/web/activity_pub/mrf/anti_link_spam_policy.ex b/lib/pleroma/web/activity_pub/mrf/anti_link_spam_policy.ex
index b90193ca0..8abe18e29 100644
--- a/lib/pleroma/web/activity_pub/mrf/anti_link_spam_policy.ex
+++ b/lib/pleroma/web/activity_pub/mrf/anti_link_spam_policy.ex
@@ -11,7 +11,7 @@ defmodule Pleroma.Web.ActivityPub.MRF.AntiLinkSpamPolicy do
# has the user successfully posted before?
defp old_user?(%User{} = u) do
- u.info.note_count > 0 || u.info.follower_count > 0
+ u.note_count > 0 || u.follower_count > 0
end
# does the post contain links?
diff --git a/lib/pleroma/web/activity_pub/publisher.ex b/lib/pleroma/web/activity_pub/publisher.ex
index 2aac4e8b9..4ea37fc7b 100644
--- a/lib/pleroma/web/activity_pub/publisher.ex
+++ b/lib/pleroma/web/activity_pub/publisher.ex
@@ -140,7 +140,7 @@ defmodule Pleroma.Web.ActivityPub.Publisher do
|> Enum.map(& &1.ap_id)
end
- defp maybe_use_sharedinbox(%User{info: %{source_data: data}}),
+ defp maybe_use_sharedinbox(%User{source_data: data}),
do: (is_map(data["endpoints"]) && Map.get(data["endpoints"], "sharedInbox")) || data["inbox"]
@doc """
@@ -156,7 +156,7 @@ defmodule Pleroma.Web.ActivityPub.Publisher do
"""
def determine_inbox(
%Activity{data: activity_data},
- %User{info: %{source_data: data}} = user
+ %User{source_data: data} = user
) do
to = activity_data["to"] || []
cc = activity_data["cc"] || []
@@ -190,12 +190,12 @@ defmodule Pleroma.Web.ActivityPub.Publisher do
recipients
|> Enum.filter(&User.ap_enabled?/1)
- |> Enum.map(fn %{info: %{source_data: data}} -> data["inbox"] end)
+ |> Enum.map(fn %{source_data: data} -> data["inbox"] end)
|> Enum.filter(fn inbox -> should_federate?(inbox, public) end)
|> Instances.filter_reachable()
|> Enum.each(fn {inbox, unreachable_since} ->
%User{ap_id: ap_id} =
- Enum.find(recipients, fn %{info: %{source_data: data}} -> data["inbox"] == inbox end)
+ Enum.find(recipients, fn %{source_data: data} -> data["inbox"] == inbox end)
# Get all the recipients on the same host and add them to cc. Otherwise, a remote
# instance would only accept a first message for the first recipient and ignore the rest.
diff --git a/lib/pleroma/web/activity_pub/relay.ex b/lib/pleroma/web/activity_pub/relay.ex
index de80612f1..a9434d75c 100644
--- a/lib/pleroma/web/activity_pub/relay.ex
+++ b/lib/pleroma/web/activity_pub/relay.ex
@@ -14,7 +14,7 @@ defmodule Pleroma.Web.ActivityPub.Relay do
"#{Pleroma.Web.Endpoint.url()}/relay"
|> User.get_or_create_service_actor_by_ap_id()
- {:ok, actor} = User.update_info(actor, &User.Info.set_invisible(&1, true))
+ {:ok, actor} = User.set_invisible(actor, true)
actor
end
diff --git a/lib/pleroma/web/activity_pub/transmogrifier.ex b/lib/pleroma/web/activity_pub/transmogrifier.ex
index 4a250d131..9b3ee842b 100644
--- a/lib/pleroma/web/activity_pub/transmogrifier.ex
+++ b/lib/pleroma/web/activity_pub/transmogrifier.ex
@@ -605,10 +605,9 @@ defmodule Pleroma.Web.ActivityPub.Transmogrifier do
with %User{ap_id: ^actor_id} = actor <- User.get_cached_by_ap_id(object["id"]) do
{:ok, new_user_data} = ActivityPub.user_data_from_user_object(object)
- banner = new_user_data[:info][:banner]
- locked = new_user_data[:info][:locked] || false
- attachment = get_in(new_user_data, [:info, :source_data, "attachment"]) || []
- invisible = new_user_data[:info][:invisible] || false
+ locked = new_user_data[:locked] || false
+ attachment = get_in(new_user_data, [:source_data, "attachment"]) || []
+ invisible = new_user_data[:invisible] || false
fields =
attachment
@@ -617,8 +616,10 @@ defmodule Pleroma.Web.ActivityPub.Transmogrifier do
update_data =
new_user_data
- |> Map.take([:name, :bio, :avatar])
- |> Map.put(:info, %{banner: banner, locked: locked, fields: fields, invisible: invisible})
+ |> Map.take([:avatar, :banner, :bio, :name])
+ |> Map.put(:fields, fields)
+ |> Map.put(:locked, locked)
+ |> Map.put(:invisible, invisible)
actor
|> User.upgrade_changeset(update_data, true)
@@ -985,7 +986,7 @@ defmodule Pleroma.Web.ActivityPub.Transmogrifier do
%{"type" => "Mention", "href" => ap_id, "name" => "@#{nickname}"}
end
- def take_emoji_tags(%User{info: %{emoji: emoji} = _user_info} = _user) do
+ def take_emoji_tags(%User{emoji: emoji}) do
emoji
|> Enum.flat_map(&Map.to_list/1)
|> Enum.map(&build_emoji_tag/1)
diff --git a/lib/pleroma/web/activity_pub/views/user_view.ex b/lib/pleroma/web/activity_pub/views/user_view.ex
index 8c5b4460b..cf08045c9 100644
--- a/lib/pleroma/web/activity_pub/views/user_view.ex
+++ b/lib/pleroma/web/activity_pub/views/user_view.ex
@@ -79,8 +79,8 @@ defmodule Pleroma.Web.ActivityPub.UserView do
emoji_tags = Transmogrifier.take_emoji_tags(user)
fields =
- user.info
- |> User.Info.fields()
+ user
+ |> User.fields()
|> Enum.map(fn %{"name" => name, "value" => value} ->
%{
"name" => Pleroma.HTML.strip_tags(name),
@@ -100,7 +100,7 @@ defmodule Pleroma.Web.ActivityPub.UserView do
"name" => user.name,
"summary" => user.bio,
"url" => user.ap_id,
- "manuallyApprovesFollowers" => user.info.locked,
+ "manuallyApprovesFollowers" => user.locked,
"publicKey" => %{
"id" => "#{user.ap_id}#main-key",
"owner" => user.ap_id,
@@ -108,8 +108,8 @@ defmodule Pleroma.Web.ActivityPub.UserView do
},
"endpoints" => endpoints,
"attachment" => fields,
- "tag" => (user.info.source_data["tag"] || []) ++ emoji_tags,
- "discoverable" => user.info.discoverable
+ "tag" => (user.source_data["tag"] || []) ++ emoji_tags,
+ "discoverable" => user.discoverable
}
|> Map.merge(maybe_make_image(&User.avatar_url/2, "icon", user))
|> Map.merge(maybe_make_image(&User.banner_url/2, "image", user))
@@ -117,8 +117,8 @@ defmodule Pleroma.Web.ActivityPub.UserView do
end
def render("following.json", %{user: user, page: page} = opts) do
- showing_items = (opts[:for] && opts[:for] == user) || !user.info.hide_follows
- showing_count = showing_items || !user.info.hide_follows_count
+ showing_items = (opts[:for] && opts[:for] == user) || !user.hide_follows
+ showing_count = showing_items || !user.hide_follows_count
query = User.get_friends_query(user)
query = from(user in query, select: [:ap_id])
@@ -136,8 +136,8 @@ defmodule Pleroma.Web.ActivityPub.UserView do
end
def render("following.json", %{user: user} = opts) do
- showing_items = (opts[:for] && opts[:for] == user) || !user.info.hide_follows
- showing_count = showing_items || !user.info.hide_follows_count
+ showing_items = (opts[:for] && opts[:for] == user) || !user.hide_follows
+ showing_count = showing_items || !user.hide_follows_count
query = User.get_friends_query(user)
query = from(user in query, select: [:ap_id])
@@ -156,7 +156,7 @@ defmodule Pleroma.Web.ActivityPub.UserView do
"totalItems" => total,
"first" =>
if showing_items do
- collection(following, "#{user.ap_id}/following", 1, !user.info.hide_follows)
+ collection(following, "#{user.ap_id}/following", 1, !user.hide_follows)
else
"#{user.ap_id}/following?page=1"
end
@@ -165,8 +165,8 @@ defmodule Pleroma.Web.ActivityPub.UserView do
end
def render("followers.json", %{user: user, page: page} = opts) do
- showing_items = (opts[:for] && opts[:for] == user) || !user.info.hide_followers
- showing_count = showing_items || !user.info.hide_followers_count
+ showing_items = (opts[:for] && opts[:for] == user) || !user.hide_followers
+ showing_count = showing_items || !user.hide_followers_count
query = User.get_followers_query(user)
query = from(user in query, select: [:ap_id])
@@ -184,8 +184,8 @@ defmodule Pleroma.Web.ActivityPub.UserView do
end
def render("followers.json", %{user: user} = opts) do
- showing_items = (opts[:for] && opts[:for] == user) || !user.info.hide_followers
- showing_count = showing_items || !user.info.hide_followers_count
+ showing_items = (opts[:for] && opts[:for] == user) || !user.hide_followers
+ showing_count = showing_items || !user.hide_followers_count
query = User.get_followers_query(user)
query = from(user in query, select: [:ap_id])
diff --git a/lib/pleroma/web/admin_api/admin_api_controller.ex b/lib/pleroma/web/admin_api/admin_api_controller.ex
index b6d3f79c8..7ffbb23e7 100644
--- a/lib/pleroma/web/admin_api/admin_api_controller.ex
+++ b/lib/pleroma/web/admin_api/admin_api_controller.ex
@@ -51,8 +51,7 @@ defmodule Pleroma.Web.AdminAPI.AdminAPIController do
:tag_users,
:untag_users,
:right_add,
- :right_delete,
- :set_activation_status
+ :right_delete
]
)
@@ -250,9 +249,9 @@ defmodule Pleroma.Web.AdminAPI.AdminAPIController do
def user_toggle_activation(%{assigns: %{user: admin}} = conn, %{"nickname" => nickname}) do
user = User.get_cached_by_nickname(nickname)
- {:ok, updated_user} = User.deactivate(user, !user.info.deactivated)
+ {:ok, updated_user} = User.deactivate(user, !user.deactivated)
- action = if user.info.deactivated, do: "activate", else: "deactivate"
+ action = if user.deactivated, do: "activate", else: "deactivate"
ModerationLog.insert_log(%{
actor: admin,
@@ -364,11 +363,11 @@ defmodule Pleroma.Web.AdminAPI.AdminAPIController do
"nicknames" => nicknames
})
when permission_group in ["moderator", "admin"] do
- info = Map.put(%{}, "is_" <> permission_group, true)
+ update = %{:"is_#{permission_group}" => true}
users = nicknames |> Enum.map(&User.get_cached_by_nickname/1)
- User.update_info(users, &User.Info.admin_api_update(&1, info))
+ for u <- users, do: User.admin_api_update(u, update)
ModerationLog.insert_log(%{
action: "grant",
@@ -377,7 +376,7 @@ defmodule Pleroma.Web.AdminAPI.AdminAPIController do
permission: permission_group
})
- json(conn, info)
+ json(conn, update)
end
def right_add_multiple(conn, _) do
@@ -389,12 +388,12 @@ defmodule Pleroma.Web.AdminAPI.AdminAPIController do
"nickname" => nickname
})
when permission_group in ["moderator", "admin"] do
- info = Map.put(%{}, "is_" <> permission_group, true)
+ fields = %{:"is_#{permission_group}" => true}
{:ok, user} =
nickname
|> User.get_cached_by_nickname()
- |> User.update_info(&User.Info.admin_api_update(&1, info))
+ |> User.admin_api_update(fields)
ModerationLog.insert_log(%{
action: "grant",
@@ -403,7 +402,7 @@ defmodule Pleroma.Web.AdminAPI.AdminAPIController do
permission: permission_group
})
- json(conn, info)
+ json(conn, fields)
end
def right_add(conn, _) do
@@ -415,8 +414,8 @@ defmodule Pleroma.Web.AdminAPI.AdminAPIController do
conn
|> json(%{
- is_moderator: user.info.is_moderator,
- is_admin: user.info.is_admin
+ is_moderator: user.is_moderator,
+ is_admin: user.is_admin
})
end
@@ -429,11 +428,11 @@ defmodule Pleroma.Web.AdminAPI.AdminAPIController do
)
when permission_group in ["moderator", "admin"] do
with false <- Enum.member?(nicknames, admin_nickname) do
- info = Map.put(%{}, "is_" <> permission_group, false)
+ update = %{:"is_#{permission_group}" => false}
users = nicknames |> Enum.map(&User.get_cached_by_nickname/1)
- User.update_info(users, &User.Info.admin_api_update(&1, info))
+ for u <- users, do: User.admin_api_update(u, update)
ModerationLog.insert_log(%{
action: "revoke",
@@ -442,7 +441,7 @@ defmodule Pleroma.Web.AdminAPI.AdminAPIController do
permission: permission_group
})
- json(conn, info)
+ json(conn, update)
else
_ -> render_error(conn, :forbidden, "You can't revoke your own admin/moderator status.")
end
@@ -460,12 +459,12 @@ defmodule Pleroma.Web.AdminAPI.AdminAPIController do
}
)
when permission_group in ["moderator", "admin"] do
- info = Map.put(%{}, "is_" <> permission_group, false)
+ fields = %{:"is_#{permission_group}" => false}
{:ok, user} =
nickname
|> User.get_cached_by_nickname()
- |> User.update_info(&User.Info.admin_api_update(&1, info))
+ |> User.admin_api_update(fields)
ModerationLog.insert_log(%{
action: "revoke",
@@ -474,7 +473,7 @@ defmodule Pleroma.Web.AdminAPI.AdminAPIController do
permission: permission_group
})
- json(conn, info)
+ json(conn, fields)
end
def right_delete(%{assigns: %{user: %{nickname: nickname}}} = conn, %{"nickname" => nickname}) do
diff --git a/lib/pleroma/web/admin_api/views/account_view.ex b/lib/pleroma/web/admin_api/views/account_view.ex
index 441269162..6aa7257ce 100644
--- a/lib/pleroma/web/admin_api/views/account_view.ex
+++ b/lib/pleroma/web/admin_api/views/account_view.ex
@@ -7,7 +7,6 @@ defmodule Pleroma.Web.AdminAPI.AccountView do
alias Pleroma.HTML
alias Pleroma.User
- alias Pleroma.User.Info
alias Pleroma.Web.AdminAPI.AccountView
alias Pleroma.Web.MediaProxy
@@ -34,9 +33,9 @@ defmodule Pleroma.Web.AdminAPI.AccountView do
"avatar" => avatar,
"nickname" => user.nickname,
"display_name" => display_name,
- "deactivated" => user.info.deactivated,
+ "deactivated" => user.deactivated,
"local" => user.local,
- "roles" => Info.roles(user.info),
+ "roles" => User.roles(user),
"tags" => user.tags || []
}
end
diff --git a/lib/pleroma/web/common_api/common_api.ex b/lib/pleroma/web/common_api/common_api.ex
index 386408d51..449b808b5 100644
--- a/lib/pleroma/web/common_api/common_api.ex
+++ b/lib/pleroma/web/common_api/common_api.ex
@@ -263,10 +263,10 @@ defmodule Pleroma.Web.CommonAPI do
# Updates the emojis for a user based on their profile
def update(user) do
emoji = emoji_from_profile(user)
- source_data = user.info |> Map.get(:source_data, %{}) |> Map.put("tag", emoji)
+ source_data = Map.put(user.source_data, "tag", emoji)
user =
- case User.update_info(user, &User.Info.set_source_data(&1, source_data)) do
+ case User.update_source_data(user, source_data) do
{:ok, user} -> user
_ -> user
end
@@ -287,20 +287,20 @@ defmodule Pleroma.Web.CommonAPI do
object: %Object{data: %{"type" => "Note"}}
} = activity <- get_by_id_or_ap_id(id_or_ap_id),
true <- Visibility.is_public?(activity),
- {:ok, _user} <- User.update_info(user, &User.Info.add_pinnned_activity(&1, activity)) do
+ {:ok, _user} <- User.add_pinnned_activity(user, activity) do
{:ok, activity}
else
- {:error, %{changes: %{info: %{errors: [pinned_activities: {err, _}]}}}} -> {:error, err}
+ {:error, %{errors: [pinned_activities: {err, _}]}} -> {:error, err}
_ -> {:error, dgettext("errors", "Could not pin")}
end
end
def unpin(id_or_ap_id, user) do
with %Activity{} = activity <- get_by_id_or_ap_id(id_or_ap_id),
- {:ok, _user} <- User.update_info(user, &User.Info.remove_pinnned_activity(&1, activity)) do
+ {:ok, _user} <- User.remove_pinnned_activity(user, activity) do
{:ok, activity}
else
- %{errors: [pinned_activities: {err, _}]} -> {:error, err}
+ {:error, %{errors: [pinned_activities: {err, _}]}} -> {:error, err}
_ -> {:error, dgettext("errors", "Could not unpin")}
end
end
@@ -392,14 +392,14 @@ defmodule Pleroma.Web.CommonAPI do
defp set_visibility(activity, _), do: {:ok, activity}
def hide_reblogs(user, %{ap_id: ap_id} = _muted) do
- if ap_id not in user.info.muted_reblogs do
- User.update_info(user, &User.Info.add_reblog_mute(&1, ap_id))
+ if ap_id not in user.muted_reblogs do
+ User.add_reblog_mute(user, ap_id)
end
end
def show_reblogs(user, %{ap_id: ap_id} = _muted) do
- if ap_id in user.info.muted_reblogs do
- User.update_info(user, &User.Info.remove_reblog_mute(&1, ap_id))
+ if ap_id in user.muted_reblogs do
+ User.remove_reblog_mute(user, ap_id)
end
end
end
diff --git a/lib/pleroma/web/masto_fe_controller.ex b/lib/pleroma/web/masto_fe_controller.ex
index 93b38e8f4..ca261ad6e 100644
--- a/lib/pleroma/web/masto_fe_controller.ex
+++ b/lib/pleroma/web/masto_fe_controller.ex
@@ -42,7 +42,7 @@ defmodule Pleroma.Web.MastoFEController do
@doc "PUT /api/web/settings"
def put_settings(%{assigns: %{user: user}} = conn, %{"data" => settings} = _params) do
- with {:ok, _} <- User.update_info(user, &User.Info.mastodon_settings_update(&1, settings)) do
+ with {:ok, _} <- User.mastodon_settings_update(user, settings) do
json(conn, %{})
else
e ->
diff --git a/lib/pleroma/web/mastodon_api/controllers/account_controller.ex b/lib/pleroma/web/mastodon_api/controllers/account_controller.ex
index 9ef7fd48d..73fad519e 100644
--- a/lib/pleroma/web/mastodon_api/controllers/account_controller.ex
+++ b/lib/pleroma/web/mastodon_api/controllers/account_controller.ex
@@ -130,25 +130,6 @@ defmodule Pleroma.Web.MastodonAPI.AccountController do
def update_credentials(%{assigns: %{user: original_user}} = conn, params) do
user = original_user
- user_params =
- %{}
- |> add_if_present(params, "display_name", :name)
- |> add_if_present(params, "note", :bio, fn value -> {:ok, User.parse_bio(value, user)} end)
- |> add_if_present(params, "avatar", :avatar, fn value ->
- with %Plug.Upload{} <- value,
- {:ok, object} <- ActivityPub.upload(value, type: :avatar) do
- {:ok, object.data}
- end
- end)
-
- emojis_text = (user_params["display_name"] || "") <> (user_params["note"] || "")
-
- user_info_emojis =
- user.info
- |> Map.get(:emoji, [])
- |> Enum.concat(Emoji.Formatter.get_emoji_map(emojis_text))
- |> Enum.dedup()
-
params =
if Map.has_key?(params, "fields_attributes") do
Map.update!(params, "fields_attributes", fn fields ->
@@ -160,7 +141,7 @@ defmodule Pleroma.Web.MastodonAPI.AccountController do
params
end
- info_params =
+ user_params =
[
:no_rich_text,
:locked,
@@ -176,15 +157,13 @@ defmodule Pleroma.Web.MastodonAPI.AccountController do
|> Enum.reduce(%{}, fn key, acc ->
add_if_present(acc, params, to_string(key), key, &{:ok, truthy_param?(&1)})
end)
- |> add_if_present(params, "default_scope", :default_scope)
- |> add_if_present(params, "fields_attributes", :fields, fn fields ->
- fields = Enum.map(fields, fn f -> Map.update!(f, "value", &AutoLinker.link(&1)) end)
-
- {:ok, fields}
- end)
- |> add_if_present(params, "fields_attributes", :raw_fields)
- |> add_if_present(params, "pleroma_settings_store", :pleroma_settings_store, fn value ->
- {:ok, Map.merge(user.info.pleroma_settings_store, value)}
+ |> add_if_present(params, "display_name", :name)
+ |> add_if_present(params, "note", :bio, fn value -> {:ok, User.parse_bio(value, user)} end)
+ |> add_if_present(params, "avatar", :avatar, fn value ->
+ with %Plug.Upload{} <- value,
+ {:ok, object} <- ActivityPub.upload(value, type: :avatar) do
+ {:ok, object.data}
+ end
end)
|> add_if_present(params, "header", :banner, fn value ->
with %Plug.Upload{} <- value,
@@ -198,12 +177,27 @@ defmodule Pleroma.Web.MastodonAPI.AccountController do
{:ok, object.data}
end
end)
- |> Map.put(:emoji, user_info_emojis)
+ |> add_if_present(params, "fields_attributes", :fields, fn fields ->
+ fields = Enum.map(fields, fn f -> Map.update!(f, "value", &AutoLinker.link(&1)) end)
- changeset =
+ {:ok, fields}
+ end)
+ |> add_if_present(params, "fields_attributes", :raw_fields)
+ |> add_if_present(params, "pleroma_settings_store", :pleroma_settings_store, fn value ->
+ {:ok, Map.merge(user.pleroma_settings_store, value)}
+ end)
+ |> add_if_present(params, "default_scope", :default_scope)
+
+ emojis_text = (user_params["display_name"] || "") <> (user_params["note"] || "")
+
+ user_emojis =
user
- |> User.update_changeset(user_params)
- |> User.change_info(&User.Info.profile_update(&1, info_params))
+ |> Map.get(:emoji, [])
+ |> Enum.concat(Emoji.Formatter.get_emoji_map(emojis_text))
+ |> Enum.dedup()
+
+ user_params = Map.put(user_params, :emoji, user_emojis)
+ changeset = User.update_changeset(user, user_params)
with {:ok, user} <- User.update_and_set_cache(changeset) do
if original_user != user, do: CommonAPI.update(user)
@@ -269,7 +263,7 @@ defmodule Pleroma.Web.MastodonAPI.AccountController do
followers =
cond do
for_user && user.id == for_user.id -> MastodonAPI.get_followers(user, params)
- user.info.hide_followers -> []
+ user.hide_followers -> []
true -> MastodonAPI.get_followers(user, params)
end
@@ -283,7 +277,7 @@ defmodule Pleroma.Web.MastodonAPI.AccountController do
followers =
cond do
for_user && user.id == for_user.id -> MastodonAPI.get_friends(user, params)
- user.info.hide_follows -> []
+ user.hide_follows -> []
true -> MastodonAPI.get_friends(user, params)
end
diff --git a/lib/pleroma/web/mastodon_api/controllers/domain_block_controller.ex b/lib/pleroma/web/mastodon_api/controllers/domain_block_controller.ex
index c7606246b..456fe7ab2 100644
--- a/lib/pleroma/web/mastodon_api/controllers/domain_block_controller.ex
+++ b/lib/pleroma/web/mastodon_api/controllers/domain_block_controller.ex
@@ -21,8 +21,8 @@ defmodule Pleroma.Web.MastodonAPI.DomainBlockController do
plug(Pleroma.Plugs.EnsurePublicOrAuthenticatedPlug)
@doc "GET /api/v1/domain_blocks"
- def index(%{assigns: %{user: %{info: info}}} = conn, _) do
- json(conn, Map.get(info, :domain_blocks, []))
+ def index(%{assigns: %{user: user}} = conn, _) do
+ json(conn, Map.get(user, :domain_blocks, []))
end
@doc "POST /api/v1/domain_blocks"
diff --git a/lib/pleroma/web/mastodon_api/views/account_view.ex b/lib/pleroma/web/mastodon_api/views/account_view.ex
index 2d4976891..e30fed610 100644
--- a/lib/pleroma/web/mastodon_api/views/account_view.ex
+++ b/lib/pleroma/web/mastodon_api/views/account_view.ex
@@ -74,23 +74,23 @@ defmodule Pleroma.Web.MastodonAPI.AccountView do
user_info = User.get_cached_user_info(user)
following_count =
- if !user.info.hide_follows_count or !user.info.hide_follows or opts[:for] == user do
+ if !user.hide_follows_count or !user.hide_follows or opts[:for] == user do
user_info.following_count
else
0
end
followers_count =
- if !user.info.hide_followers_count or !user.info.hide_followers or opts[:for] == user do
+ if !user.hide_followers_count or !user.hide_followers or opts[:for] == user do
user_info.follower_count
else
0
end
- bot = (user.info.source_data["type"] || "Person") in ["Application", "Service"]
+ bot = (user.source_data["type"] || "Person") in ["Application", "Service"]
emojis =
- (user.info.source_data["tag"] || [])
+ (user.source_data["tag"] || [])
|> Enum.filter(fn %{"type" => t} -> t == "Emoji" end)
|> Enum.map(fn %{"icon" => %{"url" => url}, "name" => name} ->
%{
@@ -102,8 +102,8 @@ defmodule Pleroma.Web.MastodonAPI.AccountView do
end)
fields =
- user.info
- |> User.Info.fields()
+ user
+ |> User.fields()
|> Enum.map(fn %{"name" => name, "value" => value} ->
%{
"name" => Pleroma.HTML.strip_tags(name),
@@ -111,23 +111,19 @@ defmodule Pleroma.Web.MastodonAPI.AccountView do
}
end)
- raw_fields = Map.get(user.info, :raw_fields, [])
-
bio = HTML.filter_tags(user.bio, User.html_filter_policy(opts[:for]))
relationship = render("relationship.json", %{user: opts[:for], target: user})
- discoverable = user.info.discoverable
-
%{
id: to_string(user.id),
username: username_from_nickname(user.nickname),
acct: user.nickname,
display_name: display_name,
- locked: user_info.locked,
+ locked: user.locked,
created_at: Utils.to_masto_date(user.inserted_at),
followers_count: followers_count,
following_count: following_count,
- statuses_count: user_info.note_count,
+ statuses_count: user.note_count,
note: bio || "",
url: User.profile_url(user),
avatar: image,
@@ -140,9 +136,9 @@ defmodule Pleroma.Web.MastodonAPI.AccountView do
source: %{
note: HTML.strip_tags((user.bio || "") |> String.replace("<br>", "\n")),
sensitive: false,
- fields: raw_fields,
+ fields: user.raw_fields,
pleroma: %{
- discoverable: discoverable
+ discoverable: user.discoverable
}
},
@@ -150,14 +146,14 @@ defmodule Pleroma.Web.MastodonAPI.AccountView do
pleroma: %{
confirmation_pending: user_info.confirmation_pending,
tags: user.tags,
- hide_followers_count: user.info.hide_followers_count,
- hide_follows_count: user.info.hide_follows_count,
- hide_followers: user.info.hide_followers,
- hide_follows: user.info.hide_follows,
- hide_favorites: user.info.hide_favorites,
+ hide_followers_count: user.hide_followers_count,
+ hide_follows_count: user.hide_follows_count,
+ hide_followers: user.hide_followers,
+ hide_follows: user.hide_follows,
+ hide_favorites: user.hide_favorites,
relationship: relationship,
- skip_thread_containment: user.info.skip_thread_containment,
- background_image: image_url(user.info.background) |> MediaProxy.url()
+ skip_thread_containment: user.skip_thread_containment,
+ background_image: image_url(user.background) |> MediaProxy.url()
}
}
|> maybe_put_role(user, opts[:for])
@@ -195,21 +191,21 @@ defmodule Pleroma.Web.MastodonAPI.AccountView do
data,
%User{id: user_id} = user,
%User{id: user_id},
- user_info
+ _user_info
) do
data
- |> Kernel.put_in([:source, :privacy], user_info.default_scope)
- |> Kernel.put_in([:source, :pleroma, :show_role], user.info.show_role)
- |> Kernel.put_in([:source, :pleroma, :no_rich_text], user.info.no_rich_text)
+ |> Kernel.put_in([:source, :privacy], user.default_scope)
+ |> Kernel.put_in([:source, :pleroma, :show_role], user.show_role)
+ |> Kernel.put_in([:source, :pleroma, :no_rich_text], user.no_rich_text)
end
defp maybe_put_settings(data, _, _, _), do: data
- defp maybe_put_settings_store(data, %User{info: info, id: id}, %User{id: id}, %{
+ defp maybe_put_settings_store(data, %User{} = user, %User{}, %{
with_pleroma_settings: true
}) do
data
- |> Kernel.put_in([:pleroma, :settings_store], info.pleroma_settings_store)
+ |> Kernel.put_in([:pleroma, :settings_store], user.pleroma_settings_store)
end
defp maybe_put_settings_store(data, _, _, _), do: data
@@ -223,28 +219,28 @@ defmodule Pleroma.Web.MastodonAPI.AccountView do
defp maybe_put_chat_token(data, _, _, _), do: data
- defp maybe_put_role(data, %User{info: %{show_role: true}} = user, _) do
+ defp maybe_put_role(data, %User{show_role: true} = user, _) do
data
- |> Kernel.put_in([:pleroma, :is_admin], user.info.is_admin)
- |> Kernel.put_in([:pleroma, :is_moderator], user.info.is_moderator)
+ |> Kernel.put_in([:pleroma, :is_admin], user.is_admin)
+ |> Kernel.put_in([:pleroma, :is_moderator], user.is_moderator)
end
defp maybe_put_role(data, %User{id: user_id} = user, %User{id: user_id}) do
data
- |> Kernel.put_in([:pleroma, :is_admin], user.info.is_admin)
- |> Kernel.put_in([:pleroma, :is_moderator], user.info.is_moderator)
+ |> Kernel.put_in([:pleroma, :is_admin], user.is_admin)
+ |> Kernel.put_in([:pleroma, :is_moderator], user.is_moderator)
end
defp maybe_put_role(data, _, _), do: data
defp maybe_put_notification_settings(data, %User{id: user_id} = user, %User{id: user_id}) do
- Kernel.put_in(data, [:pleroma, :notification_settings], user.info.notification_settings)
+ Kernel.put_in(data, [:pleroma, :notification_settings], user.notification_settings)
end
defp maybe_put_notification_settings(data, _, _), do: data
- defp maybe_put_activation_status(data, user, %User{info: %{is_admin: true}}) do
- Kernel.put_in(data, [:pleroma, :deactivated], user.info.deactivated)
+ defp maybe_put_activation_status(data, user, %User{is_admin: true}) do
+ Kernel.put_in(data, [:pleroma, :deactivated], user.deactivated)
end
defp maybe_put_activation_status(data, _, _), do: data
@@ -253,7 +249,7 @@ defmodule Pleroma.Web.MastodonAPI.AccountView do
data
|> Kernel.put_in(
[:pleroma, :unread_conversation_count],
- user.info.unread_conversation_count
+ user.unread_conversation_count
)
end
diff --git a/lib/pleroma/web/mastodon_api/views/status_view.ex b/lib/pleroma/web/mastodon_api/views/status_view.ex
index 9b8dd3086..b785ca9d4 100644
--- a/lib/pleroma/web/mastodon_api/views/status_view.ex
+++ b/lib/pleroma/web/mastodon_api/views/status_view.ex
@@ -498,6 +498,6 @@ defmodule Pleroma.Web.MastodonAPI.StatusView do
defp present?(false), do: false
defp present?(_), do: true
- defp pinned?(%Activity{id: id}, %User{info: %{pinned_activities: pinned_activities}}),
+ defp pinned?(%Activity{id: id}, %User{pinned_activities: pinned_activities}),
do: id in pinned_activities
end
diff --git a/lib/pleroma/web/oauth/oauth_controller.ex b/lib/pleroma/web/oauth/oauth_controller.ex
index 03c9a5027..fe71aca8c 100644
--- a/lib/pleroma/web/oauth/oauth_controller.ex
+++ b/lib/pleroma/web/oauth/oauth_controller.ex
@@ -202,9 +202,9 @@ defmodule Pleroma.Web.OAuth.OAuthController do
with {:ok, %User{} = user} <- Authenticator.get_user(conn),
{:ok, app} <- Token.Utils.fetch_app(conn),
{:auth_active, true} <- {:auth_active, User.auth_active?(user)},
- {:user_active, true} <- {:user_active, !user.info.deactivated},
+ {:user_active, true} <- {:user_active, !user.deactivated},
{:password_reset_pending, false} <-
- {:password_reset_pending, user.info.password_reset_pending},
+ {:password_reset_pending, user.password_reset_pending},
{:ok, scopes} <- validate_scopes(app, params),
{:ok, auth} <- Authorization.create_authorization(app, user, scopes),
{:ok, token} <- Token.exchange_token(app, auth) do
diff --git a/lib/pleroma/web/pleroma_api/controllers/account_controller.ex b/lib/pleroma/web/pleroma_api/controllers/account_controller.ex
index 9012e2175..ee40bbf33 100644
--- a/lib/pleroma/web/pleroma_api/controllers/account_controller.ex
+++ b/lib/pleroma/web/pleroma_api/controllers/account_controller.ex
@@ -80,9 +80,7 @@ defmodule Pleroma.Web.PleromaAPI.AccountController do
@doc "PATCH /api/v1/pleroma/accounts/update_banner"
def update_banner(%{assigns: %{user: user}} = conn, %{"banner" => ""}) do
- new_info = %{"banner" => %{}}
-
- with {:ok, user} <- User.update_info(user, &User.Info.profile_update(&1, new_info)) do
+ with {:ok, user} <- User.update_banner(user, %{}) do
CommonAPI.update(user)
json(conn, %{url: nil})
end
@@ -90,8 +88,7 @@ defmodule Pleroma.Web.PleromaAPI.AccountController do
def update_banner(%{assigns: %{user: user}} = conn, params) do
with {:ok, object} <- ActivityPub.upload(%{"img" => params["banner"]}, type: :banner),
- new_info <- %{"banner" => object.data},
- {:ok, user} <- User.update_info(user, &User.Info.profile_update(&1, new_info)) do
+ {:ok, user} <- User.update_banner(user, object.data) do
CommonAPI.update(user)
%{"url" => [%{"href" => href} | _]} = object.data
@@ -101,17 +98,14 @@ defmodule Pleroma.Web.PleromaAPI.AccountController do
@doc "PATCH /api/v1/pleroma/accounts/update_background"
def update_background(%{assigns: %{user: user}} = conn, %{"img" => ""}) do
- new_info = %{"background" => %{}}
-
- with {:ok, _user} <- User.update_info(user, &User.Info.profile_update(&1, new_info)) do
+ with {:ok, _user} <- User.update_background(user, %{}) do
json(conn, %{url: nil})
end
end
def update_background(%{assigns: %{user: user}} = conn, params) do
with {:ok, object} <- ActivityPub.upload(params, type: :background),
- new_info <- %{"background" => object.data},
- {:ok, _user} <- User.update_info(user, &User.Info.profile_update(&1, new_info)) do
+ {:ok, _user} <- User.update_background(user, object.data) do
%{"url" => [%{"href" => href} | _]} = object.data
json(conn, %{url: href})
@@ -119,7 +113,7 @@ defmodule Pleroma.Web.PleromaAPI.AccountController do
end
@doc "GET /api/v1/pleroma/accounts/:id/favourites"
- def favourites(%{assigns: %{account: %{info: %{hide_favorites: true}}}} = conn, _params) do
+ def favourites(%{assigns: %{account: %{hide_favorites: true}}} = conn, _params) do
render_error(conn, :forbidden, "Can't get favorites")
end
diff --git a/lib/pleroma/web/pleroma_api/controllers/mascot_controller.ex b/lib/pleroma/web/pleroma_api/controllers/mascot_controller.ex
index d71d72dd5..8cf552b7e 100644
--- a/lib/pleroma/web/pleroma_api/controllers/mascot_controller.ex
+++ b/lib/pleroma/web/pleroma_api/controllers/mascot_controller.ex
@@ -24,9 +24,7 @@ defmodule Pleroma.Web.PleromaAPI.MascotController do
with {:ok, object} <- ActivityPub.upload(file, actor: User.ap_id(user)),
# Reject if not an image
%{type: "image"} = attachment <- render_attachment(object) do
- # Sure!
- # Save to the user's info
- {:ok, _user} = User.update_info(user, &User.Info.mascot_update(&1, attachment))
+ {:ok, _user} = User.mascot_update(user, attachment)
json(conn, attachment)
else
diff --git a/lib/pleroma/web/streamer/worker.ex b/lib/pleroma/web/streamer/worker.ex
index 0ea224874..c2ee9e1f5 100644
--- a/lib/pleroma/web/streamer/worker.ex
+++ b/lib/pleroma/web/streamer/worker.ex
@@ -129,12 +129,12 @@ defmodule Pleroma.Web.Streamer.Worker do
end
defp should_send?(%User{} = user, %Activity{} = item) do
- blocks = user.info.blocks || []
- mutes = user.info.mutes || []
- reblog_mutes = user.info.muted_reblogs || []
+ blocks = user.blocks || []
+ mutes = user.mutes || []
+ reblog_mutes = user.muted_reblogs || []
recipient_blocks = MapSet.new(blocks ++ mutes)
recipients = MapSet.new(item.recipients)
- domain_blocks = Pleroma.Web.ActivityPub.MRF.subdomains_regex(user.info.domain_blocks)
+ domain_blocks = Pleroma.Web.ActivityPub.MRF.subdomains_regex(user.domain_blocks)
with parent when not is_nil(parent) <- Object.normalize(item),
true <- Enum.all?([blocks, mutes, reblog_mutes], &(item.actor not in &1)),
@@ -212,7 +212,7 @@ defmodule Pleroma.Web.Streamer.Worker do
end
@spec thread_containment(Activity.t(), User.t()) :: boolean()
- defp thread_containment(_activity, %User{info: %{skip_thread_containment: true}}), do: true
+ defp thread_containment(_activity, %User{skip_thread_containment: true}), do: true
defp thread_containment(activity, user) do
if Config.get([:instance, :skip_thread_containment]) do
diff --git a/lib/pleroma/web/twitter_api/twitter_api_controller.ex b/lib/pleroma/web/twitter_api/twitter_api_controller.ex
index bf5a6ae42..39f10c49f 100644
--- a/lib/pleroma/web/twitter_api/twitter_api_controller.ex
+++ b/lib/pleroma/web/twitter_api/twitter_api_controller.ex
@@ -20,11 +20,12 @@ defmodule Pleroma.Web.TwitterAPI.Controller do
action_fallback(:errors)
def confirm_email(conn, %{"user_id" => uid, "token" => token}) do
- new_info = [need_confirmation: false]
-
- with %User{info: info} = user <- User.get_cached_by_id(uid),
- true <- user.local and info.confirmation_pending and info.confirmation_token == token,
- {:ok, _} <- User.update_info(user, &User.Info.confirmation_changeset(&1, new_info)) do
+ with %User{} = user <- User.get_cached_by_id(uid),
+ true <- user.local and user.confirmation_pending and user.confirmation_token == token,
+ {:ok, _} <-
+ user
+ |> User.confirmation_changeset(need_confirmation: false)
+ |> User.update_and_set_cache() do
redirect(conn, to: "/")
end
end
diff --git a/lib/pleroma/web/views/masto_fe_view.ex b/lib/pleroma/web/views/masto_fe_view.ex
index 85b164b59..c39b7f095 100644
--- a/lib/pleroma/web/views/masto_fe_view.ex
+++ b/lib/pleroma/web/views/masto_fe_view.ex
@@ -61,12 +61,12 @@ defmodule Pleroma.Web.MastoFEView do
},
poll_limits: Config.get([:instance, :poll_limits]),
rights: %{
- delete_others_notice: present?(user.info.is_moderator),
- admin: present?(user.info.is_admin)
+ delete_others_notice: present?(user.is_moderator),
+ admin: present?(user.is_admin)
},
compose: %{
me: "#{user.id}",
- default_privacy: user.info.default_scope,
+ default_privacy: user.default_scope,
default_sensitive: false,
allow_content_types: Config.get([:instance, :allowed_post_formats])
},
@@ -86,7 +86,7 @@ defmodule Pleroma.Web.MastoFEView do
"video\/mp4"
]
},
- settings: user.info.settings || @default_settings,
+ settings: user.settings || @default_settings,
push_subscription: nil,
accounts: %{user.id => render(AccountView, "show.json", user: user, for: user)},
custom_emojis: render(CustomEmojiView, "index.json", custom_emojis: custom_emojis),