Merge branch 'conversations_three' into 'develop'
Conversations once more. See merge request pleroma/pleroma!1119
This commit is contained in:
commit
238dd72fad
16 changed files with 710 additions and 34 deletions
|
|
@ -22,6 +22,28 @@ defmodule Pleroma.Web.ActivityPub.ActivityPubTest do
|
|||
:ok
|
||||
end
|
||||
|
||||
describe "streaming out participations" do
|
||||
test "it streams them out" do
|
||||
user = insert(:user)
|
||||
{:ok, activity} = CommonAPI.post(user, %{"status" => ".", "visibility" => "direct"})
|
||||
|
||||
{:ok, conversation} = Pleroma.Conversation.create_or_bump_for(activity)
|
||||
|
||||
participations =
|
||||
conversation.participations
|
||||
|> Repo.preload(:user)
|
||||
|
||||
with_mock Pleroma.Web.Streamer,
|
||||
stream: fn _, _ -> nil end do
|
||||
ActivityPub.stream_out_participations(conversation.participations)
|
||||
|
||||
Enum.each(participations, fn participation ->
|
||||
assert called(Pleroma.Web.Streamer.stream("participation", participation))
|
||||
end)
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
describe "fetching restricted by visibility" do
|
||||
test "it restricts by the appropriate visibility" do
|
||||
user = insert(:user)
|
||||
|
|
@ -130,9 +152,15 @@ defmodule Pleroma.Web.ActivityPub.ActivityPubTest do
|
|||
end
|
||||
|
||||
test "doesn't drop activities with content being null" do
|
||||
user = insert(:user)
|
||||
|
||||
data = %{
|
||||
"ok" => true,
|
||||
"actor" => user.ap_id,
|
||||
"to" => [],
|
||||
"object" => %{
|
||||
"actor" => user.ap_id,
|
||||
"to" => [],
|
||||
"type" => "Note",
|
||||
"content" => nil
|
||||
}
|
||||
}
|
||||
|
|
@ -148,8 +176,17 @@ defmodule Pleroma.Web.ActivityPub.ActivityPubTest do
|
|||
end
|
||||
|
||||
test "inserts a given map into the activity database, giving it an id if it has none." do
|
||||
user = insert(:user)
|
||||
|
||||
data = %{
|
||||
"ok" => true
|
||||
"actor" => user.ap_id,
|
||||
"to" => [],
|
||||
"object" => %{
|
||||
"actor" => user.ap_id,
|
||||
"to" => [],
|
||||
"type" => "Note",
|
||||
"content" => "hey"
|
||||
}
|
||||
}
|
||||
|
||||
{:ok, %Activity{} = activity} = ActivityPub.insert(data)
|
||||
|
|
@ -159,9 +196,16 @@ defmodule Pleroma.Web.ActivityPub.ActivityPubTest do
|
|||
given_id = "bla"
|
||||
|
||||
data = %{
|
||||
"ok" => true,
|
||||
"id" => given_id,
|
||||
"context" => "blabla"
|
||||
"actor" => user.ap_id,
|
||||
"to" => [],
|
||||
"context" => "blabla",
|
||||
"object" => %{
|
||||
"actor" => user.ap_id,
|
||||
"to" => [],
|
||||
"type" => "Note",
|
||||
"content" => "hey"
|
||||
}
|
||||
}
|
||||
|
||||
{:ok, %Activity{} = activity} = ActivityPub.insert(data)
|
||||
|
|
@ -172,26 +216,39 @@ defmodule Pleroma.Web.ActivityPub.ActivityPubTest do
|
|||
end
|
||||
|
||||
test "adds a context when none is there" do
|
||||
user = insert(:user)
|
||||
|
||||
data = %{
|
||||
"id" => "some_id",
|
||||
"actor" => user.ap_id,
|
||||
"to" => [],
|
||||
"object" => %{
|
||||
"id" => "object_id"
|
||||
"actor" => user.ap_id,
|
||||
"to" => [],
|
||||
"type" => "Note",
|
||||
"content" => "hey"
|
||||
}
|
||||
}
|
||||
|
||||
{:ok, %Activity{} = activity} = ActivityPub.insert(data)
|
||||
object = Pleroma.Object.normalize(activity)
|
||||
|
||||
assert is_binary(activity.data["context"])
|
||||
assert is_binary(activity.data["object"]["context"])
|
||||
assert is_binary(object.data["context"])
|
||||
assert activity.data["context_id"]
|
||||
assert activity.data["object"]["context_id"]
|
||||
assert object.data["context_id"]
|
||||
end
|
||||
|
||||
test "adds an id to a given object if it lacks one and is a note and inserts it to the object database" do
|
||||
user = insert(:user)
|
||||
|
||||
data = %{
|
||||
"actor" => user.ap_id,
|
||||
"to" => [],
|
||||
"object" => %{
|
||||
"actor" => user.ap_id,
|
||||
"to" => [],
|
||||
"type" => "Note",
|
||||
"ok" => true
|
||||
"content" => "hey"
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -300,6 +300,65 @@ defmodule Pleroma.Web.MastodonAPI.MastodonAPIControllerTest do
|
|||
assert status["url"] != direct.data["id"]
|
||||
end
|
||||
|
||||
test "Conversations", %{conn: conn} do
|
||||
user_one = insert(:user)
|
||||
user_two = insert(:user)
|
||||
|
||||
{:ok, user_two} = User.follow(user_two, user_one)
|
||||
|
||||
{:ok, direct} =
|
||||
CommonAPI.post(user_one, %{
|
||||
"status" => "Hi @#{user_two.nickname}!",
|
||||
"visibility" => "direct"
|
||||
})
|
||||
|
||||
{:ok, _follower_only} =
|
||||
CommonAPI.post(user_one, %{
|
||||
"status" => "Hi @#{user_two.nickname}!",
|
||||
"visibility" => "private"
|
||||
})
|
||||
|
||||
res_conn =
|
||||
conn
|
||||
|> assign(:user, user_one)
|
||||
|> get("/api/v1/conversations")
|
||||
|
||||
assert response = json_response(res_conn, 200)
|
||||
|
||||
assert [
|
||||
%{
|
||||
"id" => res_id,
|
||||
"accounts" => res_accounts,
|
||||
"last_status" => res_last_status,
|
||||
"unread" => unread
|
||||
}
|
||||
] = response
|
||||
|
||||
assert length(res_accounts) == 2
|
||||
assert is_binary(res_id)
|
||||
assert unread == true
|
||||
assert res_last_status["id"] == direct.id
|
||||
|
||||
# Apparently undocumented API endpoint
|
||||
res_conn =
|
||||
conn
|
||||
|> assign(:user, user_one)
|
||||
|> post("/api/v1/conversations/#{res_id}/read")
|
||||
|
||||
assert response = json_response(res_conn, 200)
|
||||
assert length(response["accounts"]) == 2
|
||||
assert response["last_status"]["id"] == direct.id
|
||||
assert response["unread"] == false
|
||||
|
||||
# (vanilla) Mastodon frontend behaviour
|
||||
res_conn =
|
||||
conn
|
||||
|> assign(:user, user_one)
|
||||
|> get("/api/v1/statuses/#{res_last_status["id"]}/context")
|
||||
|
||||
assert %{"ancestors" => [], "descendants" => []} == json_response(res_conn, 200)
|
||||
end
|
||||
|
||||
test "doesn't include DMs from blocked users", %{conn: conn} do
|
||||
blocker = insert(:user)
|
||||
blocked = insert(:user)
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue