Formatting.

This commit is contained in:
lain 2018-11-18 18:27:04 +01:00
parent b396dba425
commit 756764266c
2 changed files with 33 additions and 24 deletions

View File

@ -23,7 +23,7 @@ defmodule Pleroma.User do
field(:search_distance, :float, virtual: true) field(:search_distance, :float, virtual: true)
field(:last_refreshed_at, :naive_datetime) field(:last_refreshed_at, :naive_datetime)
has_many(:notifications, Notification) has_many(:notifications, Notification)
embeds_one :info, Pleroma.User.Info embeds_one(:info, Pleroma.User.Info)
timestamps() timestamps()
end end
@ -412,16 +412,20 @@ def get_follow_requests(%User{} = user) do
def increase_note_count(%User{} = user) do def increase_note_count(%User{} = user) do
info_cng = User.Info.add_to_note_count(user.info, 1) info_cng = User.Info.add_to_note_count(user.info, 1)
cng = change(user)
|> put_embed(:info, info_cng) cng =
change(user)
|> put_embed(:info, info_cng)
update_and_set_cache(cng) update_and_set_cache(cng)
end end
def decrease_note_count(%User{} = user) do def decrease_note_count(%User{} = user) do
info_cng = User.Info.add_to_note_count(user.info, -1) info_cng = User.Info.add_to_note_count(user.info, -1)
cng = change(user)
|> put_embed(:info, info_cng) cng =
change(user)
|> put_embed(:info, info_cng)
update_and_set_cache(cng) update_and_set_cache(cng)
end end
@ -454,11 +458,13 @@ def update_follower_count(%User{} = user) do
follower_count = Repo.one(follower_count_query) follower_count = Repo.one(follower_count_query)
info_cng = user.info info_cng =
|> User.Info.set_follower_count(follower_count) user.info
|> User.Info.set_follower_count(follower_count)
cng = change(user) cng =
|> put_embed(:info, info_cng) change(user)
|> put_embed(:info, info_cng)
update_and_set_cache(cng) update_and_set_cache(cng)
end end
@ -613,8 +619,10 @@ def moderator_user_query() do
def deactivate(%User{} = user, status \\ true) do def deactivate(%User{} = user, status \\ true) do
info_cng = User.Info.set_activation_status(user.info, status) info_cng = User.Info.set_activation_status(user.info, status)
cng = change(user)
|> put_embed(:info, info_cng) cng =
change(user)
|> put_embed(:info, info_cng)
update_and_set_cache(cng) update_and_set_cache(cng)
end end

View File

@ -3,18 +3,19 @@ defmodule Pleroma.User.Info do
import Ecto.Changeset import Ecto.Changeset
embedded_schema do embedded_schema do
field :banner, :map, default: %{} field(:banner, :map, default: %{})
field :source_data, :map, default: %{} field(:source_data, :map, default: %{})
field :note_count, :integer, default: 0 field(:note_count, :integer, default: 0)
field :follower_count, :integer, default: 0 field(:follower_count, :integer, default: 0)
field :locked, :boolean, default: false field(:locked, :boolean, default: false)
field :default_scope, :string, default: "public" field(:default_scope, :string, default: "public")
field :blocks, {:array, :string}, default: [] field(:blocks, {:array, :string}, default: [])
field :domain_blocks, {:array, :string}, default: [] field(:domain_blocks, {:array, :string}, default: [])
field :deactivated, :boolean, default: false field(:deactivated, :boolean, default: false)
field :no_rich_text, :boolean, default: false field(:no_rich_text, :boolean, default: false)
field :ap_enabled, :boolean, default: false field(:ap_enabled, :boolean, default: false)
field :keys, :map, default: %{} field(:is_moderator, :boolean, default: false)
field(:keys, :map, default: %{})
end end
def set_activation_status(info, deactivated) do def set_activation_status(info, deactivated) do
@ -26,7 +27,7 @@ def set_activation_status(info, deactivated) do
end end
def add_to_note_count(info, number) do def add_to_note_count(info, number) do
params = %{note_count: Enum.max([0, info.note_count + number])} params = %{note_count: Enum.max([0, number])}
info info
|> cast(params, [:note_count]) |> cast(params, [:note_count])