Add hashtag filter to user statuses (GET /api/v1/accounts/:id/statuses)
authorEugenij <eugenijm@protonmail.com>
Sun, 30 Jun 2019 09:08:46 +0000 (09:08 +0000)
committerrinpatch <rinpatch@sdf.org>
Sun, 30 Jun 2019 09:08:46 +0000 (09:08 +0000)
CHANGELOG.md
lib/pleroma/web/mastodon_api/mastodon_api_controller.ex
test/web/mastodon_api/mastodon_api_controller_test.exs

index 96473b1b8d527fabe3546ff6e943351268d49b20..663d99ffd32848b9bc091d3a0d48c5d10d389855 100644 (file)
@@ -6,6 +6,8 @@ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/).
 ## [Unreleased]
 ### Added
 - MRF: Support for priming the mediaproxy cache (`Pleroma.Web.ActivityPub.MRF.MediaProxyWarmingPolicy`)
+- Mastodon API: Support for the [`tagged` filter](https://github.com/tootsuite/mastodon/pull/9755) in [`GET /api/v1/accounts/:id/statuses`](https://docs.joinmastodon.org/api/rest/accounts/#get-api-v1-accounts-id-statuses)
+
 ### Fixed
 - Not being able to pin unlisted posts
 
index 7cdba4cc03c2ed6a7c054568729e588074e25e44..ceb88511b0e5e0d03d8dfc922f4ce9651c3f5607 100644 (file)
@@ -356,6 +356,10 @@ defmodule Pleroma.Web.MastodonAPI.MastodonAPIController do
 
   def user_statuses(%{assigns: %{user: reading_user}} = conn, params) do
     with %User{} = user <- User.get_cached_by_id(params["id"]) do
+      params =
+        params
+        |> Map.put("tag", params["tagged"])
+
       activities = ActivityPub.fetch_user_activities(user, reading_user, params)
 
       conn
index 03f57dbfaa8004de9394e79be2cae7ce583c9486..b7487c68cc2052a65740c0890d9bd50373b5b65f 100644 (file)
@@ -1408,6 +1408,19 @@ defmodule Pleroma.Web.MastodonAPI.MastodonAPIControllerTest do
       assert [%{"id" => id}] = json_response(conn, 200)
       assert id == to_string(post.id)
     end
+
+    test "filters user's statuses by a hashtag", %{conn: conn} do
+      user = insert(:user)
+      {:ok, post} = CommonAPI.post(user, %{"status" => "#hashtag"})
+      {:ok, _post} = CommonAPI.post(user, %{"status" => "hashtag"})
+
+      conn =
+        conn
+        |> get("/api/v1/accounts/#{user.id}/statuses", %{"tagged" => "hashtag"})
+
+      assert [%{"id" => id}] = json_response(conn, 200)
+      assert id == to_string(post.id)
+    end
   end
 
   describe "user relationships" do