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(:last_refreshed_at, :naive_datetime)
has_many(:notifications, Notification)
embeds_one :info, Pleroma.User.Info
embeds_one(:info, Pleroma.User.Info)
timestamps()
end
@ -412,16 +412,20 @@ defmodule Pleroma.User do
def increase_note_count(%User{} = user) do
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)
end
def decrease_note_count(%User{} = user) do
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)
end
@ -454,11 +458,13 @@ defmodule Pleroma.User do
follower_count = Repo.one(follower_count_query)
info_cng = user.info
|> User.Info.set_follower_count(follower_count)
info_cng =
user.info
|> User.Info.set_follower_count(follower_count)
cng = change(user)
|> put_embed(:info, info_cng)
cng =
change(user)
|> put_embed(:info, info_cng)
update_and_set_cache(cng)
end
@ -613,8 +619,10 @@ defmodule Pleroma.User do
def deactivate(%User{} = user, status \\ true) do
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)
end

View File

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