Merge remote-tracking branch 'remotes/origin/develop' into feature/object-hashtags-rework
# Conflicts: # CHANGELOG.md # lib/pleroma/web/activity_pub/activity_pub.ex
This commit is contained in:
commit
4e14945670
130 changed files with 923 additions and 175 deletions
|
|
@ -2232,6 +2232,36 @@ defmodule Pleroma.UserTest do
|
|||
end
|
||||
end
|
||||
|
||||
describe "local_nickname/1" do
|
||||
test "returns nickname without host" do
|
||||
assert User.local_nickname("@mentioned") == "mentioned"
|
||||
assert User.local_nickname("a_local_nickname") == "a_local_nickname"
|
||||
assert User.local_nickname("nickname@host.com") == "nickname"
|
||||
end
|
||||
end
|
||||
|
||||
describe "full_nickname/1" do
|
||||
test "returns fully qualified nickname for local and remote users" do
|
||||
local_user =
|
||||
insert(:user, nickname: "local_user", ap_id: "https://somehost.com/users/local_user")
|
||||
|
||||
remote_user = insert(:user, nickname: "remote@host.com", local: false)
|
||||
|
||||
assert User.full_nickname(local_user) == "local_user@somehost.com"
|
||||
assert User.full_nickname(remote_user) == "remote@host.com"
|
||||
end
|
||||
|
||||
test "strips leading @ from mentions" do
|
||||
assert User.full_nickname("@mentioned") == "mentioned"
|
||||
assert User.full_nickname("@nickname@host.com") == "nickname@host.com"
|
||||
end
|
||||
|
||||
test "does not modify nicknames" do
|
||||
assert User.full_nickname("nickname") == "nickname"
|
||||
assert User.full_nickname("nickname@host.com") == "nickname@host.com"
|
||||
end
|
||||
end
|
||||
|
||||
test "avatar fallback" do
|
||||
user = insert(:user)
|
||||
assert User.avatar_url(user) =~ "/images/avi.png"
|
||||
|
|
@ -2248,4 +2278,43 @@ defmodule Pleroma.UserTest do
|
|||
user = insert(:user, ap_id: "https://lain.com/users/lain", nickname: "lain")
|
||||
assert User.get_host(user) == "lain.com"
|
||||
end
|
||||
|
||||
test "update_last_active_at/1" do
|
||||
user = insert(:user)
|
||||
assert is_nil(user.last_active_at)
|
||||
|
||||
test_started_at = NaiveDateTime.utc_now() |> NaiveDateTime.truncate(:second)
|
||||
|
||||
assert {:ok, user} = User.update_last_active_at(user)
|
||||
|
||||
assert user.last_active_at >= test_started_at
|
||||
assert user.last_active_at <= NaiveDateTime.truncate(NaiveDateTime.utc_now(), :second)
|
||||
|
||||
last_active_at =
|
||||
NaiveDateTime.utc_now()
|
||||
|> NaiveDateTime.add(-:timer.hours(24), :millisecond)
|
||||
|> NaiveDateTime.truncate(:second)
|
||||
|
||||
assert {:ok, user} =
|
||||
user
|
||||
|> cast(%{last_active_at: last_active_at}, [:last_active_at])
|
||||
|> User.update_and_set_cache()
|
||||
|
||||
assert user.last_active_at == last_active_at
|
||||
assert {:ok, user} = User.update_last_active_at(user)
|
||||
assert user.last_active_at >= test_started_at
|
||||
assert user.last_active_at <= NaiveDateTime.truncate(NaiveDateTime.utc_now(), :second)
|
||||
end
|
||||
|
||||
test "active_user_count/1" do
|
||||
insert(:user)
|
||||
insert(:user, %{local: false})
|
||||
insert(:user, %{last_active_at: Timex.shift(NaiveDateTime.utc_now(), weeks: -5)})
|
||||
insert(:user, %{last_active_at: Timex.shift(NaiveDateTime.utc_now(), weeks: -3)})
|
||||
insert(:user, %{last_active_at: NaiveDateTime.utc_now()})
|
||||
|
||||
assert User.active_user_count() == 2
|
||||
assert User.active_user_count(6) == 3
|
||||
assert User.active_user_count(1) == 1
|
||||
end
|
||||
end
|
||||
|
|
|
|||
|
|
@ -1607,9 +1607,9 @@ defmodule Pleroma.Web.ActivityPub.ActivityPubControllerTest do
|
|||
desc = "Description of the image"
|
||||
|
||||
image = %Plug.Upload{
|
||||
content_type: "bad/content-type",
|
||||
content_type: "image/jpeg",
|
||||
path: Path.absname("test/fixtures/image.jpg"),
|
||||
filename: "an_image.png"
|
||||
filename: "an_image.jpg"
|
||||
}
|
||||
|
||||
object =
|
||||
|
|
|
|||
|
|
@ -29,6 +29,45 @@ defmodule Pleroma.Web.MastodonAPI.AccountControllerTest do
|
|||
|> json_response_and_validate_schema(404)
|
||||
end
|
||||
|
||||
test "relationship field" do
|
||||
%{conn: conn, user: user} = oauth_access(["read"])
|
||||
|
||||
other_user = insert(:user)
|
||||
|
||||
response =
|
||||
conn
|
||||
|> get("/api/v1/accounts/#{other_user.id}")
|
||||
|> json_response_and_validate_schema(200)
|
||||
|
||||
assert response["id"] == other_user.id
|
||||
assert response["pleroma"]["relationship"] == %{}
|
||||
|
||||
assert %{"pleroma" => %{"relationship" => %{"following" => false, "followed_by" => false}}} =
|
||||
conn
|
||||
|> get("/api/v1/accounts/#{other_user.id}?with_relationships=true")
|
||||
|> json_response_and_validate_schema(200)
|
||||
|
||||
{:ok, _, %{id: other_id}} = User.follow(user, other_user)
|
||||
|
||||
assert %{
|
||||
"id" => ^other_id,
|
||||
"pleroma" => %{"relationship" => %{"following" => true, "followed_by" => false}}
|
||||
} =
|
||||
conn
|
||||
|> get("/api/v1/accounts/#{other_id}?with_relationships=true")
|
||||
|> json_response_and_validate_schema(200)
|
||||
|
||||
{:ok, _, _} = User.follow(other_user, user)
|
||||
|
||||
assert %{
|
||||
"id" => ^other_id,
|
||||
"pleroma" => %{"relationship" => %{"following" => true, "followed_by" => true}}
|
||||
} =
|
||||
conn
|
||||
|> get("/api/v1/accounts/#{other_id}?with_relationships=true")
|
||||
|> json_response_and_validate_schema(200)
|
||||
end
|
||||
|
||||
test "works by nickname" do
|
||||
user = insert(:user)
|
||||
|
||||
|
|
@ -590,6 +629,45 @@ defmodule Pleroma.Web.MastodonAPI.AccountControllerTest do
|
|||
assert [%{"id" => ^user_id}] = json_response_and_validate_schema(conn, 200)
|
||||
end
|
||||
|
||||
test "following with relationship", %{conn: conn, user: user} do
|
||||
other_user = insert(:user)
|
||||
{:ok, %{id: id}, _} = User.follow(other_user, user)
|
||||
|
||||
assert [
|
||||
%{
|
||||
"id" => ^id,
|
||||
"pleroma" => %{
|
||||
"relationship" => %{
|
||||
"id" => ^id,
|
||||
"following" => false,
|
||||
"followed_by" => true
|
||||
}
|
||||
}
|
||||
}
|
||||
] =
|
||||
conn
|
||||
|> get("/api/v1/accounts/#{user.id}/followers?with_relationships=true")
|
||||
|> json_response_and_validate_schema(200)
|
||||
|
||||
{:ok, _, _} = User.follow(user, other_user)
|
||||
|
||||
assert [
|
||||
%{
|
||||
"id" => ^id,
|
||||
"pleroma" => %{
|
||||
"relationship" => %{
|
||||
"id" => ^id,
|
||||
"following" => true,
|
||||
"followed_by" => true
|
||||
}
|
||||
}
|
||||
}
|
||||
] =
|
||||
conn
|
||||
|> get("/api/v1/accounts/#{user.id}/followers?with_relationships=true")
|
||||
|> json_response_and_validate_schema(200)
|
||||
end
|
||||
|
||||
test "getting followers, hide_followers", %{user: user, conn: conn} do
|
||||
other_user = insert(:user, hide_followers: true)
|
||||
{:ok, _user, _other_user} = User.follow(user, other_user)
|
||||
|
|
@ -660,6 +738,24 @@ defmodule Pleroma.Web.MastodonAPI.AccountControllerTest do
|
|||
assert id == to_string(other_user.id)
|
||||
end
|
||||
|
||||
test "following with relationship", %{conn: conn, user: user} do
|
||||
other_user = insert(:user)
|
||||
{:ok, user, other_user} = User.follow(user, other_user)
|
||||
|
||||
conn = get(conn, "/api/v1/accounts/#{user.id}/following?with_relationships=true")
|
||||
|
||||
id = other_user.id
|
||||
|
||||
assert [
|
||||
%{
|
||||
"id" => ^id,
|
||||
"pleroma" => %{
|
||||
"relationship" => %{"id" => ^id, "following" => true, "followed_by" => false}
|
||||
}
|
||||
}
|
||||
] = json_response_and_validate_schema(conn, 200)
|
||||
end
|
||||
|
||||
test "getting following, hide_follows, other user requesting" do
|
||||
user = insert(:user, hide_follows: true)
|
||||
other_user = insert(:user)
|
||||
|
|
@ -1565,7 +1661,6 @@ defmodule Pleroma.Web.MastodonAPI.AccountControllerTest do
|
|||
|
||||
result =
|
||||
conn
|
||||
|> assign(:user, user)
|
||||
|> get("/api/v1/mutes")
|
||||
|> json_response_and_validate_schema(200)
|
||||
|
||||
|
|
@ -1573,7 +1668,6 @@ defmodule Pleroma.Web.MastodonAPI.AccountControllerTest do
|
|||
|
||||
result =
|
||||
conn
|
||||
|> assign(:user, user)
|
||||
|> get("/api/v1/mutes?limit=1")
|
||||
|> json_response_and_validate_schema(200)
|
||||
|
||||
|
|
@ -1581,7 +1675,6 @@ defmodule Pleroma.Web.MastodonAPI.AccountControllerTest do
|
|||
|
||||
result =
|
||||
conn
|
||||
|> assign(:user, user)
|
||||
|> get("/api/v1/mutes?since_id=#{id1}")
|
||||
|> json_response_and_validate_schema(200)
|
||||
|
||||
|
|
@ -1589,7 +1682,6 @@ defmodule Pleroma.Web.MastodonAPI.AccountControllerTest do
|
|||
|
||||
result =
|
||||
conn
|
||||
|> assign(:user, user)
|
||||
|> get("/api/v1/mutes?since_id=#{id1}&max_id=#{id3}")
|
||||
|> json_response_and_validate_schema(200)
|
||||
|
||||
|
|
@ -1597,13 +1689,45 @@ defmodule Pleroma.Web.MastodonAPI.AccountControllerTest do
|
|||
|
||||
result =
|
||||
conn
|
||||
|> assign(:user, user)
|
||||
|> get("/api/v1/mutes?since_id=#{id1}&limit=1")
|
||||
|> json_response_and_validate_schema(200)
|
||||
|
||||
assert [%{"id" => ^id2}] = result
|
||||
end
|
||||
|
||||
test "list of mutes with with_relationships parameter" do
|
||||
%{user: user, conn: conn} = oauth_access(["read:mutes"])
|
||||
%{id: id1} = other_user1 = insert(:user)
|
||||
%{id: id2} = other_user2 = insert(:user)
|
||||
%{id: id3} = other_user3 = insert(:user)
|
||||
|
||||
{:ok, _, _} = User.follow(other_user1, user)
|
||||
{:ok, _, _} = User.follow(other_user2, user)
|
||||
{:ok, _, _} = User.follow(other_user3, user)
|
||||
|
||||
{:ok, _} = User.mute(user, other_user1)
|
||||
{:ok, _} = User.mute(user, other_user2)
|
||||
{:ok, _} = User.mute(user, other_user3)
|
||||
|
||||
assert [
|
||||
%{
|
||||
"id" => ^id1,
|
||||
"pleroma" => %{"relationship" => %{"muting" => true, "followed_by" => true}}
|
||||
},
|
||||
%{
|
||||
"id" => ^id2,
|
||||
"pleroma" => %{"relationship" => %{"muting" => true, "followed_by" => true}}
|
||||
},
|
||||
%{
|
||||
"id" => ^id3,
|
||||
"pleroma" => %{"relationship" => %{"muting" => true, "followed_by" => true}}
|
||||
}
|
||||
] =
|
||||
conn
|
||||
|> get("/api/v1/mutes?with_relationships=true")
|
||||
|> json_response_and_validate_schema(200)
|
||||
end
|
||||
|
||||
test "getting a list of blocks" do
|
||||
%{user: user, conn: conn} = oauth_access(["read:blocks"])
|
||||
%{id: id1} = other_user1 = insert(:user)
|
||||
|
|
|
|||
|
|
@ -47,6 +47,7 @@ defmodule Pleroma.Web.MastodonAPI.InstanceControllerTest do
|
|||
assert result["pleroma"]["metadata"]["federation"]
|
||||
assert result["pleroma"]["metadata"]["fields_limits"]
|
||||
assert result["pleroma"]["vapid_public_key"]
|
||||
assert result["pleroma"]["stats"]["mau"] == 0
|
||||
|
||||
assert email == from_config_email
|
||||
assert thumbnail == from_config_thumbnail
|
||||
|
|
|
|||
|
|
@ -263,6 +263,7 @@ defmodule Pleroma.Web.MastodonAPI.StatusControllerTest do
|
|||
|
||||
fake_conn =
|
||||
conn
|
||||
|> assign(:user, refresh_record(conn.assigns.user))
|
||||
|> put_req_header("content-type", "application/json")
|
||||
|> post("/api/v1/statuses", %{
|
||||
"status" =>
|
||||
|
|
|
|||
|
|
@ -90,6 +90,65 @@ defmodule Pleroma.Web.MastodonAPI.TimelineControllerTest do
|
|||
}
|
||||
] = result
|
||||
end
|
||||
|
||||
test "filtering", %{conn: conn, user: user} do
|
||||
local_user = insert(:user)
|
||||
{:ok, user, local_user} = User.follow(user, local_user)
|
||||
{:ok, local_activity} = CommonAPI.post(local_user, %{status: "Status"})
|
||||
with_media = create_with_media_activity(local_user)
|
||||
|
||||
remote_user = insert(:user, local: false)
|
||||
{:ok, _user, remote_user} = User.follow(user, remote_user)
|
||||
remote_activity = create_remote_activity(remote_user)
|
||||
|
||||
without_filter_ids =
|
||||
conn
|
||||
|> get("/api/v1/timelines/home")
|
||||
|> json_response_and_validate_schema(200)
|
||||
|> Enum.map(& &1["id"])
|
||||
|
||||
assert local_activity.id in without_filter_ids
|
||||
assert remote_activity.id in without_filter_ids
|
||||
assert with_media.id in without_filter_ids
|
||||
|
||||
only_local_ids =
|
||||
conn
|
||||
|> get("/api/v1/timelines/home?local=true")
|
||||
|> json_response_and_validate_schema(200)
|
||||
|> Enum.map(& &1["id"])
|
||||
|
||||
assert local_activity.id in only_local_ids
|
||||
refute remote_activity.id in only_local_ids
|
||||
assert with_media.id in only_local_ids
|
||||
|
||||
only_local_media_ids =
|
||||
conn
|
||||
|> get("/api/v1/timelines/home?local=true&only_media=true")
|
||||
|> json_response_and_validate_schema(200)
|
||||
|> Enum.map(& &1["id"])
|
||||
|
||||
refute local_activity.id in only_local_media_ids
|
||||
refute remote_activity.id in only_local_media_ids
|
||||
assert with_media.id in only_local_media_ids
|
||||
|
||||
remote_ids =
|
||||
conn
|
||||
|> get("/api/v1/timelines/home?remote=true")
|
||||
|> json_response_and_validate_schema(200)
|
||||
|> Enum.map(& &1["id"])
|
||||
|
||||
refute local_activity.id in remote_ids
|
||||
assert remote_activity.id in remote_ids
|
||||
refute with_media.id in remote_ids
|
||||
|
||||
assert conn
|
||||
|> get("/api/v1/timelines/home?remote=true&only_media=true")
|
||||
|> json_response_and_validate_schema(200) == []
|
||||
|
||||
assert conn
|
||||
|> get("/api/v1/timelines/home?remote=true&local=true")
|
||||
|> json_response_and_validate_schema(200) == []
|
||||
end
|
||||
end
|
||||
|
||||
describe "public" do
|
||||
|
|
@ -98,27 +157,80 @@ defmodule Pleroma.Web.MastodonAPI.TimelineControllerTest do
|
|||
user = insert(:user)
|
||||
|
||||
{:ok, activity} = CommonAPI.post(user, %{status: "test"})
|
||||
with_media = create_with_media_activity(user)
|
||||
|
||||
_activity = insert(:note_activity, local: false)
|
||||
remote = insert(:note_activity, local: false)
|
||||
|
||||
conn = get(conn, "/api/v1/timelines/public?local=False")
|
||||
assert conn
|
||||
|> get("/api/v1/timelines/public?local=False")
|
||||
|> json_response_and_validate_schema(:ok)
|
||||
|> length == 3
|
||||
|
||||
assert length(json_response_and_validate_schema(conn, :ok)) == 2
|
||||
local_ids =
|
||||
conn
|
||||
|> get("/api/v1/timelines/public?local=True")
|
||||
|> json_response_and_validate_schema(:ok)
|
||||
|> Enum.map(& &1["id"])
|
||||
|
||||
conn = get(build_conn(), "/api/v1/timelines/public?local=True")
|
||||
assert activity.id in local_ids
|
||||
assert with_media.id in local_ids
|
||||
refute remote.id in local_ids
|
||||
|
||||
assert [%{"content" => "test"}] = json_response_and_validate_schema(conn, :ok)
|
||||
local_ids =
|
||||
conn
|
||||
|> get("/api/v1/timelines/public?local=True")
|
||||
|> json_response_and_validate_schema(:ok)
|
||||
|> Enum.map(& &1["id"])
|
||||
|
||||
conn = get(build_conn(), "/api/v1/timelines/public?local=1")
|
||||
assert activity.id in local_ids
|
||||
assert with_media.id in local_ids
|
||||
refute remote.id in local_ids
|
||||
|
||||
assert [%{"content" => "test"}] = json_response_and_validate_schema(conn, :ok)
|
||||
local_ids =
|
||||
conn
|
||||
|> get("/api/v1/timelines/public?local=True&only_media=true")
|
||||
|> json_response_and_validate_schema(:ok)
|
||||
|> Enum.map(& &1["id"])
|
||||
|
||||
refute activity.id in local_ids
|
||||
assert with_media.id in local_ids
|
||||
refute remote.id in local_ids
|
||||
|
||||
local_ids =
|
||||
conn
|
||||
|> get("/api/v1/timelines/public?local=1")
|
||||
|> json_response_and_validate_schema(:ok)
|
||||
|> Enum.map(& &1["id"])
|
||||
|
||||
assert activity.id in local_ids
|
||||
assert with_media.id in local_ids
|
||||
refute remote.id in local_ids
|
||||
|
||||
remote_id = remote.id
|
||||
|
||||
assert [%{"id" => ^remote_id}] =
|
||||
conn
|
||||
|> get("/api/v1/timelines/public?remote=true")
|
||||
|> json_response_and_validate_schema(:ok)
|
||||
|
||||
with_media_id = with_media.id
|
||||
|
||||
assert [%{"id" => ^with_media_id}] =
|
||||
conn
|
||||
|> get("/api/v1/timelines/public?only_media=true")
|
||||
|> json_response_and_validate_schema(:ok)
|
||||
|
||||
assert conn
|
||||
|> get("/api/v1/timelines/public?remote=true&only_media=true")
|
||||
|> json_response_and_validate_schema(:ok) == []
|
||||
|
||||
# does not contain repeats
|
||||
{:ok, _} = CommonAPI.repeat(activity.id, user)
|
||||
|
||||
conn = get(build_conn(), "/api/v1/timelines/public?local=true")
|
||||
|
||||
assert [_] = json_response_and_validate_schema(conn, :ok)
|
||||
assert [_, _] =
|
||||
conn
|
||||
|> get("/api/v1/timelines/public?local=true")
|
||||
|> json_response_and_validate_schema(:ok)
|
||||
end
|
||||
|
||||
test "the public timeline includes only public statuses for an authenticated user" do
|
||||
|
|
@ -544,6 +656,77 @@ defmodule Pleroma.Web.MastodonAPI.TimelineControllerTest do
|
|||
}
|
||||
] = result
|
||||
end
|
||||
|
||||
test "filtering", %{user: user, conn: conn} do
|
||||
{:ok, list} = Pleroma.List.create("name", user)
|
||||
|
||||
local_user = insert(:user)
|
||||
{:ok, local_activity} = CommonAPI.post(local_user, %{status: "Marisa is stupid."})
|
||||
with_media = create_with_media_activity(local_user)
|
||||
{:ok, list} = Pleroma.List.follow(list, local_user)
|
||||
|
||||
remote_user = insert(:user, local: false)
|
||||
remote_activity = create_remote_activity(remote_user)
|
||||
{:ok, list} = Pleroma.List.follow(list, remote_user)
|
||||
|
||||
all_ids =
|
||||
conn
|
||||
|> get("/api/v1/timelines/list/#{list.id}")
|
||||
|> json_response_and_validate_schema(200)
|
||||
|> Enum.map(& &1["id"])
|
||||
|
||||
assert local_activity.id in all_ids
|
||||
assert with_media.id in all_ids
|
||||
assert remote_activity.id in all_ids
|
||||
|
||||
only_local_ids =
|
||||
conn
|
||||
|> get("/api/v1/timelines/list/#{list.id}?local=true")
|
||||
|> json_response_and_validate_schema(200)
|
||||
|> Enum.map(& &1["id"])
|
||||
|
||||
assert local_activity.id in only_local_ids
|
||||
assert with_media.id in only_local_ids
|
||||
refute remote_activity.id in only_local_ids
|
||||
|
||||
only_local_media_ids =
|
||||
conn
|
||||
|> get("/api/v1/timelines/list/#{list.id}?local=true&only_media=true")
|
||||
|> json_response_and_validate_schema(200)
|
||||
|> Enum.map(& &1["id"])
|
||||
|
||||
refute local_activity.id in only_local_media_ids
|
||||
assert with_media.id in only_local_media_ids
|
||||
refute remote_activity.id in only_local_media_ids
|
||||
|
||||
remote_ids =
|
||||
conn
|
||||
|> get("/api/v1/timelines/list/#{list.id}?remote=true")
|
||||
|> json_response_and_validate_schema(200)
|
||||
|> Enum.map(& &1["id"])
|
||||
|
||||
refute local_activity.id in remote_ids
|
||||
refute with_media.id in remote_ids
|
||||
assert remote_activity.id in remote_ids
|
||||
|
||||
assert conn
|
||||
|> get("/api/v1/timelines/list/#{list.id}?remote=true&only_media=true")
|
||||
|> json_response_and_validate_schema(200) == []
|
||||
|
||||
only_media_ids =
|
||||
conn
|
||||
|> get("/api/v1/timelines/list/#{list.id}?only_media=true")
|
||||
|> json_response_and_validate_schema(200)
|
||||
|> Enum.map(& &1["id"])
|
||||
|
||||
refute local_activity.id in only_media_ids
|
||||
assert with_media.id in only_media_ids
|
||||
refute remote_activity.id in only_media_ids
|
||||
|
||||
assert conn
|
||||
|> get("/api/v1/timelines/list/#{list.id}?only_media=true&local=true&remote=true")
|
||||
|> json_response_and_validate_schema(200) == []
|
||||
end
|
||||
end
|
||||
|
||||
describe "hashtag" do
|
||||
|
|
@ -554,19 +737,85 @@ defmodule Pleroma.Web.MastodonAPI.TimelineControllerTest do
|
|||
following = insert(:user)
|
||||
|
||||
{:ok, activity} = CommonAPI.post(following, %{status: "test #2hu"})
|
||||
with_media = create_with_media_activity(following)
|
||||
|
||||
nconn = get(conn, "/api/v1/timelines/tag/2hu")
|
||||
remote = insert(:user, local: false)
|
||||
remote_activity = create_remote_activity(remote)
|
||||
|
||||
assert [%{"id" => id}] = json_response_and_validate_schema(nconn, :ok)
|
||||
all_ids =
|
||||
conn
|
||||
|> get("/api/v1/timelines/tag/2hu")
|
||||
|> json_response_and_validate_schema(:ok)
|
||||
|> Enum.map(& &1["id"])
|
||||
|
||||
assert id == to_string(activity.id)
|
||||
assert activity.id in all_ids
|
||||
assert with_media.id in all_ids
|
||||
assert remote_activity.id in all_ids
|
||||
|
||||
# works for different capitalization too
|
||||
nconn = get(conn, "/api/v1/timelines/tag/2HU")
|
||||
all_ids =
|
||||
conn
|
||||
|> get("/api/v1/timelines/tag/2HU")
|
||||
|> json_response_and_validate_schema(:ok)
|
||||
|> Enum.map(& &1["id"])
|
||||
|
||||
assert [%{"id" => id}] = json_response_and_validate_schema(nconn, :ok)
|
||||
assert activity.id in all_ids
|
||||
assert with_media.id in all_ids
|
||||
assert remote_activity.id in all_ids
|
||||
|
||||
assert id == to_string(activity.id)
|
||||
local_ids =
|
||||
conn
|
||||
|> get("/api/v1/timelines/tag/2hu?local=true")
|
||||
|> json_response_and_validate_schema(:ok)
|
||||
|> Enum.map(& &1["id"])
|
||||
|
||||
assert activity.id in local_ids
|
||||
assert with_media.id in local_ids
|
||||
refute remote_activity.id in local_ids
|
||||
|
||||
remote_ids =
|
||||
conn
|
||||
|> get("/api/v1/timelines/tag/2hu?remote=true")
|
||||
|> json_response_and_validate_schema(:ok)
|
||||
|> Enum.map(& &1["id"])
|
||||
|
||||
refute activity.id in remote_ids
|
||||
refute with_media.id in remote_ids
|
||||
assert remote_activity.id in remote_ids
|
||||
|
||||
media_ids =
|
||||
conn
|
||||
|> get("/api/v1/timelines/tag/2hu?only_media=true")
|
||||
|> json_response_and_validate_schema(:ok)
|
||||
|> Enum.map(& &1["id"])
|
||||
|
||||
refute activity.id in media_ids
|
||||
assert with_media.id in media_ids
|
||||
refute remote_activity.id in media_ids
|
||||
|
||||
media_local_ids =
|
||||
conn
|
||||
|> get("/api/v1/timelines/tag/2hu?only_media=true&local=true")
|
||||
|> json_response_and_validate_schema(:ok)
|
||||
|> Enum.map(& &1["id"])
|
||||
|
||||
refute activity.id in media_local_ids
|
||||
assert with_media.id in media_local_ids
|
||||
refute remote_activity.id in media_local_ids
|
||||
|
||||
ids =
|
||||
conn
|
||||
|> get("/api/v1/timelines/tag/2hu?only_media=true&local=true&remote=true")
|
||||
|> json_response_and_validate_schema(:ok)
|
||||
|> Enum.map(& &1["id"])
|
||||
|
||||
refute activity.id in ids
|
||||
refute with_media.id in ids
|
||||
refute remote_activity.id in ids
|
||||
|
||||
assert conn
|
||||
|> get("/api/v1/timelines/tag/2hu?only_media=true&remote=true")
|
||||
|> json_response_and_validate_schema(:ok) == []
|
||||
end
|
||||
|
||||
test "multi-hashtag timeline", %{conn: conn} do
|
||||
|
|
@ -726,4 +975,37 @@ defmodule Pleroma.Web.MastodonAPI.TimelineControllerTest do
|
|||
ensure_authenticated_access(base_uri)
|
||||
end
|
||||
end
|
||||
|
||||
defp create_remote_activity(user) do
|
||||
obj =
|
||||
insert(:note, %{
|
||||
data: %{
|
||||
"to" => [
|
||||
"https://www.w3.org/ns/activitystreams#Public",
|
||||
User.ap_followers(user)
|
||||
]
|
||||
},
|
||||
user: user
|
||||
})
|
||||
|
||||
insert(:note_activity, %{
|
||||
note: obj,
|
||||
recipients: [
|
||||
"https://www.w3.org/ns/activitystreams#Public",
|
||||
User.ap_followers(user)
|
||||
],
|
||||
user: user,
|
||||
local: false
|
||||
})
|
||||
end
|
||||
|
||||
defp create_with_media_activity(user) do
|
||||
obj = insert(:attachment_note, user: user)
|
||||
|
||||
insert(:note_activity, %{
|
||||
note: obj,
|
||||
recipients: ["https://www.w3.org/ns/activitystreams#Public", User.ap_followers(user)],
|
||||
user: user
|
||||
})
|
||||
end
|
||||
end
|
||||
|
|
|
|||
|
|
@ -73,6 +73,7 @@ defmodule Pleroma.Web.MastodonAPI.AccountViewTest do
|
|||
},
|
||||
fields: []
|
||||
},
|
||||
fqn: "shp@shitposter.club",
|
||||
pleroma: %{
|
||||
ap_id: user.ap_id,
|
||||
also_known_as: ["https://shitposter.zone/users/shp"],
|
||||
|
|
@ -172,6 +173,7 @@ defmodule Pleroma.Web.MastodonAPI.AccountViewTest do
|
|||
},
|
||||
fields: []
|
||||
},
|
||||
fqn: "shp@shitposter.club",
|
||||
pleroma: %{
|
||||
ap_id: user.ap_id,
|
||||
also_known_as: [],
|
||||
|
|
|
|||
|
|
@ -104,7 +104,7 @@ defmodule Pleroma.Web.PleromaAPI.ConversationControllerTest do
|
|||
[participation] = Participation.for_user(user)
|
||||
participation = Repo.preload(participation, :recipients)
|
||||
|
||||
assert user in participation.recipients
|
||||
assert refresh_record(user) in participation.recipients
|
||||
assert other_user in participation.recipients
|
||||
end
|
||||
|
||||
|
|
|
|||
58
test/pleroma/web/plugs/user_tracking_plug_test.exs
Normal file
58
test/pleroma/web/plugs/user_tracking_plug_test.exs
Normal file
|
|
@ -0,0 +1,58 @@
|
|||
# Pleroma: A lightweight social networking server
|
||||
# Copyright © 2017-2021 Pleroma Authors <https://pleroma.social/>
|
||||
# SPDX-License-Identifier: AGPL-3.0-only
|
||||
|
||||
defmodule Pleroma.Web.Plugs.UserTrackingPlugTest do
|
||||
use Pleroma.Web.ConnCase, async: true
|
||||
|
||||
import Pleroma.Factory
|
||||
|
||||
alias Pleroma.Web.Plugs.UserTrackingPlug
|
||||
|
||||
test "updates last_active_at for a new user", %{conn: conn} do
|
||||
user = insert(:user)
|
||||
|
||||
assert is_nil(user.last_active_at)
|
||||
|
||||
test_started_at = NaiveDateTime.utc_now() |> NaiveDateTime.truncate(:second)
|
||||
|
||||
%{assigns: %{user: user}} =
|
||||
conn
|
||||
|> assign(:user, user)
|
||||
|> UserTrackingPlug.call(%{})
|
||||
|
||||
assert user.last_active_at >= test_started_at
|
||||
assert user.last_active_at <= NaiveDateTime.truncate(NaiveDateTime.utc_now(), :second)
|
||||
end
|
||||
|
||||
test "doesn't update last_active_at if it was updated recently", %{conn: conn} do
|
||||
last_active_at =
|
||||
NaiveDateTime.utc_now()
|
||||
|> NaiveDateTime.add(-:timer.hours(1), :millisecond)
|
||||
|> NaiveDateTime.truncate(:second)
|
||||
|
||||
user = insert(:user, %{last_active_at: last_active_at})
|
||||
|
||||
%{assigns: %{user: user}} =
|
||||
conn
|
||||
|> assign(:user, user)
|
||||
|> UserTrackingPlug.call(%{})
|
||||
|
||||
assert user.last_active_at == last_active_at
|
||||
end
|
||||
|
||||
test "skips updating last_active_at if user ID is nil", %{conn: conn} do
|
||||
%{assigns: %{user: user}} =
|
||||
conn
|
||||
|> assign(:user, %Pleroma.User{})
|
||||
|> UserTrackingPlug.call(%{})
|
||||
|
||||
assert is_nil(user.last_active_at)
|
||||
end
|
||||
|
||||
test "does nothing if user is not present", %{conn: conn} do
|
||||
%{assigns: assigns} = UserTrackingPlug.call(conn, %{})
|
||||
|
||||
refute Map.has_key?(assigns, :user)
|
||||
end
|
||||
end
|
||||
|
|
@ -104,6 +104,37 @@ defmodule Pleroma.Factory do
|
|||
}
|
||||
end
|
||||
|
||||
def attachment_note_factory(attrs \\ %{}) do
|
||||
user = attrs[:user] || insert(:user)
|
||||
{length, attrs} = Map.pop(attrs, :length, 1)
|
||||
|
||||
data = %{
|
||||
"attachment" =>
|
||||
Stream.repeatedly(fn -> attachment_data(user.ap_id, attrs[:href]) end)
|
||||
|> Enum.take(length)
|
||||
}
|
||||
|
||||
build(:note, Map.put(attrs, :data, data))
|
||||
end
|
||||
|
||||
defp attachment_data(ap_id, href) do
|
||||
href = href || sequence(:href, &"#{Pleroma.Web.Endpoint.url()}/media/#{&1}.jpg")
|
||||
|
||||
%{
|
||||
"url" => [
|
||||
%{
|
||||
"href" => href,
|
||||
"type" => "Link",
|
||||
"mediaType" => "image/jpeg"
|
||||
}
|
||||
],
|
||||
"name" => "some name",
|
||||
"type" => "Document",
|
||||
"actor" => ap_id,
|
||||
"mediaType" => "image/jpeg"
|
||||
}
|
||||
end
|
||||
|
||||
def audio_factory(attrs \\ %{}) do
|
||||
text = sequence(:text, &"lain radio episode #{&1}")
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue