Merge remote-tracking branch 'origin/develop' into inactive-test

This commit is contained in:
Mark Felder 2024-08-07 13:59:01 -04:00
commit 9e42c6b6a7
11 changed files with 35 additions and 37 deletions

View file

View file

@ -1 +1 @@
Worker configuration is no longer available. This only affects custom max_retries values for Oban queues. Worker configuration is no longer available. This only affects custom max_retries values for a couple Oban queues.

View file

@ -130,7 +130,7 @@ def follow(followed, follower) do
if activity.data["state"] == "reject" do if activity.data["state"] == "reject" do
{:error, :rejected} {:error, :rejected}
else else
{:ok, follower, followed, activity} {:ok, followed, follower, activity}
end end
end end
end end

View file

@ -18,10 +18,10 @@ def follow(follower, followed, params \\ %{}) do
if not User.following?(follower, followed) do if not User.following?(follower, followed) do
CommonAPI.follow(followed, follower) CommonAPI.follow(followed, follower)
else else
{:ok, follower, followed, nil} {:ok, followed, follower, nil}
end end
with {:ok, follower, _followed, _} <- result do with {:ok, _followed, follower, _} <- result do
options = cast_params(params) options = cast_params(params)
set_reblogs_visibility(options[:reblogs], result) set_reblogs_visibility(options[:reblogs], result)
set_subscription(options[:notify], result) set_subscription(options[:notify], result)
@ -29,19 +29,19 @@ def follow(follower, followed, params \\ %{}) do
end end
end end
defp set_reblogs_visibility(false, {:ok, follower, followed, _}) do defp set_reblogs_visibility(false, {:ok, followed, follower, _}) do
CommonAPI.hide_reblogs(followed, follower) CommonAPI.hide_reblogs(followed, follower)
end end
defp set_reblogs_visibility(_, {:ok, follower, followed, _}) do defp set_reblogs_visibility(_, {:ok, followed, follower, _}) do
CommonAPI.show_reblogs(followed, follower) CommonAPI.show_reblogs(followed, follower)
end end
defp set_subscription(true, {:ok, follower, followed, _}) do defp set_subscription(true, {:ok, followed, follower, _}) do
User.subscribe(follower, followed) User.subscribe(follower, followed)
end end
defp set_subscription(false, {:ok, follower, followed, _}) do defp set_subscription(false, {:ok, followed, follower, _}) do
User.unsubscribe(follower, followed) User.unsubscribe(follower, followed)
end end

View file

@ -29,5 +29,6 @@ def enabled, do: match?([subject: _, public_key: _, private_key: _], vapid_confi
{:ok, Oban.Job.t()} | {:error, Oban.Job.changeset() | term()} {:ok, Oban.Job.t()} | {:error, Oban.Job.changeset() | term()}
def send(notification) do def send(notification) do
WebPusherWorker.new(%{"op" => "web_push", "notification_id" => notification.id}) WebPusherWorker.new(%{"op" => "web_push", "notification_id" => notification.id})
|> Oban.insert()
end end
end end

View file

@ -1747,7 +1747,7 @@ test "it renders the page, if the user has 'hide_followers' set and the request
%{conn: conn} do %{conn: conn} do
user = insert(:user, hide_followers: true) user = insert(:user, hide_followers: true)
other_user = insert(:user) other_user = insert(:user)
{:ok, _other_user, user, _activity} = CommonAPI.follow(user, other_user) {:ok, user, _other_user, _activity} = CommonAPI.follow(user, other_user)
result = result =
conn conn
@ -1843,7 +1843,7 @@ test "it renders the page, if the user has 'hide_follows' set and the request is
%{conn: conn} do %{conn: conn} do
user = insert(:user, hide_follows: true) user = insert(:user, hide_follows: true)
other_user = insert(:user) other_user = insert(:user)
{:ok, user, _other_user, _activity} = CommonAPI.follow(other_user, user) {:ok, _other_user, user, _activity} = CommonAPI.follow(other_user, user)
result = result =
conn conn

View file

@ -54,20 +54,17 @@ test "it streams out notifications and streams" do
[ [
stream: fn _, _ -> nil end stream: fn _, _ -> nil end
] ]
},
{
Pleroma.Web.Push,
[],
[
send: fn _ -> nil end
]
} }
]) do ]) do
SideEffects.handle_after_transaction(meta) SideEffects.handle_after_transaction(meta)
assert called(Pleroma.Web.Streamer.stream(["user", "user:notification"], notification)) assert called(Pleroma.Web.Streamer.stream(["user", "user:notification"], notification))
assert called(Pleroma.Web.Streamer.stream(["user", "user:pleroma_chat"], :_)) assert called(Pleroma.Web.Streamer.stream(["user", "user:pleroma_chat"], :_))
assert called(Pleroma.Web.Push.send(notification))
assert_enqueued(
worker: "Pleroma.Workers.WebPusherWorker",
args: %{"notification_id" => notification.id, "op" => "web_push"}
)
end end
end end
end end

View file

@ -138,7 +138,7 @@ test "instance users do not expose oAuth endpoints" do
test "sets totalItems to zero when followers are hidden" do test "sets totalItems to zero when followers are hidden" do
user = insert(:user) user = insert(:user)
other_user = insert(:user) other_user = insert(:user)
{:ok, _other_user, user, _activity} = CommonAPI.follow(user, other_user) {:ok, user, _other_user, _activity} = CommonAPI.follow(user, other_user)
assert %{"totalItems" => 1} = UserView.render("followers.json", %{user: user}) assert %{"totalItems" => 1} = UserView.render("followers.json", %{user: user})
user = Map.merge(user, %{hide_followers_count: true, hide_followers: true}) user = Map.merge(user, %{hide_followers_count: true, hide_followers: true})
refute UserView.render("followers.json", %{user: user}) |> Map.has_key?("totalItems") refute UserView.render("followers.json", %{user: user}) |> Map.has_key?("totalItems")
@ -147,7 +147,7 @@ test "sets totalItems to zero when followers are hidden" do
test "sets correct totalItems when followers are hidden but the follower counter is not" do test "sets correct totalItems when followers are hidden but the follower counter is not" do
user = insert(:user) user = insert(:user)
other_user = insert(:user) other_user = insert(:user)
{:ok, _other_user, user, _activity} = CommonAPI.follow(user, other_user) {:ok, user, _other_user, _activity} = CommonAPI.follow(user, other_user)
assert %{"totalItems" => 1} = UserView.render("followers.json", %{user: user}) assert %{"totalItems" => 1} = UserView.render("followers.json", %{user: user})
user = Map.merge(user, %{hide_followers_count: false, hide_followers: true}) user = Map.merge(user, %{hide_followers_count: false, hide_followers: true})
assert %{"totalItems" => 1} = UserView.render("followers.json", %{user: user}) assert %{"totalItems" => 1} = UserView.render("followers.json", %{user: user})
@ -158,7 +158,7 @@ test "sets correct totalItems when followers are hidden but the follower counter
test "sets totalItems to zero when follows are hidden" do test "sets totalItems to zero when follows are hidden" do
user = insert(:user) user = insert(:user)
other_user = insert(:user) other_user = insert(:user)
{:ok, user, _other_user, _activity} = CommonAPI.follow(other_user, user) {:ok, _other_user, user, _activity} = CommonAPI.follow(other_user, user)
assert %{"totalItems" => 1} = UserView.render("following.json", %{user: user}) assert %{"totalItems" => 1} = UserView.render("following.json", %{user: user})
user = Map.merge(user, %{hide_follows_count: true, hide_follows: true}) user = Map.merge(user, %{hide_follows_count: true, hide_follows: true})
assert %{"totalItems" => 0} = UserView.render("following.json", %{user: user}) assert %{"totalItems" => 0} = UserView.render("following.json", %{user: user})
@ -167,7 +167,7 @@ test "sets totalItems to zero when follows are hidden" do
test "sets correct totalItems when follows are hidden but the follow counter is not" do test "sets correct totalItems when follows are hidden but the follow counter is not" do
user = insert(:user) user = insert(:user)
other_user = insert(:user) other_user = insert(:user)
{:ok, user, _other_user, _activity} = CommonAPI.follow(other_user, user) {:ok, _other_user, user, _activity} = CommonAPI.follow(other_user, user)
assert %{"totalItems" => 1} = UserView.render("following.json", %{user: user}) assert %{"totalItems" => 1} = UserView.render("following.json", %{user: user})
user = Map.merge(user, %{hide_follows_count: false, hide_follows: true}) user = Map.merge(user, %{hide_follows_count: false, hide_follows: true})
assert %{"totalItems" => 1} = UserView.render("following.json", %{user: user}) assert %{"totalItems" => 1} = UserView.render("following.json", %{user: user})

