init tag feed
authorMaksim Pechnikov <parallel588@gmail.com>
Fri, 6 Dec 2019 06:32:29 +0000 (09:32 +0300)
committerMaksim Pechnikov <parallel588@gmail.com>
Fri, 6 Dec 2019 06:33:40 +0000 (09:33 +0300)
lib/pleroma/emails/admin_email.ex
lib/pleroma/web/feed/tag_controller.ex [new file with mode: 0644]
lib/pleroma/web/feed/user_controller.ex [moved from lib/pleroma/web/feed/feed_controller.ex with 89% similarity]
lib/pleroma/web/metadata/feed.ex
lib/pleroma/web/router.ex
lib/pleroma/web/templates/feed/feed/tag.xml.eex [new file with mode: 0644]
lib/pleroma/web/templates/feed/feed/user.xml.eex [moved from lib/pleroma/web/templates/feed/feed/feed.xml.eex with 67% similarity]
test/emails/admin_email_test.exs
test/user_test.exs
test/web/feed/tag_controller_test.exs [new file with mode: 0644]
test/web/feed/user_controller_test.exs [moved from test/web/feed/feed_controller_test.exs with 99% similarity]

index b15e4041bd4295d17d3a6a5124748ff87c60778a..d7dd4b2e064908ccd91cd937f4a784a2afb33600 100644 (file)
@@ -17,7 +17,7 @@ defmodule Pleroma.Emails.AdminEmail do
   end
 
   defp user_url(user) do
-    Helpers.feed_url(Pleroma.Web.Endpoint, :feed_redirect, user.id)
+    Helpers.user_feed_url(Pleroma.Web.Endpoint, :feed_redirect, user.id)
   end
 
   def report(to, reporter, account, statuses, comment) do
diff --git a/lib/pleroma/web/feed/tag_controller.ex b/lib/pleroma/web/feed/tag_controller.ex
new file mode 100644 (file)
index 0000000..66abc18
--- /dev/null
@@ -0,0 +1,36 @@
+# Pleroma: A lightweight social networking server
+# Copyright © 2017-2019 Pleroma Authors <https://pleroma.social/>
+# SPDX-License-Identifier: AGPL-3.0-only
+
+defmodule Pleroma.Web.Feed.TagController do
+  use Pleroma.Web, :controller
+
+  alias Pleroma.Config
+  alias Pleroma.Web.ActivityPub.ActivityPub
+  alias Pleroma.Web.Feed.FeedView
+
+  def feed(conn, %{"tag" => tag} = params) do
+    activities =
+      %{
+        "type" => ["Create"],
+        "whole_db" => true,
+        "tag" => parse_tag(tag)
+      }
+      |> Map.merge(Map.take(params, ["max_id"]))
+      |> ActivityPub.fetch_public_activities()
+
+    conn
+    |> put_resp_content_type("application/atom+xml")
+    |> put_view(FeedView)
+    |> render("tag.xml", activities: activities, feed_config: Config.get([:feed]))
+  end
+
+  defp parse_tag(raw_tag) when is_binary(raw_tag) do
+    case Enum.reverse(String.split(raw_tag, ".")) do
+      [format | tag] when format in ["atom", "rss"] -> Enum.join(tag, ".")
+      _ -> raw_tag
+    end
+  end
+
+  defp parse_tag(raw_tag), do: raw_tag
+end
similarity index 89%
rename from lib/pleroma/web/feed/feed_controller.ex
rename to lib/pleroma/web/feed/user_controller.ex
index d0e23007df7610544587136b0a86a69aa130f6f3..e5d8427ce41abdd11b7a0a43ddd9473e9132bfbd 100644 (file)
@@ -2,13 +2,14 @@
 # Copyright © 2017-2019 Pleroma Authors <https://pleroma.social/>
 # SPDX-License-Identifier: AGPL-3.0-only
 
-defmodule Pleroma.Web.Feed.FeedController do
+defmodule Pleroma.Web.Feed.UserController do
   use Pleroma.Web, :controller
 
   alias Fallback.RedirectController
   alias Pleroma.User
   alias Pleroma.Web.ActivityPub.ActivityPub
   alias Pleroma.Web.ActivityPub.ActivityPubController
+  alias Pleroma.Web.Feed.FeedView
 
   plug(Pleroma.Plugs.SetFormatPlug when action in [:feed_redirect])
 
