Remove scrobbling support
authorFloatingGhost <hannah@coffee-and-dreams.uk>
Tue, 19 Jul 2022 14:07:45 +0000 (15:07 +0100)
committerFloatingGhost <hannah@coffee-and-dreams.uk>
Tue, 19 Jul 2022 14:07:45 +0000 (15:07 +0100)
17 files changed:
lib/pleroma/web/activity_pub/activity_pub.ex
lib/pleroma/web/activity_pub/transmogrifier.ex
lib/pleroma/web/activity_pub/utils.ex
lib/pleroma/web/activity_pub/views/object_view.ex
lib/pleroma/web/api_spec.ex
lib/pleroma/web/api_spec/operations/pleroma_scrobble_operation.ex [deleted file]
lib/pleroma/web/common_api.ex
lib/pleroma/web/common_api/activity_draft.ex
lib/pleroma/web/pleroma_api/controllers/scrobble_controller.ex [deleted file]
lib/pleroma/web/pleroma_api/views/scrobble_view.ex [deleted file]
lib/pleroma/web/router.ex
test/pleroma/web/activity_pub/activity_pub_test.exs
test/pleroma/web/activity_pub/transmogrifier/audio_handling_test.exs
test/pleroma/web/activity_pub/transmogrifier_test.exs
test/pleroma/web/common_api_test.exs
test/pleroma/web/pleroma_api/controllers/scrobble_controller_test.exs [deleted file]
test/pleroma/web/pleroma_api/views/scrobble_view_test.exs [deleted file]

index 236181b079ea48b87fff174450c49fe271499086..3583f16261554aa0f06ba5ec80d9bbdcf5a2f3b9 100644 (file)
@@ -318,26 +318,6 @@ defmodule Pleroma.Web.ActivityPub.ActivityPub do
     :ok
   end
 
-  @spec listen(map()) :: {:ok, Activity.t()} | {:error, any()}
-  def listen(%{to: to, actor: actor, context: context, object: object} = params) do
-    additional = params[:additional] || %{}
-    # only accept false as false value
-    local = !(params[:local] == false)
-    published = params[:published]
-
-    listen_data =
-      make_listen_data(
-        %{to: to, actor: actor, published: published, context: context, object: object},
-        additional
-      )
-
-    with {:ok, activity} <- insert(listen_data, local),
-         _ <- notify_and_stream(activity),
-         :ok <- maybe_federate(activity) do
-      {:ok, activity}
-    end
-  end
-
   @spec unfollow(User.t(), User.t(), String.t() | nil, boolean()) ::
           {:ok, Activity.t()} | nil | {:error, any()}
   def unfollow(follower, followed, activity_id \\ nil, local \\ true) do
index cf0c9a9e2ffe2e2bc826dc67987f75c968a60a8e..cf072f7ac90102a8e7ba7ef881e6defcbc12b080 100644 (file)
@@ -384,37 +384,6 @@ defmodule Pleroma.Web.ActivityPub.Transmogrifier do
   def handle_incoming(%{"id" => id}, _options) when is_binary(id) and byte_size(id) < 8,
     do: :error
 
-  def handle_incoming(
-        %{"type" => "Listen", "object" => %{"type" => "Audio"} = object} = data,
-        options
-      ) do
-    actor = Containment.get_actor(data)
-
-    data =
-      Map.put(data, "actor", actor)
-      |> fix_addressing
-
-    with {:ok, %User{} = user} <- User.get_or_fetch_by_ap_id(data["actor"]) do
-      reply_depth = (options[:depth] || 0) + 1
-      options = Keyword.put(options, :depth, reply_depth)
-      object = fix_object(object, options)
-
-      params = %{
-        to: data["to"],
-        object: object,
-        actor: user,
-        context: nil,
-        local: false,
-        published: data["published"],
-        additional: Map.take(data, ["cc", "id"])
-      }
-
-      ActivityPub.listen(params)
-    else
-      _e -> :error
-    end
-  end
-
   @doc "Rewrite misskey likes into EmojiReacts"
   def handle_incoming(
         %{
@@ -695,7 +664,7 @@ defmodule Pleroma.Web.ActivityPub.Transmogrifier do
   #  """
 
   def prepare_outgoing(%{"type" => activity_type, "object" => object_id} = data)
-      when activity_type in ["Create", "Listen"] do
+      when activity_type in ["Create"] do
     object =
       object_id
       |> Object.normalize(fetch: false)
index 6a8360def7003269319f2938fb3b2479962458c9..0e92deb31120df665a1367930e6dfd18c48aa64c 100644 (file)
@@ -713,21 +713,6 @@ defmodule Pleroma.Web.ActivityPub.Utils do
     |> Map.merge(additional)
   end
 
-  #### Listen-related helpers
-  def make_listen_data(params, additional) do
-    published = params.published || make_date()
-
-    %{
-      "type" => "Listen",
-      "to" => params.to |> Enum.uniq(),
-      "actor" => params.actor.ap_id,
-      "object" => params.object,
-      "published" => published,
-      "context" => params.context
-    }
-    |> Map.merge(additional)
-  end
-
   #### Flag-related helpers
   @spec make_flag_data(map(), map()) :: map()
   def make_flag_data(%{actor: actor, context: context, content: content} = params, additional) do
index 8a3e4d77b1f37fb7690714da917409a3a5b85f71..d9b59406c232c2341dd95a366ee759491fe63766 100644 (file)
@@ -16,7 +16,7 @@ defmodule Pleroma.Web.ActivityPub.ObjectView do
   end
 
   def render("object.json", %{object: %Activity{data: %{"type" => activity_type}} = activity})
-      when activity_type in ["Create", "Listen"] do
+      when activity_type in ["Create"] do
     base = Pleroma.Web.ActivityPub.Utils.make_json_ld_header()
     object = Object.normalize(activity, fetch: false)
 
index 528cd9cf4fc43eeddbc760874322c2c4a4dd86b8..66ae7dcf836b13b02f01b2198cbaa110f85dc42f 100644 (file)
@@ -79,7 +79,7 @@ defmodule Pleroma.Web.ApiSpec do
         "x-tagGroups": [
           %{
             "name" => "Accounts",
-            "tags" => ["Account actions", "Retrieve account information", "Scrobbles"]
+            "tags" => ["Account actions", "Retrieve account information"]
           },
           %{
             "name" => "Administration",
diff --git a/lib/pleroma/web/api_spec/operations/pleroma_scrobble_operation.ex b/lib/pleroma/web/api_spec/operations/pleroma_scrobble_operation.ex
deleted file mode 100644 (file)
index 6a909fc..0000000
+++ /dev/null
@@ -1,102 +0,0 @@
-# Pleroma: A lightweight social networking server
-# Copyright © 2017-2021 Pleroma Authors <https://pleroma.social/>
-# SPDX-License-Identifier: AGPL-3.0-only
-
-defmodule Pleroma.Web.ApiSpec.PleromaScrobbleOperation do
-  alias OpenApiSpex.Operation
-  alias OpenApiSpex.Reference
-  alias OpenApiSpex.Schema
-  alias Pleroma.Web.ApiSpec.Schemas.Account
-  alias Pleroma.Web.ApiSpec.Schemas.VisibilityScope
-
-  import Pleroma.Web.ApiSpec.Helpers
-
-  def open_api_operation(action) do
-    operation = String.to_existing_atom("#{action}_operation")
-    apply(__MODULE__, operation, [])
-  end
-
-  def create_operation do
-    %Operation{
-      tags: ["Scrobbles"],
-      summary: "Creates a new Listen activity for an account",
-      security: [%{"oAuth" => ["write"]}],
-      operationId: "PleromaAPI.ScrobbleController.create",
-      requestBody: request_body("Parameters", create_request(), requried: true),
-      responses: %{
-        200 => Operation.response("Scrobble", "application/json", scrobble())
-      }
-    }
-  end
-
-  def index_operation do
-    %Operation{
-      tags: ["Scrobbles"],
-      summary: "Requests a list of current and recent Listen activities for an account",
-      operationId: "PleromaAPI.ScrobbleController.index",
-      parameters: [
-        %Reference{"$ref": "#/components/parameters/accountIdOrNickname"} | pagination_params()
-      ],
-      security: [%{"oAuth" => ["read"]}],
-      responses: %{
-        200 =>
-          Operation.response("Array of Scrobble", "application/json", %Schema{
-            type: :array,
-            items: scrobble()
-          })
-      }
-    }
-  end
-
-  defp create_request do
-    %Schema{
-      type: :object,
-      required: [:title],
-      properties: %{
-        title: %Schema{type: :string, description: "The title of the media playing"},
-        album: %Schema{type: :string, description: "The album of the media playing"},
-        artist: %Schema{type: :string, description: "The artist of the media playing"},
-        length: %Schema{type: :integer, description: "The length of the media playing"},
-        visibility: %Schema{
-          allOf: [VisibilityScope],
-          default: "public",
-          description: "Scrobble visibility"
-        }
-      },
-      example: %{
-        "title" => "Some Title",
-        "artist" => "Some Artist",
-        "album" => "Some Album",
-        "length" => 180_000
-      }
-    }
-  end
-
-  defp scrobble do
-    %Schema{
-      type: :object,
-      properties: %{
-        id: %Schema{type: :string},
-        account: Account,
-        title: %Schema{type: :string, description: "The title of the media playing"},
-        album: %Schema{type: :string, description: "The album of the media playing"},
-        artist: %Schema{type: :string, description: "The artist of the media playing"},
-        length: %Schema{
-          type: :integer,
-          description: "The length of the media playing",
-          nullable: true
-        },
-        created_at: %Schema{type: :string, format: :"date-time"}
-      },
-      example: %{
-        "id" => "1234",
-        "account" => Account.schema().example,
-        "title" => "Some Title",
-        "artist" => "Some Artist",
-        "album" => "Some Album",
-        "length" => 180_000,
-        "created_at" => "2019-09-28T12:40:45.000Z"
-      }
-    }
-  end
-end
index 856fa95b9c6dd23369b2554b2ad4736cd4124a3d..3c2e7ae86bed2348eaf24a013ee5563b9d0401c9 100644 (file)
@@ -388,12 +388,6 @@ defmodule Pleroma.Web.CommonAPI do
     |> check_expiry_date()
   end
 
-  def listen(user, data) do
-    with {:ok, draft} <- ActivityDraft.listen(user, data) do
-      ActivityPub.listen(draft.changes)
-    end
-  end
-
   def post(user, %{status: _} = data) do
     with {:ok, draft} <- ActivityDraft.create(user, data) do
       ActivityPub.create(draft.changes, draft.preview?)
index bd56b6e20bc86a7661d59c2bf6e7d22f51e9f29c..ea88213fbdae41c28149857b92c2846bb4d088ef 100644 (file)
@@ -64,30 +64,6 @@ defmodule Pleroma.Web.CommonAPI.ActivityDraft do
     |> validate()
   end
 
-  def listen(user, params) do
-    user
-    |> new(params)
-    |> visibility()
-    |> to_and_cc()
-    |> context()
-    |> listen_object()
-    |> with_valid(&changes/1)
-    |> validate()
-  end
-
-  defp listen_object(draft) do
-    object =
-      draft.params
-      |> Map.take([:album, :artist, :title, :length])
-      |> Map.new(fn {key, value} -> {to_string(key), value} end)
-      |> Map.put("type", "Audio")
-      |> Map.put("to", draft.to)
-      |> Map.put("cc", draft.cc)
-      |> Map.put("actor", draft.user.ap_id)
-
-    %__MODULE__{draft | object: object}
-  end
-
   defp put_params(draft, params) do
     params = Map.put_new(params, :in_reply_to_status_id, params[:in_reply_to_id])
     %__MODULE__{draft | params: params}
diff --git a/lib/pleroma/web/pleroma_api/controllers/scrobble_controller.ex b/lib/pleroma/web/pleroma_api/controllers/scrobble_controller.ex
deleted file mode 100644 (file)
index ca26d80..0000000
+++ /dev/null
@@ -1,52 +0,0 @@
-# Pleroma: A lightweight social networking server
-# Copyright © 2017-2021 Pleroma Authors <https://pleroma.social/>
-# SPDX-License-Identifier: AGPL-3.0-only
-
-defmodule Pleroma.Web.PleromaAPI.ScrobbleController do
-  use Pleroma.Web, :controller
-
-  import Pleroma.Web.ControllerHelper, only: [add_link_headers: 2]
-
-  alias Pleroma.User
-  alias Pleroma.Web.ActivityPub.ActivityPub
-  alias Pleroma.Web.CommonAPI
-  alias Pleroma.Web.Plugs.OAuthScopesPlug
-
-  plug(Pleroma.Web.ApiSpec.CastAndValidate)
-
-  plug(
-    OAuthScopesPlug,
-    %{scopes: ["read"], fallback: :proceed_unauthenticated} when action == :index
-  )
-
-  plug(OAuthScopesPlug, %{scopes: ["write"]} when action == :create)
-
-  defdelegate open_api_operation(action), to: Pleroma.Web.ApiSpec.PleromaScrobbleOperation
-
-  def create(%{assigns: %{user: user}, body_params: params} = conn, _) do
-    with {:ok, activity} <- CommonAPI.listen(user, params) do
-      render(conn, "show.json", activity: activity, for: user)
-    else
-      {:error, message} ->
-        conn
-        |> put_status(:bad_request)
-        |> json(%{"error" => message})
-    end
-  end
-
-  def index(%{assigns: %{user: reading_user}} = conn, %{id: id} = params) do
-    with %User{} = user <- User.get_cached_by_nickname_or_id(id, for: reading_user) do
-      params = Map.put(params, :type, ["Listen"])
-
-      activities = ActivityPub.fetch_user_abstract_activities(user, reading_user, params)
-
-      conn
-      |> add_link_headers(activities)
-      |> render("index.json", %{
-        activities: activities,
-        for: reading_user,
-        as: :activity
-      })
-    end
-  end
-end
diff --git a/lib/pleroma/web/pleroma_api/views/scrobble_view.ex b/lib/pleroma/web/pleroma_api/views/scrobble_view.ex
deleted file mode 100644 (file)
index 2bc0695..0000000
+++ /dev/null
@@ -1,37 +0,0 @@
-# Pleroma: A lightweight social networking server
-# Copyright © 2017-2021 Pleroma Authors <https://pleroma.social/>
-# SPDX-License-Identifier: AGPL-3.0-only
-
-defmodule Pleroma.Web.PleromaAPI.ScrobbleView do
-  use Pleroma.Web, :view
-
-  require Pleroma.Constants
-
-  alias Pleroma.Activity
-  alias Pleroma.HTML
-  alias Pleroma.Object
-  alias Pleroma.Web.CommonAPI
-  alias Pleroma.Web.CommonAPI.Utils
-  alias Pleroma.Web.MastodonAPI.AccountView
-
-  def render("show.json", %{activity: %Activity{data: %{"type" => "Listen"}} = activity} = opts) do
-    object = Object.normalize(activity, fetch: false)
-
-    user = CommonAPI.get_user(activity.data["actor"])
-    created_at = Utils.to_masto_date(activity.data["published"])
-
-    %{
-      id: activity.id,
-      account: AccountView.render("show.json", %{user: user, for: opts[:for]}),
-      created_at: created_at,
-      title: object.data["title"] |> HTML.strip_tags(),
-      artist: object.data["artist"] |> HTML.strip_tags(),
-      album: object.data["album"] |> HTML.strip_tags(),
-      length: object.data["length"]
-    }
-  end
-
-  def render("index.json", opts) do
-    safe_render_many(opts.activities, __MODULE__, "show.json", opts)
-  end
-end
index f53a7389555a505962eb05ed150ea4a3b33e4671..9974e3dee6057588681b70e76ce411d2162409f6 100644 (file)
@@ -448,8 +448,6 @@ defmodule Pleroma.Web.Router do
       get("/mascot", MascotController, :show)
       put("/mascot", MascotController, :update)
 
-      post("/scrobble", ScrobbleController, :create)
-
       get("/backups", BackupController, :index)
       post("/backups", BackupController, :create)
     end
@@ -471,7 +469,6 @@ defmodule Pleroma.Web.Router do
 
   scope "/api/v1/pleroma", Pleroma.Web.PleromaAPI do
     pipe_through(:api)
-    get("/accounts/:id/scrobbles", ScrobbleController, :index)
     get("/federation_status", InstancesController, :show)
   end
 
index f85c4bbb85b8a8033c2829ffeceda7918ffd63f9..9644379065d2af437e1ff30113cbe86da50ae5ce 100644 (file)
@@ -543,42 +543,6 @@ defmodule Pleroma.Web.ActivityPub.ActivityPubTest do
     end
   end
 
-  describe "listen activities" do
-    test "does not increase user note count" do
-      user = insert(:user)
-
-      {:ok, activity} =
-        ActivityPub.listen(%{
-          to: ["https://www.w3.org/ns/activitystreams#Public"],
-          actor: user,
-          context: "",
-          object: %{
-            "actor" => user.ap_id,
-            "to" => ["https://www.w3.org/ns/activitystreams#Public"],
-            "artist" => "lain",
-            "title" => "lain radio episode 1",
-            "length" => 180_000,
-            "type" => "Audio"
-          }
-        })
-
-      assert activity.actor == user.ap_id
-
-      user = User.get_cached_by_id(user.id)
-      assert user.note_count == 0
-    end
-
-    test "can be fetched into a timeline" do
-      _listen_activity_1 = insert(:listen)
-      _listen_activity_2 = insert(:listen)
-      _listen_activity_3 = insert(:listen)
-
-      timeline = ActivityPub.fetch_activities([], %{type: ["Listen"]})
-
-      assert length(timeline) == 3
-    end
-  end
-
   describe "create activities" do
     setup do
       [user: insert(:user)]
index a0942ce8b8c6a7f49fd1385cd80448ebe803a122..0a1a965cac47523b51d5c24c69c903134a526808 100644 (file)
@@ -12,39 +12,6 @@ defmodule Pleroma.Web.ActivityPub.Transmogrifier.AudioHandlingTest do
 
   import Pleroma.Factory
 
-  test "it works for incoming listens" do
-    _user = insert(:user, ap_id: "http://mastodon.example.org/users/admin")
-
-    data = %{
-      "@context" => "https://www.w3.org/ns/activitystreams",
-      "to" => ["https://www.w3.org/ns/activitystreams#Public"],
-      "cc" => [],
-      "type" => "Listen",
-      "id" => "http://mastodon.example.org/users/admin/listens/1234/activity",
-      "actor" => "http://mastodon.example.org/users/admin",
-      "object" => %{
-        "type" => "Audio",
-        "to" => ["https://www.w3.org/ns/activitystreams#Public"],
-        "cc" => [],
-        "id" => "http://mastodon.example.org/users/admin/listens/1234",
-        "attributedTo" => "http://mastodon.example.org/users/admin",
-        "title" => "lain radio episode 1",
-        "artist" => "lain",
-        "album" => "lain radio",
-        "length" => 180_000
-      }
-    }
-
-    {:ok, %Activity{local: false} = activity} = Transmogrifier.handle_incoming(data)
-
-    object = Object.normalize(activity, fetch: false)
-
-    assert object.data["title"] == "lain radio episode 1"
-    assert object.data["artist"] == "lain"
-    assert object.data["album"] == "lain radio"
-    assert object.data["length"] == 180_000
-  end
-
   test "Funkwhale Audio object" do
     Tesla.Mock.mock(fn
       %{url: "https://channels.tests.funkwhale.audio/federation/actors/compositions"} ->
index 06daf6a9fc7b6af5173116ad21ee433bc08fbf22..3756fdee0123d7b5c3f953defab97eac9b717810 100644 (file)
@@ -273,20 +273,6 @@ defmodule Pleroma.Web.ActivityPub.TransmogrifierTest do
       assert is_nil(modified["bcc"])
     end
 
-    test "it can handle Listen activities" do
-      listen_activity = insert(:listen)
-
-      {:ok, modified} = Transmogrifier.prepare_outgoing(listen_activity.data)
-
-      assert modified["type"] == "Listen"
-
-      user = insert(:user)
-
-      {:ok, activity} = CommonAPI.listen(user, %{"title" => "lain radio episode 1"})
-
-      {:ok, _modified} = Transmogrifier.prepare_outgoing(activity.data)
-    end
-
     test "custom emoji urls are URI encoded" do
       # :dinosaur: filename has a space -> dino walking.gif
       user = insert(:user)
index 85a4a3a1139afdcd9bcc64420611d8e1b6dcad6c..167909cfbb9f078efe5ed8792699e594117c981b 100644 (file)
@@ -1331,45 +1331,6 @@ defmodule Pleroma.Web.CommonAPITest do
     end
   end
 
-  describe "listen/2" do
-    test "returns a valid activity" do
-      user = insert(:user)
-
-      {:ok, activity} =
-        CommonAPI.listen(user, %{
-          title: "lain radio episode 1",
-          album: "lain radio",
-          artist: "lain",
-          length: 180_000
-        })
-
-      object = Object.normalize(activity, fetch: false)
-
-      assert object.data["title"] == "lain radio episode 1"
-
-      assert Visibility.get_visibility(activity) == "public"
-    end
-
-    test "respects visibility=private" do
-      user = insert(:user)
-
-      {:ok, activity} =
-        CommonAPI.listen(user, %{
-          title: "lain radio episode 1",
-          album: "lain radio",
-          artist: "lain",
-          length: 180_000,
-          visibility: "private"
-        })
-
-      object = Object.normalize(activity, fetch: false)
-
-      assert object.data["title"] == "lain radio episode 1"
-
-      assert Visibility.get_visibility(activity) == "private"
-    end
-  end
-
   describe "get_user/1" do
     test "gets user by ap_id" do
       user = insert(:user)
diff --git a/test/pleroma/web/pleroma_api/controllers/scrobble_controller_test.exs b/test/pleroma/web/pleroma_api/controllers/scrobble_controller_test.exs
deleted file mode 100644 (file)
index d4546f4..0000000
+++ /dev/null
@@ -1,60 +0,0 @@
-# Pleroma: A lightweight social networking server
-# Copyright © 2017-2021 Pleroma Authors <https://pleroma.social/>
-# SPDX-License-Identifier: AGPL-3.0-only
-
-defmodule Pleroma.Web.PleromaAPI.ScrobbleControllerTest do
-  use Pleroma.Web.ConnCase, async: true
-
-  alias Pleroma.Web.CommonAPI
-
-  describe "POST /api/v1/pleroma/scrobble" do
-    test "works correctly" do
-      %{conn: conn} = oauth_access(["write"])
-
-      conn =
-        conn
-        |> put_req_header("content-type", "application/json")
-        |> post("/api/v1/pleroma/scrobble", %{
-          "title" => "lain radio episode 1",
-          "artist" => "lain",
-          "album" => "lain radio",
-          "length" => "180000"
-        })
-
-      assert %{"title" => "lain radio episode 1"} = json_response_and_validate_schema(conn, 200)
-    end
-  end
-
-  describe "GET /api/v1/pleroma/accounts/:id/scrobbles" do
-    test "works correctly" do
-      %{user: user, conn: conn} = oauth_access(["read"])
-
-      {:ok, _activity} =
-        CommonAPI.listen(user, %{
-          title: "lain radio episode 1",
-          artist: "lain",
-          album: "lain radio"
-        })
-
-      {:ok, _activity} =
-        CommonAPI.listen(user, %{
-          title: "lain radio episode 2",
-          artist: "lain",
-          album: "lain radio"
-        })
-
-      {:ok, _activity} =
-        CommonAPI.listen(user, %{
-          title: "lain radio episode 3",
-          artist: "lain",
-          album: "lain radio"
-        })
-
-      conn = get(conn, "/api/v1/pleroma/accounts/#{user.id}/scrobbles")
-
-      result = json_response_and_validate_schema(conn, 200)
-
-      assert length(result) == 3
-    end
-  end
-end
diff --git a/test/pleroma/web/pleroma_api/views/scrobble_view_test.exs b/test/pleroma/web/pleroma_api/views/scrobble_view_test.exs
deleted file mode 100644 (file)
index 382051f..0000000
+++ /dev/null
@@ -1,20 +0,0 @@
-# Pleroma: A lightweight social networking server
-# Copyright © 2017-2021 Pleroma Authors <https://pleroma.social/>
-# SPDX-License-Identifier: AGPL-3.0-only
-
-defmodule Pleroma.Web.PleromaAPI.ScrobbleViewTest do
-  use Pleroma.DataCase, async: true
-
-  alias Pleroma.Web.PleromaAPI.ScrobbleView
-
-  import Pleroma.Factory
-
-  test "successfully renders a Listen activity (pleroma extension)" do
-    listen_activity = insert(:listen)
-
-    status = ScrobbleView.render("show.json", activity: listen_activity)
-
-    assert status.length == listen_activity.data["object"]["length"]
-    assert status.title == listen_activity.data["object"]["title"]
-  end
-end