View file

@ -1420,7 +1420,7 @@ test "remove a reblog mute", %{muter: muter, muted: muted} do
describe "follow/2" do describe "follow/2" do
test "directly follows a non-locked local user" do test "directly follows a non-locked local user" do
[follower, followed] = insert_pair(:user) [follower, followed] = insert_pair(:user)
{:ok, follower, followed, _} = CommonAPI.follow(followed, follower) {:ok, followed, follower, _} = CommonAPI.follow(followed, follower)
assert User.following?(follower, followed) assert User.following?(follower, followed)
end end
@ -1429,7 +1429,7 @@ test "directly follows a non-locked local user" do
describe "unfollow/2" do describe "unfollow/2" do
test "also unsubscribes a user" do test "also unsubscribes a user" do
[follower, followed] = insert_pair(:user) [follower, followed] = insert_pair(:user)
{:ok, follower, followed, _} = CommonAPI.follow(followed, follower) {:ok, followed, follower, _} = CommonAPI.follow(followed, follower)
{:ok, _subscription} = User.subscribe(follower, followed) {:ok, _subscription} = User.subscribe(follower, followed)
assert User.subscribed_to?(follower, followed) assert User.subscribed_to?(follower, followed)
@ -1441,7 +1441,7 @@ test "also unsubscribes a user" do
test "also unpins a user" do test "also unpins a user" do
[follower, followed] = insert_pair(:user) [follower, followed] = insert_pair(:user)
{:ok, follower, followed, _} = CommonAPI.follow(followed, follower) {:ok, followed, follower, _} = CommonAPI.follow(followed, follower)
{:ok, _endorsement} = User.endorse(follower, followed) {:ok, _endorsement} = User.endorse(follower, followed)
assert User.endorses?(follower, followed) assert User.endorses?(follower, followed)
@ -1455,7 +1455,7 @@ test "cancels a pending follow for a local user" do
follower = insert(:user) follower = insert(:user)
followed = insert(:user, is_locked: true) followed = insert(:user, is_locked: true)
assert {:ok, follower, followed, %{id: activity_id, data: %{"state" => "pending"}}} = assert {:ok, followed, follower, %{id: activity_id, data: %{"state" => "pending"}}} =
CommonAPI.follow(followed, follower) CommonAPI.follow(followed, follower)
assert User.get_follow_state(follower, followed) == :follow_pending assert User.get_follow_state(follower, followed) == :follow_pending
@ -1477,7 +1477,7 @@ test "cancels a pending follow for a remote user" do
follower = insert(:user) follower = insert(:user)
followed = insert(:user, is_locked: true, local: false) followed = insert(:user, is_locked: true, local: false)
assert {:ok, follower, followed, %{id: activity_id, data: %{"state" => "pending"}}} = assert {:ok, followed, follower, %{id: activity_id, data: %{"state" => "pending"}}} =
CommonAPI.follow(followed, follower) CommonAPI.follow(followed, follower)
assert User.get_follow_state(follower, followed) == :follow_pending assert User.get_follow_state(follower, followed) == :follow_pending

View file

@ -493,7 +493,7 @@ test "represent a relationship for the user with a pending follow request" do
user = insert(:user) user = insert(:user)
other_user = insert(:user, is_locked: true) other_user = insert(:user, is_locked: true)
{:ok, user, other_user, _} = CommonAPI.follow(other_user, user) {:ok, other_user, user, _} = CommonAPI.follow(other_user, user)
user = User.get_cached_by_id(user.id) user = User.get_cached_by_id(user.id)
other_user = User.get_cached_by_id(other_user.id) other_user = User.get_cached_by_id(other_user.id)
@ -560,8 +560,8 @@ test "shows when follows/followers stats are hidden and sets follow/follower cou
test "shows when follows/followers are hidden" do test "shows when follows/followers are hidden" do
user = insert(:user, hide_followers: true, hide_follows: true) user = insert(:user, hide_followers: true, hide_follows: true)
other_user = insert(:user) other_user = insert(:user)
{:ok, user, other_user, _activity} = CommonAPI.follow(other_user, user) {:ok, other_user, user, _activity} = CommonAPI.follow(other_user, user)
{:ok, _other_user, user, _activity} = CommonAPI.follow(user, other_user) {:ok, user, _other_user, _activity} = CommonAPI.follow(user, other_user)
assert %{ assert %{
followers_count: 1, followers_count: 1,
@ -573,11 +573,11 @@ test "shows when follows/followers are hidden" do
test "shows actual follower/following count to the account owner" do test "shows actual follower/following count to the account owner" do
user = insert(:user, hide_followers: true, hide_follows: true) user = insert(:user, hide_followers: true, hide_follows: true)
other_user = insert(:user) other_user = insert(:user)
{:ok, user, other_user, _activity} = CommonAPI.follow(other_user, user) {:ok, other_user, user, _activity} = CommonAPI.follow(other_user, user)
assert User.following?(user, other_user) assert User.following?(user, other_user)
assert Pleroma.FollowingRelationship.follower_count(other_user) == 1 assert Pleroma.FollowingRelationship.follower_count(other_user) == 1
{:ok, _other_user, user, _activity} = CommonAPI.follow(user, other_user) {:ok, user, _other_user, _activity} = CommonAPI.follow(user, other_user)
assert %{ assert %{
followers_count: 1, followers_count: 1,
@ -696,7 +696,7 @@ test "shows non-zero when follow requests are pending" do
assert %{locked: true} = AccountView.render("show.json", %{user: user, for: user}) assert %{locked: true} = AccountView.render("show.json", %{user: user, for: user})
other_user = insert(:user) other_user = insert(:user)
{:ok, _other_user, user, _activity} = CommonAPI.follow(user, other_user) {:ok, user, _other_user, _activity} = CommonAPI.follow(user, other_user)
assert %{locked: true, follow_requests_count: 1} = assert %{locked: true, follow_requests_count: 1} =
AccountView.render("show.json", %{user: user, for: user}) AccountView.render("show.json", %{user: user, for: user})
@ -708,7 +708,7 @@ test "decreases when accepting a follow request" do
assert %{locked: true} = AccountView.render("show.json", %{user: user, for: user}) assert %{locked: true} = AccountView.render("show.json", %{user: user, for: user})
other_user = insert(:user) other_user = insert(:user)
{:ok, other_user, user, _activity} = CommonAPI.follow(user, other_user) {:ok, user, other_user, _activity} = CommonAPI.follow(user, other_user)
assert %{locked: true, follow_requests_count: 1} = assert %{locked: true, follow_requests_count: 1} =
AccountView.render("show.json", %{user: user, for: user}) AccountView.render("show.json", %{user: user, for: user})
@ -725,7 +725,7 @@ test "decreases when rejecting a follow request" do
assert %{locked: true} = AccountView.render("show.json", %{user: user, for: user}) assert %{locked: true} = AccountView.render("show.json", %{user: user, for: user})
other_user = insert(:user) other_user = insert(:user)
{:ok, other_user, user, _activity} = CommonAPI.follow(user, other_user) {:ok, user, other_user, _activity} = CommonAPI.follow(user, other_user)
assert %{locked: true, follow_requests_count: 1} = assert %{locked: true, follow_requests_count: 1} =
AccountView.render("show.json", %{user: user, for: user}) AccountView.render("show.json", %{user: user, for: user})
@ -742,7 +742,7 @@ test "shows non-zero when historical unapproved requests are present" do
assert %{locked: true} = AccountView.render("show.json", %{user: user, for: user}) assert %{locked: true} = AccountView.render("show.json", %{user: user, for: user})
other_user = insert(:user) other_user = insert(:user)
{:ok, _other_user, user, _activity} = CommonAPI.follow(user, other_user) {:ok, user, _other_user, _activity} = CommonAPI.follow(user, other_user)
{:ok, user} = User.update_and_set_cache(user, %{is_locked: false}) {:ok, user} = User.update_and_set_cache(user, %{is_locked: false})

View file

@ -132,7 +132,7 @@ test "Reblog notification" do
test "Follow notification" do test "Follow notification" do
follower = insert(:user) follower = insert(:user)
followed = insert(:user) followed = insert(:user)
{:ok, follower, followed, _activity} = CommonAPI.follow(followed, follower) {:ok, followed, follower, _activity} = CommonAPI.follow(followed, follower)
notification = Notification |> Repo.one() |> Repo.preload(:activity) notification = Notification |> Repo.one() |> Repo.preload(:activity)
expected = %{ expected = %{