@@ -27,7 +28,7 @@ defmodule Pleroma.Web.Feed.FeedController do
 
   def feed_redirect(conn, %{"nickname" => nickname}) do
     with {_, %User{} = user} <- {:fetch_user, User.get_cached_by_nickname(nickname)} do
-      redirect(conn, external: "#{feed_url(conn, :feed, user.nickname)}.atom")
+      redirect(conn, external: "#{user_feed_url(conn, :feed, user.nickname)}.atom")
     end
   end
 
@@ -44,7 +45,8 @@ defmodule Pleroma.Web.Feed.FeedController do
 
       conn
       |> put_resp_content_type("application/atom+xml")
-      |> render("feed.xml",
+      |> put_view(FeedView)
+      |> render("user.xml",
         user: user,
         activities: activities,
         feed_config: Pleroma.Config.get([:feed])
index 8043e6c547f52a63c33193ea24b30582395ea149..ee48913a70bfb65c1a1cfa2803a5b9dca1fc52bd 100644 (file)
@@ -16,7 +16,7 @@ defmodule Pleroma.Web.Metadata.Providers.Feed do
        [
          rel: "alternate",
          type: "application/atom+xml",
-         href: Helpers.feed_path(Endpoint, :feed, user.nickname) <> ".atom"
+         href: Helpers.user_feed_path(Endpoint, :feed, user.nickname) <> ".atom"
        ], []}
     ]
   end
index e6c4f6f1495d1c14c6c1eac0218a325e02ab89d5..871f3bf85668ade5d52711e1be3c2c5685e3295f 100644 (file)
@@ -526,8 +526,10 @@ defmodule Pleroma.Web.Router do
     get("/notice/:id", OStatus.OStatusController, :notice)
     get("/notice/:id/embed_player", OStatus.OStatusController, :notice_player)
 
-    get("/users/:nickname/feed", Feed.FeedController, :feed)
-    get("/users/:nickname", Feed.FeedController, :feed_redirect)
+    get("/users/:nickname/feed", Feed.UserController, :feed, as: :user_feed)
+    get("/users/:nickname", Feed.UserController, :feed_redirect, as: :user_feed)
+
+    get("/tags/:tag", Feed.TagController, :feed, as: :tag_feed)
 
     get("/mailer/unsubscribe/:token", Mailer.SubscriptionController, :unsubscribe)
   end
diff --git a/lib/pleroma/web/templates/feed/feed/tag.xml.eex b/lib/pleroma/web/templates/feed/feed/tag.xml.eex
new file mode 100644 (file)
index 0000000..52b1d7b
--- /dev/null
@@ -0,0 +1,10 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<feed
+  xmlns="http://www.w3.org/2005/Atom"
+  xmlns:thr="http://purl.org/syndication/thread/1.0"
+  xmlns:activity="http://activitystrea.ms/spec/1.0/"
+  xmlns:poco="http://portablecontacts.net/spec/1.0"
+  xmlns:ostatus="http://ostatus.org/schema/1.0">
+
+  <title>TAGS</title>
+</feed>
similarity index 67%
rename from lib/pleroma/web/templates/feed/feed/feed.xml.eex
rename to lib/pleroma/web/templates/feed/feed/user.xml.eex
index 5ae36d345d79bc88e663eeeab60d3dc634fc9082..d274c08ae06d1b5082e2ff3bb3ad6215b3400ac4 100644 (file)
@@ -6,16 +6,16 @@
   xmlns:poco="http://portablecontacts.net/spec/1.0"
   xmlns:ostatus="http://ostatus.org/schema/1.0">
 
-  <id><%= feed_url(@conn, :feed, @user.nickname) <> ".atom" %></id>
+  <id><%= user_feed_url(@conn, :feed, @user.nickname) <> ".atom" %></id>
   <title><%= @user.nickname <> "'s timeline" %></title>
   <updated><%= most_recent_update(@activities, @user) %></updated>
   <logo><%= logo(@user) %></logo>
-  <link rel="self" href="<%= '#{feed_url(@conn, :feed, @user.nickname)}.atom' %>" type="application/atom+xml"/>
+  <link rel="self" href="<%= '#{user_feed_url(@conn, :feed, @user.nickname)}.atom' %>" type="application/atom+xml"/>
 
   <%= render @view_module, "_author.xml", assigns %>
 
   <%= if last_activity(@activities) do %>
