adding following_address field to user
This commit is contained in:
parent
b972b972e0
commit
f8786fa6f2
5 changed files with 41 additions and 8 deletions
|
@ -52,6 +52,7 @@ defmodule Pleroma.User do
|
||||||
field(:avatar, :map)
|
field(:avatar, :map)
|
||||||
field(:local, :boolean, default: true)
|
field(:local, :boolean, default: true)
|
||||||
field(:follower_address, :string)
|
field(:follower_address, :string)
|
||||||
|
field(:following_address, :string)
|
||||||
field(:search_rank, :float, virtual: true)
|
field(:search_rank, :float, virtual: true)
|
||||||
field(:search_type, :integer, virtual: true)
|
field(:search_type, :integer, virtual: true)
|
||||||
field(:tags, {:array, :string}, default: [])
|
field(:tags, {:array, :string}, default: [])
|
||||||
|
@ -162,9 +163,10 @@ defmodule Pleroma.User do
|
||||||
|
|
||||||
if changes.valid? do
|
if changes.valid? do
|
||||||
case info_cng.changes[:source_data] do
|
case info_cng.changes[:source_data] do
|
||||||
%{"followers" => followers} ->
|
%{"followers" => followers, "following" => following} ->
|
||||||
changes
|
changes
|
||||||
|> put_change(:follower_address, followers)
|
|> put_change(:follower_address, followers)
|
||||||
|
|> put_change(:following_address, following)
|
||||||
|
|
||||||
_ ->
|
_ ->
|
||||||
followers = User.ap_followers(%User{nickname: changes.changes[:nickname]})
|
followers = User.ap_followers(%User{nickname: changes.changes[:nickname]})
|
||||||
|
@ -196,7 +198,14 @@ defmodule Pleroma.User do
|
||||||
|> User.Info.user_upgrade(params[:info])
|
|> User.Info.user_upgrade(params[:info])
|
||||||
|
|
||||||
struct
|
struct
|
||||||
|> cast(params, [:bio, :name, :follower_address, :avatar, :last_refreshed_at])
|
|> cast(params, [
|
||||||
|
:bio,
|
||||||
|
:name,
|
||||||
|
:follower_address,
|
||||||
|
:following_address,
|
||||||
|
:avatar,
|
||||||
|
:last_refreshed_at
|
||||||
|
])
|
||||||
|> unique_constraint(:nickname)
|
|> unique_constraint(:nickname)
|
||||||
|> validate_format(:nickname, local_nickname_regex())
|
|> validate_format(:nickname, local_nickname_regex())
|
||||||
|> validate_length(:bio, max: 5000)
|
|> validate_length(:bio, max: 5000)
|
||||||
|
@ -1039,15 +1048,20 @@ defmodule Pleroma.User do
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
@spec external_users(keyword()) :: [User.t()]
|
@spec external_users_query() :: Ecto.Query.t()
|
||||||
def external_users(opts \\ []) do
|
def external_users_query do
|
||||||
query =
|
|
||||||
User.Query.build(%{
|
User.Query.build(%{
|
||||||
external: true,
|
external: true,
|
||||||
active: true,
|
active: true,
|
||||||
order_by: :id,
|
order_by: :id
|
||||||
select: [:id, :ap_id, :info]
|
|
||||||
})
|
})
|
||||||
|
end
|
||||||
|
|
||||||
|
@spec external_users(keyword()) :: [User.t()]
|
||||||
|
def external_users(opts \\ []) do
|
||||||
|
query =
|
||||||
|
external_users_query()
|
||||||
|
|> select([u], struct(u, [:id, :ap_id, :info]))
|
||||||
|
|
||||||
query =
|
query =
|
||||||
if opts[:max_id],
|
if opts[:max_id],
|
||||||
|
|
|
@ -994,6 +994,7 @@ defmodule Pleroma.Web.ActivityPub.ActivityPub do
|
||||||
avatar: avatar,
|
avatar: avatar,
|
||||||
name: data["name"],
|
name: data["name"],
|
||||||
follower_address: data["followers"],
|
follower_address: data["followers"],
|
||||||
|
following_address: data["following"],
|
||||||
bio: data["summary"]
|
bio: data["summary"]
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -0,0 +1,9 @@
|
||||||
|
defmodule Pleroma.Repo.Migrations.AddFollowingAddressToUser do
|
||||||
|
use Ecto.Migration
|
||||||
|
|
||||||
|
def change do
|
||||||
|
alter table(:users) do
|
||||||
|
add(:following_address, :string, unique: true)
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
|
@ -0,0 +1,8 @@
|
||||||
|
defmodule Pleroma.Repo.Migrations.AddFollowingAddressIndexToUser do
|
||||||
|
use Ecto.Migration
|
||||||
|
|
||||||
|
@disable_ddl_transaction true
|
||||||
|
def change do
|
||||||
|
create(index(:users, [:following_address], concurrently: true))
|
||||||
|
end
|
||||||
|
end
|
|
@ -1121,6 +1121,7 @@ defmodule Pleroma.Web.ActivityPub.TransmogrifierTest do
|
||||||
assert user.info.ap_enabled
|
assert user.info.ap_enabled
|
||||||
assert user.info.note_count == 1
|
assert user.info.note_count == 1
|
||||||
assert user.follower_address == "https://niu.moe/users/rye/followers"
|
assert user.follower_address == "https://niu.moe/users/rye/followers"
|
||||||
|
assert user.following_address == "https://niu.moe/users/rye/following"
|
||||||
|
|
||||||
user = User.get_cached_by_id(user.id)
|
user = User.get_cached_by_id(user.id)
|
||||||
assert user.info.note_count == 1
|
assert user.info.note_count == 1
|
||||||
|
|
Loading…
Reference in a new issue