summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorHaelwenn <contact+git.pleroma.social@hacktivis.me>2020-03-29 19:18:22 +0000
committerHaelwenn <contact+git.pleroma.social@hacktivis.me>2020-03-29 19:18:22 +0000
commite999c67cee65cfe07de6dc76ad18f213c0252bb3 (patch)
tree8c90fce63d4392ad146e83f2300de3d33eeb83a1
parent4e81b4b190161ebb0c496c682fa8e1e0c38a3903 (diff)
parent863ec33ba2a90708d199f18683ffe0c4658c710a (diff)
Merge branch 'feature/funkwhale-audio' into 'develop'
Add support for funkwhale Audio activity Closes #764 and #1624 See merge request pleroma/pleroma!2287
-rw-r--r--lib/pleroma/web/activity_pub/transmogrifier.ex5
-rw-r--r--lib/pleroma/web/mastodon_api/views/status_view.ex2
-rw-r--r--test/fixtures/tesla_mock/funkwhale_audio.json44
-rw-r--r--test/fixtures/tesla_mock/funkwhale_channel.json44
-rw-r--r--test/support/http_request_mock.ex15
-rw-r--r--test/web/mastodon_api/views/status_view_test.exs16
-rw-r--r--test/web/oauth/oauth_controller_test.exs2
7 files changed, 124 insertions, 4 deletions
diff --git a/lib/pleroma/web/activity_pub/transmogrifier.ex b/lib/pleroma/web/activity_pub/transmogrifier.ex
index d6549a932..09bd9a442 100644
--- a/lib/pleroma/web/activity_pub/transmogrifier.ex
+++ b/lib/pleroma/web/activity_pub/transmogrifier.ex
@@ -229,7 +229,8 @@ defmodule Pleroma.Web.ActivityPub.Transmogrifier do
Map.put(object, "url", url["href"])
end
- def fix_url(%{"type" => "Video", "url" => url} = object) when is_list(url) do
+ def fix_url(%{"type" => object_type, "url" => url} = object)
+ when object_type in ["Video", "Audio"] and is_list(url) do
first_element = Enum.at(url, 0)
link_element = Enum.find(url, fn x -> is_map(x) and x["mimeType"] == "text/html" end)
@@ -398,7 +399,7 @@ defmodule Pleroma.Web.ActivityPub.Transmogrifier do
%{"type" => "Create", "object" => %{"type" => objtype} = object} = data,
options
)
- when objtype in ["Article", "Event", "Note", "Video", "Page", "Question", "Answer"] do
+ when objtype in ["Article", "Event", "Note", "Video", "Page", "Question", "Answer", "Audio"] do
actor = Containment.get_actor(data)
data =
diff --git a/lib/pleroma/web/mastodon_api/views/status_view.ex b/lib/pleroma/web/mastodon_api/views/status_view.ex
index 440eef4ba..82326986c 100644
--- a/lib/pleroma/web/mastodon_api/views/status_view.ex
+++ b/lib/pleroma/web/mastodon_api/views/status_view.ex
@@ -482,7 +482,7 @@ defmodule Pleroma.Web.MastodonAPI.StatusView do
end
def render_content(%{data: %{"type" => object_type}} = object)
- when object_type in ["Video", "Event"] do
+ when object_type in ["Video", "Event", "Audio"] do
with name when not is_nil(name) and name != "" <- object.data["name"] do
"<p><a href=\"#{object.data["id"]}\">#{name}</a></p>#{object.data["content"]}"
else
diff --git a/test/fixtures/tesla_mock/funkwhale_audio.json b/test/fixtures/tesla_mock/funkwhale_audio.json
new file mode 100644
index 000000000..15736b1f8
--- /dev/null
+++ b/test/fixtures/tesla_mock/funkwhale_audio.json
@@ -0,0 +1,44 @@
+{
+ "id": "https://channels.tests.funkwhale.audio/federation/music/uploads/42342395-0208-4fee-a38d-259a6dae0871",
+ "type": "Audio",
+ "name": "Compositions - Test Audio for Pleroma",
+ "attributedTo": "https://channels.tests.funkwhale.audio/federation/actors/compositions",
+ "published": "2020-03-11T10:01:52.714918+00:00",
+ "to": "https://www.w3.org/ns/activitystreams#Public",
+ "url": [
+ {
+ "type": "Link",
+ "mimeType": "audio/ogg",
+ "href": "https://channels.tests.funkwhale.audio/api/v1/listen/3901e5d8-0445-49d5-9711-e096cf32e515/?upload=42342395-0208-4fee-a38d-259a6dae0871&download=false"
+ },
+ {
+ "type": "Link",
+ "mimeType": "text/html",
+ "href": "https://channels.tests.funkwhale.audio/library/tracks/74"
+ }
+ ],
+ "content": "<p>This is a test Audio for Pleroma.</p>",
+ "mediaType": "text/html",
+ "tag": [
+ {
+ "type": "Hashtag",
+ "name": "#funkwhale"
+ },
+ {
+ "type": "Hashtag",
+ "name": "#test"
+ },
+ {
+ "type": "Hashtag",
+ "name": "#tests"
+ }
+ ],
+ "summary": "#funkwhale #test #tests",
+ "@context": [
+ "https://www.w3.org/ns/activitystreams",
+ "https://w3id.org/security/v1",
+ {
+ "manuallyApprovesFollowers": "as:manuallyApprovesFollowers"
+ }
+ ]
+}
diff --git a/test/fixtures/tesla_mock/funkwhale_channel.json b/test/fixtures/tesla_mock/funkwhale_channel.json
new file mode 100644
index 000000000..cf9ee8151
--- /dev/null
+++ b/test/fixtures/tesla_mock/funkwhale_channel.json
@@ -0,0 +1,44 @@
+{
+ "id": "https://channels.tests.funkwhale.audio/federation/actors/compositions",
+ "outbox": "https://channels.tests.funkwhale.audio/federation/actors/compositions/outbox",
+ "inbox": "https://channels.tests.funkwhale.audio/federation/actors/compositions/inbox",
+ "preferredUsername": "compositions",
+ "type": "Person",
+ "name": "Compositions",
+ "followers": "https://channels.tests.funkwhale.audio/federation/actors/compositions/followers",
+ "following": "https://channels.tests.funkwhale.audio/federation/actors/compositions/following",
+ "manuallyApprovesFollowers": false,
+ "url": [
+ {
+ "type": "Link",
+ "href": "https://channels.tests.funkwhale.audio/channels/compositions",
+ "mediaType": "text/html"
+ },
+ {
+ "type": "Link",
+ "href": "https://channels.tests.funkwhale.audio/api/v1/channels/compositions/rss",
+ "mediaType": "application/rss+xml"
+ }
+ ],
+ "icon": {
+ "type": "Image",
+ "url": "https://channels.tests.funkwhale.audio/media/attachments/75/b4/f1/nosmile.jpeg",
+ "mediaType": "image/jpeg"
+ },
+ "summary": "<p>I'm testing federation with the fediverse :)</p>",
+ "@context": [
+ "https://www.w3.org/ns/activitystreams",
+ "https://w3id.org/security/v1",
+ {
+ "manuallyApprovesFollowers": "as:manuallyApprovesFollowers"
+ }
+ ],
+ "publicKey": {
+ "owner": "https://channels.tests.funkwhale.audio/federation/actors/compositions",
+ "publicKeyPem": "-----BEGIN RSA PUBLIC KEY-----\nMIIBCgKCAQEAv25u57oZfVLV3KltS+HcsdSx9Op4MmzIes1J8Wu8s0KbdXf2zEwS\nsVqyHgs/XCbnzsR3FqyJTo46D2BVnvZcuU5srNcR2I2HMaqQ0oVdnATE4K6KdcgV\nN+98pMWo56B8LTgE1VpvqbsrXLi9jCTzjrkebVMOP+ZVu+64v1qdgddseblYMnBZ\nct0s7ONbHnqrWlTGf5wES1uIZTVdn5r4MduZG+Uenfi1opBS0lUUxfWdW9r0oF2b\nyneZUyaUCbEroeKbqsweXCWVgnMarUOsgqC42KM4cf95lySSwTSaUtZYIbTw7s9W\n2jveU/rVg8BYZu5JK5obgBoxtlUeUoSswwIDAQAB\n-----END RSA PUBLIC KEY-----\n",
+ "id": "https://channels.tests.funkwhale.audio/federation/actors/compositions#main-key"
+ },
+ "endpoints": {
+ "sharedInbox": "https://channels.tests.funkwhale.audio/federation/shared/inbox"
+ }
+}
diff --git a/test/support/http_request_mock.ex b/test/support/http_request_mock.ex
index e72638814..79ab129fd 100644
--- a/test/support/http_request_mock.ex
+++ b/test/support/http_request_mock.ex
@@ -1273,6 +1273,21 @@ defmodule HttpRequestMock do
{:ok, %Tesla.Env{status: 200, body: File.read!("test/fixtures/tesla_mock/rin.json")}}
end
+ def get(
+ "https://channels.tests.funkwhale.audio/federation/music/uploads/42342395-0208-4fee-a38d-259a6dae0871",
+ _,
+ _,
+ _
+ ) do
+ {:ok,
+ %Tesla.Env{status: 200, body: File.read!("test/fixtures/tesla_mock/funkwhale_audio.json")}}
+ end
+
+ def get("https://channels.tests.funkwhale.audio/federation/actors/compositions", _, _, _) do
+ {:ok,
+ %Tesla.Env{status: 200, body: File.read!("test/fixtures/tesla_mock/funkwhale_channel.json")}}
+ end
+
def get("http://example.com/rel_me/error", _, _, _) do
{:ok, %Tesla.Env{status: 404, body: ""}}
end
diff --git a/test/web/mastodon_api/views/status_view_test.exs b/test/web/mastodon_api/views/status_view_test.exs
index 9191730cd..3b6571706 100644
--- a/test/web/mastodon_api/views/status_view_test.exs
+++ b/test/web/mastodon_api/views/status_view_test.exs
@@ -431,6 +431,22 @@ defmodule Pleroma.Web.MastodonAPI.StatusViewTest do
assert length(represented[:media_attachments]) == 1
end
+ test "funkwhale audio" do
+ user = insert(:user)
+
+ {:ok, object} =
+ Pleroma.Object.Fetcher.fetch_object_from_id(
+ "https://channels.tests.funkwhale.audio/federation/music/uploads/42342395-0208-4fee-a38d-259a6dae0871"
+ )
+
+ %Activity{} = activity = Activity.get_create_by_object_ap_id(object.data["id"])
+
+ represented = StatusView.render("show.json", %{for: user, activity: activity})
+
+ assert represented[:id] == to_string(activity.id)
+ assert length(represented[:media_attachments]) == 1
+ end
+
test "a Mobilizon event" do
user = insert(:user)
diff --git a/test/web/oauth/oauth_controller_test.exs b/test/web/oauth/oauth_controller_test.exs
index 0b0972b17..f2f98d768 100644
--- a/test/web/oauth/oauth_controller_test.exs
+++ b/test/web/oauth/oauth_controller_test.exs
@@ -575,7 +575,7 @@ defmodule Pleroma.Web.OAuth.OAuthControllerTest do
# In case scope param is missing, expecting _all_ app-supported scopes to be granted
for user <- [non_admin, admin],
{requested_scopes, expected_scopes} <-
- %{scopes_subset => scopes_subset, nil => app_scopes} do
+ %{scopes_subset => scopes_subset, nil: app_scopes} do
conn =
post(
build_conn(),