-    <link rel="next" href="<%= '#{feed_url(@conn, :feed, @user.nickname)}.atom?max_id=#{last_activity(@activities).id}' %>" type="application/atom+xml"/>
+    <link rel="next" href="<%= '#{user_feed_url(@conn, :feed, @user.nickname)}.atom?max_id=#{last_activity(@activities).id}' %>" type="application/atom+xml"/>
   <% end %>
 
   <%= for activity <- @activities do %>
index ad89f9213b10d54ecb70920eed7a4a7fcf9dfa75..383cc3459285670a7108edfa3e0074e94a4004a6 100644 (file)
@@ -19,8 +19,8 @@ defmodule Pleroma.Emails.AdminEmailTest do
       AdminEmail.report(to_user, reporter, account, [%{name: "Test", id: "12"}], "Test comment")
 
     status_url = Helpers.o_status_url(Pleroma.Web.Endpoint, :notice, "12")
-    reporter_url = Helpers.feed_url(Pleroma.Web.Endpoint, :feed_redirect, reporter.id)
-    account_url = Helpers.feed_url(Pleroma.Web.Endpoint, :feed_redirect, account.id)
+    reporter_url = Helpers.user_feed_url(Pleroma.Web.Endpoint, :feed_redirect, reporter.id)
+    account_url = Helpers.user_feed_url(Pleroma.Web.Endpoint, :feed_redirect, account.id)
 
     assert res.to == [{to_user.name, to_user.email}]
     assert res.from == {config[:name], config[:notify_email]}
index bfa8faafa3e292d67639d37ee8b3976bcbbccdfb..7b0842e247dfc34142fc2d83bad3b32495c235cf 100644 (file)
@@ -548,7 +548,7 @@ defmodule Pleroma.UserTest do
     user = insert(:user)
 
     assert User.ap_id(user) ==
-             Pleroma.Web.Router.Helpers.feed_url(
+             Pleroma.Web.Router.Helpers.user_feed_url(
                Pleroma.Web.Endpoint,
                :feed_redirect,
                user.nickname
@@ -559,7 +559,7 @@ defmodule Pleroma.UserTest do
     user = insert(:user)
 
     assert User.ap_followers(user) ==
-             Pleroma.Web.Router.Helpers.feed_url(
+             Pleroma.Web.Router.Helpers.user_feed_url(
                Pleroma.Web.Endpoint,
                :feed_redirect,
                user.nickname
diff --git a/test/web/feed/tag_controller_test.exs b/test/web/feed/tag_controller_test.exs
new file mode 100644 (file)
index 0000000..82115f8
--- /dev/null
@@ -0,0 +1,31 @@
+# Pleroma: A lightweight social networking server
+# Copyright © 2017-2019 Pleroma Authors <https://pleroma.social/>
+# SPDX-License-Identifier: AGPL-3.0-only
+
+defmodule Pleroma.Web.Feed.TagControllerTest do
+  use Pleroma.Web.ConnCase
+
+  import Pleroma.Factory
+
+  clear_config([:feed])
+
+  test "gets a feed", %{conn: conn} do
+    Pleroma.Config.put(
+      [:feed, :post_title],
+      %{max_length: 10, omission: "..."}
+    )
+
+    user = insert(:user)
+    {:ok, _activity1} = Pleroma.Web.CommonAPI.post(user, %{"status" => "yeah #PleromaArt"})
+
+    {:ok, _activity2} =
+      Pleroma.Web.CommonAPI.post(user, %{"status" => "42 This is :moominmamma #PleromaArt"})
+
+    {:ok, _activity3} = Pleroma.Web.CommonAPI.post(user, %{"status" => "This is :moominmamma"})
+
+    assert conn
+           |> put_req_header("content-type", "application/atom+xml")
+           |> get("/tags/pleromaart.rss")
+           |> response(200)
+  end
+end
similarity index 99%
rename from test/web/feed/feed_controller_test.exs
rename to test/web/feed/user_controller_test.exs
index 6f61acf43b2d4b6303a1f673ca0074d20e650d06..e4386ff2c81fc056ef6bdeb1f539dc5ca79f7ca6 100644 (file)
@@ -2,7 +2,7 @@
 # Copyright © 2017-2019 Pleroma Authors <https://pleroma.social/>
 # SPDX-License-Identifier: AGPL-3.0-only
 
-defmodule Pleroma.Web.Feed.FeedControllerTest do
+defmodule Pleroma.Web.Feed.UserControllerTest do
   use Pleroma.Web.ConnCase
 
   import Pleroma.Factory