Merge remote-tracking branch 'pleroma/develop' into feature/disable-account
This commit is contained in:
commit
22ac2288be
|
@ -14,6 +14,19 @@ defmodule Pleroma.Web.CommonAPI do
|
||||||
|
|
||||||
import Pleroma.Web.CommonAPI.Utils
|
import Pleroma.Web.CommonAPI.Utils
|
||||||
|
|
||||||
|
def follow(follower, followed) do
|
||||||
|
with {:ok, follower} <- User.maybe_direct_follow(follower, followed),
|
||||||
|
{:ok, activity} <- ActivityPub.follow(follower, followed),
|
||||||
|
{:ok, follower, followed} <-
|
||||||
|
User.wait_and_refresh(
|
||||||
|
Pleroma.Config.get([:activitypub, :follow_handshake_timeout]),
|
||||||
|
follower,
|
||||||
|
followed
|
||||||
|
) do
|
||||||
|
{:ok, follower, followed, activity}
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
def delete(activity_id, user) do
|
def delete(activity_id, user) do
|
||||||
with %Activity{data: %{"object" => %{"id" => object_id}}} <- Repo.get(Activity, activity_id),
|
with %Activity{data: %{"object" => %{"id" => object_id}}} <- Repo.get(Activity, activity_id),
|
||||||
%Object{} = object <- Object.normalize(object_id),
|
%Object{} = object <- Object.normalize(object_id),
|
||||||
|
|
|
@ -292,13 +292,16 @@ def user_statuses(%{assigns: %{user: reading_user}} = conn, params) do
|
||||||
end
|
end
|
||||||
|
|
||||||
def dm_timeline(%{assigns: %{user: user}} = conn, params) do
|
def dm_timeline(%{assigns: %{user: user}} = conn, params) do
|
||||||
query =
|
params =
|
||||||
ActivityPub.fetch_activities_query(
|
params
|
||||||
[user.ap_id],
|
|> Map.put("type", "Create")
|
||||||
Map.merge(params, %{"type" => "Create", visibility: "direct"})
|
|> Map.put("blocking_user", user)
|
||||||
)
|
|> Map.put("user", user)
|
||||||
|
|> Map.put(:visibility, "direct")
|
||||||
|
|
||||||
activities = Repo.all(query)
|
activities =
|
||||||
|
ActivityPub.fetch_activities_query([user.ap_id], params)
|
||||||
|
|> Repo.all()
|
||||||
|
|
||||||
conn
|
conn
|
||||||
|> add_link_headers(:dm_timeline, activities)
|
|> add_link_headers(:dm_timeline, activities)
|
||||||
|
@ -733,14 +736,7 @@ def reject_follow_request(%{assigns: %{user: followed}} = conn, %{"id" => id}) d
|
||||||
|
|
||||||
def follow(%{assigns: %{user: follower}} = conn, %{"id" => id}) do
|
def follow(%{assigns: %{user: follower}} = conn, %{"id" => id}) do
|
||||||
with %User{} = followed <- Repo.get(User, id),
|
with %User{} = followed <- Repo.get(User, id),
|
||||||
{:ok, follower} <- User.maybe_direct_follow(follower, followed),
|
{:ok, follower, followed, _} <- CommonAPI.follow(follower, followed) do
|
||||||
{:ok, _activity} <- ActivityPub.follow(follower, followed),
|
|
||||||
{:ok, follower, followed} <-
|
|
||||||
User.wait_and_refresh(
|
|
||||||
Config.get([:activitypub, :follow_handshake_timeout]),
|
|
||||||
follower,
|
|
||||||
followed
|
|
||||||
) do
|
|
||||||
conn
|
conn
|
||||||
|> put_view(AccountView)
|
|> put_view(AccountView)
|
||||||
|> render("relationship.json", %{user: follower, target: followed})
|
|> render("relationship.json", %{user: follower, target: followed})
|
||||||
|
@ -754,8 +750,7 @@ def follow(%{assigns: %{user: follower}} = conn, %{"id" => id}) do
|
||||||
|
|
||||||
def follow(%{assigns: %{user: follower}} = conn, %{"uri" => uri}) do
|
def follow(%{assigns: %{user: follower}} = conn, %{"uri" => uri}) do
|
||||||
with %User{} = followed <- Repo.get_by(User, nickname: uri),
|
with %User{} = followed <- Repo.get_by(User, nickname: uri),
|
||||||
{:ok, follower} <- User.maybe_direct_follow(follower, followed),
|
{:ok, follower, followed, _} <- CommonAPI.follow(follower, followed) do
|
||||||
{:ok, _activity} <- ActivityPub.follow(follower, followed) do
|
|
||||||
conn
|
conn
|
||||||
|> put_view(AccountView)
|
|> put_view(AccountView)
|
||||||
|> render("account.json", %{user: followed, for: follower})
|
|> render("account.json", %{user: followed, for: follower})
|
||||||
|
|
|
@ -28,18 +28,8 @@ def delete(%User{} = user, id) do
|
||||||
end
|
end
|
||||||
|
|
||||||
def follow(%User{} = follower, params) do
|
def follow(%User{} = follower, params) do
|
||||||
with {:ok, %User{} = followed} <- get_user(params),
|
with {:ok, %User{} = followed} <- get_user(params) do
|
||||||
{:ok, follower} <- User.maybe_direct_follow(follower, followed),
|
CommonAPI.follow(follower, followed)
|
||||||
{:ok, activity} <- ActivityPub.follow(follower, followed),
|
|
||||||
{:ok, follower, followed} <-
|
|
||||||
User.wait_and_refresh(
|
|
||||||
Pleroma.Config.get([:activitypub, :follow_handshake_timeout]),
|
|
||||||
follower,
|
|
||||||
followed
|
|
||||||
) do
|
|
||||||
{:ok, follower, followed, activity}
|
|
||||||
else
|
|
||||||
err -> err
|
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
|
@ -177,13 +177,16 @@ def mentions_timeline(%{assigns: %{user: user}} = conn, params) do
|
||||||
end
|
end
|
||||||
|
|
||||||
def dm_timeline(%{assigns: %{user: user}} = conn, params) do
|
def dm_timeline(%{assigns: %{user: user}} = conn, params) do
|
||||||
query =
|
params =
|
||||||
ActivityPub.fetch_activities_query(
|
params
|
||||||
[user.ap_id],
|
|> Map.put("type", "Create")
|
||||||
Map.merge(params, %{"type" => "Create", "user" => user, visibility: "direct"})
|
|> Map.put("blocking_user", user)
|
||||||
)
|
|> Map.put("user", user)
|
||||||
|
|> Map.put(:visibility, "direct")
|
||||||
|
|
||||||
activities = Repo.all(query)
|
activities =
|
||||||
|
ActivityPub.fetch_activities_query([user.ap_id], params)
|
||||||
|
|> Repo.all()
|
||||||
|
|
||||||
conn
|
conn
|
||||||
|> put_view(ActivityView)
|
|> put_view(ActivityView)
|
||||||
|
|
|
@ -248,6 +248,33 @@ test "direct timeline", %{conn: conn} do
|
||||||
assert status["url"] != direct.data["id"]
|
assert status["url"] != direct.data["id"]
|
||||||
end
|
end
|
||||||
|
|
||||||
|
test "doesn't include DMs from blocked users", %{conn: conn} do
|
||||||
|
blocker = insert(:user)
|
||||||
|
blocked = insert(:user)
|
||||||
|
user = insert(:user)
|
||||||
|
{:ok, blocker} = User.block(blocker, blocked)
|
||||||
|
|
||||||
|
{:ok, _blocked_direct} =
|
||||||
|
CommonAPI.post(blocked, %{
|
||||||
|
"status" => "Hi @#{blocker.nickname}!",
|
||||||
|
"visibility" => "direct"
|
||||||
|
})
|
||||||
|
|
||||||
|
{:ok, direct} =
|
||||||
|
CommonAPI.post(user, %{
|
||||||
|
"status" => "Hi @#{blocker.nickname}!",
|
||||||
|
"visibility" => "direct"
|
||||||
|
})
|
||||||
|
|
||||||
|
res_conn =
|
||||||
|
conn
|
||||||
|
|> assign(:user, user)
|
||||||
|
|> get("api/v1/timelines/direct")
|
||||||
|
|
||||||
|
[status] = json_response(res_conn, 200)
|
||||||
|
assert status["id"] == direct.id
|
||||||
|
end
|
||||||
|
|
||||||
test "replying to a status", %{conn: conn} do
|
test "replying to a status", %{conn: conn} do
|
||||||
user = insert(:user)
|
user = insert(:user)
|
||||||
|
|
||||||
|
|
|
@ -415,6 +415,33 @@ test "it show direct messages", %{conn: conn} do
|
||||||
assert status["id"] == direct_two.id
|
assert status["id"] == direct_two.id
|
||||||
assert status_two["id"] == direct.id
|
assert status_two["id"] == direct.id
|
||||||
end
|
end
|
||||||
|
|
||||||
|
test "doesn't include DMs from blocked users", %{conn: conn} do
|
||||||
|
blocker = insert(:user)
|
||||||
|
blocked = insert(:user)
|
||||||
|
user = insert(:user)
|
||||||
|
{:ok, blocker} = User.block(blocker, blocked)
|
||||||
|
|
||||||
|
{:ok, _blocked_direct} =
|
||||||
|
CommonAPI.post(blocked, %{
|
||||||
|
"status" => "Hi @#{blocker.nickname}!",
|
||||||
|
"visibility" => "direct"
|
||||||
|
})
|
||||||
|
|
||||||
|
{:ok, direct} =
|
||||||
|
CommonAPI.post(user, %{
|
||||||
|
"status" => "Hi @#{blocker.nickname}!",
|
||||||
|
"visibility" => "direct"
|
||||||
|
})
|
||||||
|
|
||||||
|
res_conn =
|
||||||
|
conn
|
||||||
|
|> assign(:user, blocker)
|
||||||
|
|> get("/api/statuses/dm_timeline.json")
|
||||||
|
|
||||||
|
[status] = json_response(res_conn, 200)
|
||||||
|
assert status["id"] == direct.id
|
||||||
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
describe "GET /statuses/mentions.json" do
|
describe "GET /statuses/mentions.json" do
|
||||||
|
@ -1762,8 +1789,6 @@ test "it approves a friend request" do
|
||||||
|> assign(:user, user)
|
|> assign(:user, user)
|
||||||
|> post("/api/pleroma/friendships/approve", %{"user_id" => other_user.id})
|
|> post("/api/pleroma/friendships/approve", %{"user_id" => other_user.id})
|
||||||
|
|
||||||
user = Repo.get(User, user.id)
|
|
||||||
|
|
||||||
assert relationship = json_response(conn, 200)
|
assert relationship = json_response(conn, 200)
|
||||||
assert other_user.id == relationship["id"]
|
assert other_user.id == relationship["id"]
|
||||||
assert relationship["follows_you"] == true
|
assert relationship["follows_you"] == true
|
||||||
|
@ -1787,8 +1812,6 @@ test "it denies a friend request" do
|
||||||
|> assign(:user, user)
|
|> assign(:user, user)
|
||||||
|> post("/api/pleroma/friendships/deny", %{"user_id" => other_user.id})
|
|> post("/api/pleroma/friendships/deny", %{"user_id" => other_user.id})
|
||||||
|
|
||||||
user = Repo.get(User, user.id)
|
|
||||||
|
|
||||||
assert relationship = json_response(conn, 200)
|
assert relationship = json_response(conn, 200)
|
||||||
assert other_user.id == relationship["id"]
|
assert other_user.id == relationship["id"]
|
||||||
assert relationship["follows_you"] == false
|
assert relationship["follows_you"] == false
|
||||||
|
|
Loading…
Reference in a new issue