Merge branch 'mastoapi-media-timeline' into 'develop'
MastoAPI: Add media timelines. Closes #63 See merge request pleroma/pleroma!16
This commit is contained in:
commit
dd76036cbb
|
@ -159,6 +159,12 @@ defp restrict_favorited_by(query, %{"favorited_by" => ap_id}) do
|
||||||
end
|
end
|
||||||
defp restrict_favorited_by(query, _), do: query
|
defp restrict_favorited_by(query, _), do: query
|
||||||
|
|
||||||
|
defp restrict_media(query, %{"only_media" => val}) when val == "true" or val == "1" do
|
||||||
|
from activity in query,
|
||||||
|
where: fragment("not (? #> '{\"object\",\"attachment\"}' = ?)", activity.data, ^[])
|
||||||
|
end
|
||||||
|
defp restrict_media(query, _), do: query
|
||||||
|
|
||||||
# Only search through last 100_000 activities by default
|
# Only search through last 100_000 activities by default
|
||||||
defp restrict_recent(query, %{"whole_db" => true}), do: query
|
defp restrict_recent(query, %{"whole_db" => true}), do: query
|
||||||
defp restrict_recent(query, _) do
|
defp restrict_recent(query, _) do
|
||||||
|
@ -191,6 +197,7 @@ def fetch_activities(recipients, opts \\ %{}) do
|
||||||
|> restrict_favorited_by(opts)
|
|> restrict_favorited_by(opts)
|
||||||
|> restrict_recent(opts)
|
|> restrict_recent(opts)
|
||||||
|> restrict_blocked(opts)
|
|> restrict_blocked(opts)
|
||||||
|
|> restrict_media(opts)
|
||||||
|> Repo.all
|
|> Repo.all
|
||||||
|> Enum.reverse
|
|> Enum.reverse
|
||||||
end
|
end
|
||||||
|
|
|
@ -249,6 +249,29 @@ test "gets a users statuses", %{conn: conn} do
|
||||||
|
|
||||||
assert id == to_string(note_two.id)
|
assert id == to_string(note_two.id)
|
||||||
end
|
end
|
||||||
|
|
||||||
|
test "gets an users media", %{conn: conn} do
|
||||||
|
note = insert(:note_activity)
|
||||||
|
user = User.get_by_ap_id(note.data["actor"])
|
||||||
|
|
||||||
|
file = %Plug.Upload{content_type: "image/jpg", path: Path.absname("test/fixtures/image.jpg"), filename: "an_image.jpg"}
|
||||||
|
media = TwitterAPI.upload(file, "json")
|
||||||
|
|> Poison.decode!
|
||||||
|
|
||||||
|
{:ok, image_post} = TwitterAPI.create_status(user, %{"status" => "cofe", "media_ids" => [media["media_id"]]})
|
||||||
|
|
||||||
|
conn = conn
|
||||||
|
|> get("/api/v1/accounts/#{user.id}/statuses", %{"only_media" => "true"})
|
||||||
|
|
||||||
|
assert [%{"id" => id}] = json_response(conn, 200)
|
||||||
|
assert id == to_string(image_post.id)
|
||||||
|
|
||||||
|
conn = build_conn()
|
||||||
|
|> get("/api/v1/accounts/#{user.id}/statuses", %{"only_media" => "1"})
|
||||||
|
|
||||||
|
assert [%{"id" => id}] = json_response(conn, 200)
|
||||||
|
assert id == to_string(image_post.id)
|
||||||
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
describe "user relationships" do
|
describe "user relationships" do
|
||||||
|
|
Loading…
Reference in New Issue