mirror of
https://git.pleroma.social/pleroma/pleroma.git
synced 2024-11-05 08:31:36 +00:00
Merge branch 'user-follow-all-unique' into 'develop'
User.follow_all: ensure the following array stays unique See merge request pleroma/pleroma!750
This commit is contained in:
commit
e914eeb632
2 changed files with 23 additions and 1 deletions
|
@ -315,7 +315,16 @@ defmodule Pleroma.User do
|
|||
q =
|
||||
from(u in User,
|
||||
where: u.id == ^follower.id,
|
||||
update: [set: [following: fragment("array_cat(?, ?)", u.following, ^followed_addresses)]]
|
||||
update: [
|
||||
set: [
|
||||
following:
|
||||
fragment(
|
||||
"array(select distinct unnest (array_cat(?, ?)))",
|
||||
u.following,
|
||||
^followed_addresses
|
||||
)
|
||||
]
|
||||
]
|
||||
)
|
||||
|
||||
{1, [follower]} = Repo.update_all(q, [], returning: true)
|
||||
|
|
|
@ -65,6 +65,19 @@ defmodule Pleroma.UserTest do
|
|||
refute User.following?(user, not_followed)
|
||||
end
|
||||
|
||||
test "follow_all follows mutliple users without duplicating" do
|
||||
user = insert(:user)
|
||||
followed_zero = insert(:user)
|
||||
followed_one = insert(:user)
|
||||
followed_two = insert(:user)
|
||||
|
||||
{:ok, user} = User.follow_all(user, [followed_zero, followed_one])
|
||||
assert length(user.following) == 3
|
||||
|
||||
{:ok, user} = User.follow_all(user, [followed_one, followed_two])
|
||||
assert length(user.following) == 4
|
||||
end
|
||||
|
||||
test "follow takes a user and another user" do
|
||||
user = insert(:user)
|
||||
followed = insert(:user)
|
||||
|
|
Loading…
Reference in a new issue