Update/add OpenBSD config files
[akkoma] / lib / pleroma / user / info.ex
1 defmodule Pleroma.User.Info do
2 use Ecto.Schema
3 import Ecto.Changeset
4
5 embedded_schema do
6 field(:banner, :map, default: %{})
7 field(:background, :map, default: %{})
8 field(:source_data, :map, default: %{})
9 field(:note_count, :integer, default: 0)
10 field(:follower_count, :integer, default: 0)
11 field(:locked, :boolean, default: false)
12 field(:default_scope, :string, default: "public")
13 field(:blocks, {:array, :string}, default: [])
14 field(:domain_blocks, {:array, :string}, default: [])
15 field(:deactivated, :boolean, default: false)
16 field(:no_rich_text, :boolean, default: false)
17 field(:ap_enabled, :boolean, default: false)
18 field(:is_moderator, :boolean, default: false)
19 field(:is_admin, :boolean, default: false)
20 field(:keys, :string, default: nil)
21 field(:settings, :map, default: nil)
22 field(:magic_key, :string, default: nil)
23 field(:uri, :string, default: nil)
24 field(:topic, :string, default: nil)
25 field(:hub, :string, default: nil)
26 field(:salmon, :string, default: nil)
27 field(:hide_network, :boolean, default: false)
28
29 # Found in the wild
30 # ap_id -> Where is this used?
31 # bio -> Where is this used?
32 # avatar -> Where is this used?
33 # fqn -> Where is this used?
34 # host -> Where is this used?
35 # subject _> Where is this used?
36 end
37
38 def set_activation_status(info, deactivated) do
39 params = %{deactivated: deactivated}
40
41 info
42 |> cast(params, [:deactivated])
43 |> validate_required([:deactivated])
44 end
45
46 def add_to_note_count(info, number) do
47 set_note_count(info, info.note_count + number)
48 end
49
50 def set_note_count(info, number) do
51 params = %{note_count: Enum.max([0, number])}
52
53 info
54 |> cast(params, [:note_count])
55 |> validate_required([:note_count])
56 end
57
58 def set_follower_count(info, number) do
59 params = %{follower_count: Enum.max([0, number])}
60
61 info
62 |> cast(params, [:follower_count])
63 |> validate_required([:follower_count])
64 end
65
66 def set_blocks(info, blocks) do
67 params = %{blocks: blocks}
68
69 info
70 |> cast(params, [:blocks])
71 |> validate_required([:blocks])
72 end
73
74 def add_to_block(info, blocked) do
75 set_blocks(info, Enum.uniq([blocked | info.blocks]))
76 end
77
78 def remove_from_block(info, blocked) do
79 set_blocks(info, List.delete(info.blocks, blocked))
80 end
81
82 def set_domain_blocks(info, domain_blocks) do
83 params = %{domain_blocks: domain_blocks}
84
85 info
86 |> cast(params, [:domain_blocks])
87 |> validate_required([:domain_blocks])
88 end
89
90 def add_to_domain_block(info, domain_blocked) do
91 set_domain_blocks(info, Enum.uniq([domain_blocked | info.domain_blocks]))
92 end
93
94 def remove_from_domain_block(info, domain_blocked) do
95 set_domain_blocks(info, List.delete(info.domain_blocks, domain_blocked))
96 end
97
98 def set_keys(info, keys) do
99 params = %{keys: keys}
100
101 info
102 |> cast(params, [:keys])
103 |> validate_required([:keys])
104 end
105
106 def remote_user_creation(info, params) do
107 info
108 |> cast(params, [
109 :ap_enabled,
110 :source_data,
111 :banner,
112 :locked,
113 :magic_key,
114 :uri,
115 :hub,
116 :topic,
117 :salmon
118 ])
119 end
120
121 def user_upgrade(info, params) do
122 info
123 |> cast(params, [
124 :ap_enabled,
125 :source_data,
126 :banner,
127 :locked,
128 :magic_key
129 ])
130 end
131
132 def profile_update(info, params) do
133 info
134 |> cast(params, [
135 :locked,
136 :no_rich_text,
137 :default_scope,
138 :banner,
139 :hide_network,
140 :background
141 ])
142 end
143
144 def mastodon_profile_update(info, params) do
145 info
146 |> cast(params, [
147 :locked,
148 :banner
149 ])
150 end
151
152 def mastodon_settings_update(info, params) do
153 info
154 |> cast(params, [:settings])
155 end
156
157 def set_source_data(info, source_data) do
158 params = %{source_data: source_data}
159
160 info
161 |> cast(params, [:source_data])
162 |> validate_required([:source_data])
163 end
164
165 def admin_api_update(info, params) do
166 info
167 |> cast(params, [
168 :is_moderator,
169 :is_admin
170 ])
171 end
172 end