1 # Pleroma: A lightweight social networking server
2 # Copyright © 2017-2018 Pleroma Authors <https://pleroma.social/>
3 # SPDX-License-Identifier: AGPL-3.0-only
5 defmodule Pleroma.User.Info do
10 field(:banner, :map, default: %{})
11 field(:background, :map, default: %{})
12 field(:source_data, :map, default: %{})
13 field(:note_count, :integer, default: 0)
14 field(:follower_count, :integer, default: 0)
15 field(:locked, :boolean, default: false)
16 field(:confirmation_pending, :boolean, default: false)
17 field(:confirmation_token, :string, default: nil)
18 field(:default_scope, :string, default: "public")
19 field(:blocks, {:array, :string}, default: [])
20 field(:domain_blocks, {:array, :string}, default: [])
21 field(:deactivated, :boolean, default: false)
22 field(:no_rich_text, :boolean, default: false)
23 field(:ap_enabled, :boolean, default: false)
24 field(:is_moderator, :boolean, default: false)
25 field(:is_admin, :boolean, default: false)
26 field(:keys, :string, default: nil)
27 field(:settings, :map, default: nil)
28 field(:magic_key, :string, default: nil)
29 field(:uri, :string, default: nil)
30 field(:topic, :string, default: nil)
31 field(:hub, :string, default: nil)
32 field(:salmon, :string, default: nil)
33 field(:hide_network, :boolean, default: false)
36 # ap_id -> Where is this used?
37 # bio -> Where is this used?
38 # avatar -> Where is this used?
39 # fqn -> Where is this used?
40 # host -> Where is this used?
41 # subject _> Where is this used?
44 def superuser?(info), do: info.is_admin || info.is_moderator
46 def set_activation_status(info, deactivated) do
47 params = %{deactivated: deactivated}
50 |> cast(params, [:deactivated])
51 |> validate_required([:deactivated])
54 def add_to_note_count(info, number) do
55 set_note_count(info, info.note_count + number)
58 def set_note_count(info, number) do
59 params = %{note_count: Enum.max([0, number])}
62 |> cast(params, [:note_count])
63 |> validate_required([:note_count])
66 def set_follower_count(info, number) do
67 params = %{follower_count: Enum.max([0, number])}
70 |> cast(params, [:follower_count])
71 |> validate_required([:follower_count])
74 def set_blocks(info, blocks) do
75 params = %{blocks: blocks}
78 |> cast(params, [:blocks])
79 |> validate_required([:blocks])
82 def add_to_block(info, blocked) do
83 set_blocks(info, Enum.uniq([blocked | info.blocks]))
86 def remove_from_block(info, blocked) do
87 set_blocks(info, List.delete(info.blocks, blocked))
90 def set_domain_blocks(info, domain_blocks) do
91 params = %{domain_blocks: domain_blocks}
94 |> cast(params, [:domain_blocks])
95 |> validate_required([:domain_blocks])
98 def add_to_domain_block(info, domain_blocked) do
99 set_domain_blocks(info, Enum.uniq([domain_blocked | info.domain_blocks]))
102 def remove_from_domain_block(info, domain_blocked) do
103 set_domain_blocks(info, List.delete(info.domain_blocks, domain_blocked))
106 def set_keys(info, keys) do
107 params = %{keys: keys}
110 |> cast(params, [:keys])
111 |> validate_required([:keys])
114 def remote_user_creation(info, params) do
129 def user_upgrade(info, params) do
140 def profile_update(info, params) do
152 def confirmation_changeset(info, :confirmed) do
153 confirmation_changeset(info, %{
154 confirmation_pending: false,
155 confirmation_token: nil
159 def confirmation_changeset(info, :unconfirmed) do
160 confirmation_changeset(info, %{
161 confirmation_pending: true,
162 confirmation_token: :crypto.strong_rand_bytes(32) |> Base.url_encode64()
166 def confirmation_changeset(info, params) do
167 cast(info, params, [:confirmation_pending, :confirmation_token])
170 def mastodon_profile_update(info, params) do
178 def mastodon_settings_update(info, settings) do
179 params = %{settings: settings}
182 |> cast(params, [:settings])
183 |> validate_required([:settings])
186 def set_source_data(info, source_data) do
187 params = %{source_data: source_data}
190 |> cast(params, [:source_data])
191 |> validate_required([:source_data])
194 def admin_api_update(info, params) do