Skip to content
GitLab
Menu
Projects
Groups
Snippets
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
Menu
Open sidebar
Pleroma
pleroma
Commits
26938d65
Commit
26938d65
authored
Jan 09, 2019
by
lain
Browse files
Add User mass following function.
parent
5c5c8508
Changes
2
Hide whitespace changes
Inline
Side-by-side
lib/pleroma/user.ex
View file @
26938d65
...
...
@@ -307,6 +307,25 @@ def maybe_follow(%User{} = follower, %User{info: _info} = followed) do
end
end
@doc
"A mass follow for local users. Ignores blocks and has no side effects"
@spec
follow_all
(
User
.
t
(),
list
(
User
.
t
()))
::
{
atom
(),
User
.
t
()}
def
follow_all
(
follower
,
followeds
)
do
following
=
(
follower
.
following
++
Enum
.
map
(
followeds
,
fn
%{
follower_address:
fa
}
->
fa
end
))
|>
Enum
.
uniq
()
{
:ok
,
follower
}
=
follower
|>
follow_changeset
(%{
following:
following
})
|>
update_and_set_cache
Enum
.
each
(
followeds
,
fn
followed
->
update_follower_count
(
followed
)
end
)
{
:ok
,
follower
}
end
def
follow
(%
User
{}
=
follower
,
%
User
{
info:
info
}
=
followed
)
do
user_config
=
Application
.
get_env
(
:pleroma
,
:user
)
deny_follow_blocked
=
Keyword
.
get
(
user_config
,
:deny_follow_blocked
)
...
...
test/user_test.exs
View file @
26938d65
...
...
@@ -48,6 +48,17 @@ test "ap_followers returns the followers collection for the user" do
assert
expected_followers_collection
==
User
.
ap_followers
(
user
)
end
test
"follow_all follows mutliple users"
do
user
=
insert
(
:user
)
followed_one
=
insert
(
:user
)
followed_two
=
insert
(
:user
)
{
:ok
,
user
}
=
User
.
follow_all
(
user
,
[
followed_one
,
followed_two
])
assert
User
.
following?
(
user
,
followed_one
)
assert
User
.
following?
(
user
,
followed_two
)
end
test
"follow takes a user and another user"
do
user
=
insert
(
:user
)
followed
=
insert
(
:user
)
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment