mirror of
https://git.youjo.love/youjo/youjo-be.git
synced 2024-11-20 05:49:54 +01:00
some fixes
This commit is contained in:
parent
b9acf25060
commit
b5b0a0d332
7 changed files with 140 additions and 169 deletions
|
@ -1289,7 +1289,6 @@ defmodule Pleroma.Web.ActivityPub.ActivityPub do
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
||||||
defp exclude_chat_messages(query, %{include_chat_messages: true}), do: query
|
defp exclude_chat_messages(query, %{include_chat_messages: true}), do: query
|
||||||
|
|
||||||
defp exclude_chat_messages(query, _) do
|
defp exclude_chat_messages(query, _) do
|
||||||
|
@ -1627,8 +1626,7 @@ defmodule Pleroma.Web.ActivityPub.ActivityPub do
|
||||||
shared_inbox: shared_inbox,
|
shared_inbox: shared_inbox,
|
||||||
pinned_objects: pinned_objects,
|
pinned_objects: pinned_objects,
|
||||||
nickname: nickname,
|
nickname: nickname,
|
||||||
accepts_chat_messages: accepts_chat_messages,
|
accepts_chat_messages: accepts_chat_messages
|
||||||
pinned_objects: pinned_objects
|
|
||||||
}
|
}
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
|
@ -27,7 +27,7 @@ defmodule Pleroma.Web.ActivityPub.ObjectValidators.CommonFields do
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
# All objects except Answer and CHatMessage
|
# All objects except Answer and ChatMessage
|
||||||
defmacro object_fields do
|
defmacro object_fields do
|
||||||
quote bind_quoted: binding() do
|
quote bind_quoted: binding() do
|
||||||
field(:content, :string)
|
field(:content, :string)
|
||||||
|
|
|
@ -128,28 +128,6 @@ defmodule Pleroma.Web.ApiSpec.ChatOperation do
|
||||||
}
|
}
|
||||||
end
|
end
|
||||||
|
|
||||||
def index_operation do
|
|
||||||
%Operation{
|
|
||||||
tags: ["Chats"],
|
|
||||||
summary: "Retrieve list of chats (unpaginated)",
|
|
||||||
deprecated: true,
|
|
||||||
description:
|
|
||||||
"Deprecated due to no support for pagination. Using [/api/v2/pleroma/chats](#operation/ChatController.index2) instead is recommended.",
|
|
||||||
operationId: "ChatController.index",
|
|
||||||
parameters: [
|
|
||||||
Operation.parameter(:with_muted, :query, BooleanLike, "Include chats from muted users")
|
|
||||||
],
|
|
||||||
responses: %{
|
|
||||||
200 => Operation.response("The chats of the user", "application/json", chats_response())
|
|
||||||
},
|
|
||||||
security: [
|
|
||||||
%{
|
|
||||||
"oAuth" => ["read:chats"]
|
|
||||||
}
|
|
||||||
]
|
|
||||||
}
|
|
||||||
end
|
|
||||||
|
|
||||||
def index2_operation do
|
def index2_operation do
|
||||||
%Operation{
|
%Operation{
|
||||||
tags: ["Chats"],
|
tags: ["Chats"],
|
||||||
|
|
|
@ -46,8 +46,12 @@ defmodule Pleroma.Web.ApiSpec.Schemas.Account do
|
||||||
type: :boolean,
|
type: :boolean,
|
||||||
description: "whether the user allows automatically follow moved following accounts"
|
description: "whether the user allows automatically follow moved following accounts"
|
||||||
},
|
},
|
||||||
background_image: %Schema{type: :string, nullable: true, format: :uri},
|
background_image: %Schema{
|
||||||
chat_token: %Schema{type: :string},
|
type: :string, nullable: true, format: :uri
|
||||||
|
},
|
||||||
|
chat_token: %Schema{
|
||||||
|
type: :string
|
||||||
|
},
|
||||||
is_confirmed: %Schema{
|
is_confirmed: %Schema{
|
||||||
type: :boolean,
|
type: :boolean,
|
||||||
description:
|
description:
|
||||||
|
|
|
@ -70,6 +70,13 @@ defmodule Pleroma.Web.MastodonAPI.InstanceView do
|
||||||
if Config.get([:media_proxy, :enabled]) do
|
if Config.get([:media_proxy, :enabled]) do
|
||||||
"media_proxy"
|
"media_proxy"
|
||||||
end,
|
end,
|
||||||
|
# backwards compat
|
||||||
|
if Config.get([:shout, :enabled]) do
|
||||||
|
"chat"
|
||||||
|
end,
|
||||||
|
if Config.get([:shout, :enabled]) do
|
||||||
|
"shout"
|
||||||
|
end,
|
||||||
if Config.get([:instance, :allow_relay]) do
|
if Config.get([:instance, :allow_relay]) do
|
||||||
"relay"
|
"relay"
|
||||||
end,
|
end,
|
||||||
|
@ -77,6 +84,7 @@ defmodule Pleroma.Web.MastodonAPI.InstanceView do
|
||||||
"safe_dm_mentions"
|
"safe_dm_mentions"
|
||||||
end,
|
end,
|
||||||
"pleroma_emoji_reactions",
|
"pleroma_emoji_reactions",
|
||||||
|
"pleroma_chat_messages",
|
||||||
if Config.get([:instance, :show_reactions]) do
|
if Config.get([:instance, :show_reactions]) do
|
||||||
"exposable_reactions"
|
"exposable_reactions"
|
||||||
end,
|
end,
|
||||||
|
|
|
@ -133,6 +133,7 @@ defmodule Pleroma.Web.NodeInfoTest do
|
||||||
|
|
||||||
default_features = [
|
default_features = [
|
||||||
"pleroma_api",
|
"pleroma_api",
|
||||||
|
"akkoma_api",
|
||||||
"mastodon_api",
|
"mastodon_api",
|
||||||
"mastodon_api_streaming",
|
"mastodon_api_streaming",
|
||||||
"polls",
|
"polls",
|
||||||
|
|
|
@ -307,8 +307,7 @@ defmodule Pleroma.Web.PleromaAPI.ChatControllerTest do
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
for tested_endpoint <- ["/api/v1/pleroma/chats", "/api/v2/pleroma/chats"] do
|
describe "GET /api/v2/pleroma/chats" do
|
||||||
describe "GET #{tested_endpoint}" do
|
|
||||||
setup do: oauth_access(["read:chats"])
|
setup do: oauth_access(["read:chats"])
|
||||||
|
|
||||||
test "it does not return chats with deleted users", %{conn: conn, user: user} do
|
test "it does not return chats with deleted users", %{conn: conn, user: user} do
|
||||||
|
@ -320,7 +319,7 @@ defmodule Pleroma.Web.PleromaAPI.ChatControllerTest do
|
||||||
|
|
||||||
result =
|
result =
|
||||||
conn
|
conn
|
||||||
|> get(unquote(tested_endpoint))
|
|> get("/api/v2/pleroma/chats")
|
||||||
|> json_response_and_validate_schema(200)
|
|> json_response_and_validate_schema(200)
|
||||||
|
|
||||||
assert length(result) == 0
|
assert length(result) == 0
|
||||||
|
@ -333,7 +332,7 @@ defmodule Pleroma.Web.PleromaAPI.ChatControllerTest do
|
||||||
|
|
||||||
result =
|
result =
|
||||||
conn
|
conn
|
||||||
|> get(unquote(tested_endpoint))
|
|> get("/api/v2/pleroma/chats")
|
||||||
|> json_response_and_validate_schema(200)
|
|> json_response_and_validate_schema(200)
|
||||||
|
|
||||||
assert length(result) == 1
|
assert length(result) == 1
|
||||||
|
@ -342,7 +341,7 @@ defmodule Pleroma.Web.PleromaAPI.ChatControllerTest do
|
||||||
|
|
||||||
result =
|
result =
|
||||||
conn
|
conn
|
||||||
|> get(unquote(tested_endpoint))
|
|> get("/api/v2/pleroma/chats")
|
||||||
|> json_response_and_validate_schema(200)
|
|> json_response_and_validate_schema(200)
|
||||||
|
|
||||||
assert length(result) == 0
|
assert length(result) == 0
|
||||||
|
@ -355,7 +354,7 @@ defmodule Pleroma.Web.PleromaAPI.ChatControllerTest do
|
||||||
|
|
||||||
result =
|
result =
|
||||||
conn
|
conn
|
||||||
|> get(unquote(tested_endpoint))
|
|> get("/api/v2/pleroma/chats")
|
||||||
|> json_response_and_validate_schema(200)
|
|> json_response_and_validate_schema(200)
|
||||||
|
|
||||||
assert length(result) == 1
|
assert length(result) == 1
|
||||||
|
@ -364,34 +363,19 @@ defmodule Pleroma.Web.PleromaAPI.ChatControllerTest do
|
||||||
|
|
||||||
result =
|
result =
|
||||||
conn
|
conn
|
||||||
|> get(unquote(tested_endpoint))
|
|> get("/api/v2/pleroma/chats")
|
||||||
|> json_response_and_validate_schema(200)
|
|> json_response_and_validate_schema(200)
|
||||||
|
|
||||||
assert length(result) == 0
|
assert length(result) == 0
|
||||||
|
|
||||||
result =
|
result =
|
||||||
conn
|
conn
|
||||||
|> get("#{unquote(tested_endpoint)}?with_muted=true")
|
|> get("/api/v2/pleroma/chats?with_muted=true")
|
||||||
|> json_response_and_validate_schema(200)
|
|> json_response_and_validate_schema(200)
|
||||||
|
|
||||||
assert length(result) == 1
|
assert length(result) == 1
|
||||||
end
|
end
|
||||||
|
|
||||||
if tested_endpoint == "/api/v1/pleroma/chats" do
|
|
||||||
test "it returns all chats", %{conn: conn, user: user} do
|
|
||||||
Enum.each(1..30, fn _ ->
|
|
||||||
recipient = insert(:user)
|
|
||||||
{:ok, _} = Chat.get_or_create(user.id, recipient.ap_id)
|
|
||||||
end)
|
|
||||||
|
|
||||||
result =
|
|
||||||
conn
|
|
||||||
|> get(unquote(tested_endpoint))
|
|
||||||
|> json_response_and_validate_schema(200)
|
|
||||||
|
|
||||||
assert length(result) == 30
|
|
||||||
end
|
|
||||||
else
|
|
||||||
test "it paginates chats", %{conn: conn, user: user} do
|
test "it paginates chats", %{conn: conn, user: user} do
|
||||||
Enum.each(1..30, fn _ ->
|
Enum.each(1..30, fn _ ->
|
||||||
recipient = insert(:user)
|
recipient = insert(:user)
|
||||||
|
@ -400,7 +384,7 @@ defmodule Pleroma.Web.PleromaAPI.ChatControllerTest do
|
||||||
|
|
||||||
result =
|
result =
|
||||||
conn
|
conn
|
||||||
|> get(unquote(tested_endpoint))
|
|> get("/api/v2/pleroma/chats")
|
||||||
|> json_response_and_validate_schema(200)
|
|> json_response_and_validate_schema(200)
|
||||||
|
|
||||||
assert length(result) == 20
|
assert length(result) == 20
|
||||||
|
@ -408,12 +392,11 @@ defmodule Pleroma.Web.PleromaAPI.ChatControllerTest do
|
||||||
|
|
||||||
result =
|
result =
|
||||||
conn
|
conn
|
||||||
|> get(unquote(tested_endpoint) <> "?max_id=#{last_id}")
|
|> get("/api/v2/pleroma/chats?max_id=#{last_id}")
|
||||||
|> json_response_and_validate_schema(200)
|
|> json_response_and_validate_schema(200)
|
||||||
|
|
||||||
assert length(result) == 10
|
assert length(result) == 10
|
||||||
end
|
end
|
||||||
end
|
|
||||||
|
|
||||||
test "it return a list of chats the current user is participating in, in descending order of updates",
|
test "it return a list of chats the current user is participating in, in descending order of updates",
|
||||||
%{conn: conn, user: user} do
|
%{conn: conn, user: user} do
|
||||||
|
@ -433,7 +416,7 @@ defmodule Pleroma.Web.PleromaAPI.ChatControllerTest do
|
||||||
|
|
||||||
result =
|
result =
|
||||||
conn
|
conn
|
||||||
|> get(unquote(tested_endpoint))
|
|> get("/api/v2/pleroma/chats")
|
||||||
|> json_response_and_validate_schema(200)
|
|> json_response_and_validate_schema(200)
|
||||||
|
|
||||||
ids = Enum.map(result, & &1["id"])
|
ids = Enum.map(result, & &1["id"])
|
||||||
|
@ -460,12 +443,11 @@ defmodule Pleroma.Web.PleromaAPI.ChatControllerTest do
|
||||||
|
|
||||||
result =
|
result =
|
||||||
conn
|
conn
|
||||||
|> get(unquote(tested_endpoint))
|
|> get("/api/v2/pleroma/chats")
|
||||||
|> json_response_and_validate_schema(200)
|
|> json_response_and_validate_schema(200)
|
||||||
|
|
||||||
account_ids = Enum.map(result, &get_in(&1, ["account", "id"]))
|
account_ids = Enum.map(result, &get_in(&1, ["account", "id"]))
|
||||||
assert Enum.sort(account_ids) == Enum.sort([user2.id, user3.id])
|
assert Enum.sort(account_ids) == Enum.sort([user2.id, user3.id])
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
|
||||||
end
|
end
|
||||||
|
|
Loading…
Reference in a new issue