Browse Source

adding following_address field to user

tags/v1.1.4
Alex S 5 years ago
parent
commit
f8786fa6f2
5 changed files with 41 additions and 8 deletions
  1. +22
    -8
      lib/pleroma/user.ex
  2. +1
    -0
      lib/pleroma/web/activity_pub/activity_pub.ex
  3. +9
    -0
      priv/repo/migrations/20190710115833_add_following_address_to_user.exs
  4. +8
    -0
      priv/repo/migrations/20190710125051_add_following_address_index_to_user.exs
  5. +1
    -0
      test/web/activity_pub/transmogrifier_test.exs

+ 22
- 8
lib/pleroma/user.ex View File

@@ -52,6 +52,7 @@ defmodule Pleroma.User do
field(:avatar, :map)
field(:local, :boolean, default: true)
field(:follower_address, :string)
field(:following_address, :string)
field(:search_rank, :float, virtual: true)
field(:search_type, :integer, virtual: true)
field(:tags, {:array, :string}, default: [])
@@ -162,9 +163,10 @@ defmodule Pleroma.User do

if changes.valid? do
case info_cng.changes[:source_data] do
%{"followers" => followers} ->
%{"followers" => followers, "following" => following} ->
changes
|> put_change(:follower_address, followers)
|> put_change(:following_address, following)

_ ->
followers = User.ap_followers(%User{nickname: changes.changes[:nickname]})
@@ -196,7 +198,14 @@ defmodule Pleroma.User do
|> User.Info.user_upgrade(params[:info])

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)
|> validate_format(:nickname, local_nickname_regex())
|> validate_length(:bio, max: 5000)
@@ -1039,15 +1048,20 @@ defmodule Pleroma.User do
end
end

@spec external_users_query() :: Ecto.Query.t()
def external_users_query do
User.Query.build(%{
external: true,
active: true,
order_by: :id
})
end

@spec external_users(keyword()) :: [User.t()]
def external_users(opts \\ []) do
query =
User.Query.build(%{
external: true,
active: true,
order_by: :id,
select: [:id, :ap_id, :info]
})
external_users_query()
|> select([u], struct(u, [:id, :ap_id, :info]))

query =
if opts[:max_id],


+ 1
- 0
lib/pleroma/web/activity_pub/activity_pub.ex View File

@@ -994,6 +994,7 @@ defmodule Pleroma.Web.ActivityPub.ActivityPub do
avatar: avatar,
name: data["name"],
follower_address: data["followers"],
following_address: data["following"],
bio: data["summary"]
}



+ 9
- 0
priv/repo/migrations/20190710115833_add_following_address_to_user.exs View File

@@ -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

+ 8
- 0
priv/repo/migrations/20190710125051_add_following_address_index_to_user.exs View File

@@ -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

+ 1
- 0
test/web/activity_pub/transmogrifier_test.exs View File

@@ -1121,6 +1121,7 @@ defmodule Pleroma.Web.ActivityPub.TransmogrifierTest do
assert user.info.ap_enabled
assert user.info.note_count == 1
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)
assert user.info.note_count == 1


Loading…
Cancel
Save