@spec get_followers(User.t(), pos_integer()) :: {:ok, list(User.t())}
def get_followers(user, page \\ nil) do
- q = get_followers_query(user, page)
-
- {:ok, Repo.all(q)}
+ user
+ |> get_followers_query(page)
+ |> Repo.all()
end
@spec get_external_followers(User.t(), pos_integer()) :: {:ok, list(User.t())}
def get_friends_query(user), do: get_friends_query(user, nil)
def get_friends(user, page \\ nil) do
- q = get_friends_query(user, page)
-
- {:ok, Repo.all(q)}
+ user
+ |> get_friends_query(page)
+ |> Repo.all()
end
def get_friends_ids(user, page \\ nil) do
@spec get_follow_requests(User.t()) :: {:ok, [User.t()]}
def get_follow_requests(%User{} = user) do
- users =
- Activity.follow_requests_for_actor(user)
- |> join(:inner, [a], u in User, on: a.actor == u.ap_id)
- |> where([a, u], not fragment("? @> ?", u.following, ^[user.follower_address]))
- |> group_by([a, u], u.id)
- |> select([a, u], u)
- |> Repo.all()
-
- {:ok, users}
+ user
+ |> Activity.follow_requests_for_actor()
+ |> join(:inner, [a], u in User, on: a.actor == u.ap_id)
+ |> where([a, u], not fragment("? @> ?", u.following, ^[user.follower_address]))
+ |> group_by([a, u], u.id)
+ |> select([a, u], u)
+ |> Repo.all()
end
def increase_note_count(%User{} = user) do
def deactivate(%User{} = user, status \\ true) do
info_cng = User.Info.set_activation_status(user.info, status)
- with {:ok, friends} <- User.get_friends(user),
- {:ok, followers} <- User.get_followers(user),
- {:ok, user} <-
+ with {:ok, user} <-
user
|> change()
|> put_embed(:info, info_cng)
|> update_and_set_cache() do
- Enum.each(followers, &invalidate_cache(&1))
- Enum.each(friends, &update_follower_count(&1))
+ Enum.each(get_followers(user), &invalidate_cache/1)
+ Enum.each(get_friends(user), &update_follower_count/1)
{:ok, user}
end
{:ok, _user} = ActivityPub.delete(user)
# Remove all relationships
- {:ok, followers} = User.get_followers(user)
-
- Enum.each(followers, fn follower ->
+ user
+ |> get_followers()
+ |> Enum.each(fn follower ->
ActivityPub.unfollow(follower, user)
- User.unfollow(follower, user)
+ unfollow(follower, user)
end)
- {:ok, friends} = User.get_friends(user)
-
- Enum.each(friends, fn followed ->
+ user
+ |> get_friends()
+ |> Enum.each(fn followed ->
ActivityPub.unfollow(user, followed)
- User.unfollow(user, followed)
+ unfollow(user, followed)
end)
delete_user_activities(user)
def perform(:fetch_initial_posts, %User{} = user) do
pages = Pleroma.Config.get!([:fetch_initial_posts, :pages])
- Enum.each(
- # Insert all the posts in reverse order, so they're in the right order on the timeline
- Enum.reverse(Utils.fetch_ordered_collection(user.info.source_data["outbox"], pages)),
- &Pleroma.Web.Federator.incoming_ap_doc/1
- )
-
- {:ok, user}
+ # Insert all the posts in reverse order, so they're in the right order on the timeline
+ user.info.source_data["outbox"]
+ |> Utils.fetch_ordered_collection(pages)
+ |> Enum.reverse()
+ |> Enum.each(&Pleroma.Web.Federator.incoming_ap_doc/1)
end
def perform(:deactivate_async, user, status), do: deactivate(user, status)
})
end
- def delete_user_activities(%User{ap_id: ap_id} = user) do
+ def delete_user_activities(%User{ap_id: ap_id}) do
ap_id
|> Activity.Queries.by_actor()
|> RepoStreamer.chunk_stream(50)
- |> Stream.each(fn activities ->
- Enum.each(activities, &delete_activity(&1))
- end)
+ |> Stream.each(fn activities -> Enum.each(activities, &delete_activity/1) end)
|> Stream.run()
-
- {:ok, user}
end
defp delete_activity(%{data: %{"type" => "Create"}} = activity) do
CommonAPI.follow(follower, unlocked)
CommonAPI.follow(follower, locked)
- assert {:ok, []} = User.get_follow_requests(unlocked)
- assert {:ok, [activity]} = User.get_follow_requests(locked)
+ assert [] = User.get_follow_requests(unlocked)
+ assert [activity] = User.get_follow_requests(locked)
assert activity
end
CommonAPI.follow(accepted_follower, locked)
User.follow(accepted_follower, locked)
- assert {:ok, [activity]} = User.get_follow_requests(locked)
+ assert [activity] = User.get_follow_requests(locked)
assert activity
end
follower = insert(:user)
CommonAPI.follow(follower, followed)
- assert {:ok, [_activity]} = User.get_follow_requests(followed)
+ assert [_activity] = User.get_follow_requests(followed)
{:ok, _follower} = User.block(followed, follower)
- assert {:ok, []} = User.get_follow_requests(followed)
+ assert [] = User.get_follow_requests(followed)
end
test "follow_all follows mutliple users" do
test "it enforces the fqn format for nicknames" do
cs = User.remote_user_creation(%{@valid_remote | nickname: "bla"})
- assert cs.changes.local == false
+ assert Ecto.Changeset.get_field(cs, :local) == false
assert cs.changes.avatar
refute cs.valid?
end
{:ok, follower_one} = User.follow(follower_one, user)
{:ok, follower_two} = User.follow(follower_two, user)
- {:ok, res} = User.get_followers(user)
+ res = User.get_followers(user)
assert Enum.member?(res, follower_one)
assert Enum.member?(res, follower_two)
{:ok, user} = User.follow(user, followed_one)
{:ok, user} = User.follow(user, followed_two)
- {:ok, res} = User.get_friends(user)
+ res = User.get_friends(user)
followed_one = User.get_cached_by_ap_id(followed_one.ap_id)
followed_two = User.get_cached_by_ap_id(followed_two.ap_id)
info = User.get_cached_user_info(user2)
assert info.follower_count == 0
- assert {:ok, []} = User.get_followers(user2)
+ assert [] = User.get_followers(user2)
end
test "hide a user from friends" do
assert info.following_count == 0
assert User.following_count(user2) == 0
- assert {:ok, []} = User.get_friends(user2)
+ assert [] = User.get_friends(user2)
end
test "hide a user's statuses from timelines and notifications" do
test ".delete_user_activities deletes all create activities", %{user: user} do
{:ok, activity} = CommonAPI.post(user, %{"status" => "2hu"})
- {:ok, _} = User.delete_user_activities(user)
+ User.delete_user_activities(user)
# TODO: Remove favorites, repeats, delete activities.
refute Activity.get_by_id(activity.id)