Merge branch 'develop' into feature/activitypub
[akkoma] / lib / pleroma / web / websub / websub.ex
index 41bdffb5bcccc6806279753c413127268c35d6ce..47a01849df74bc8b5bec01ff4b66954f9e8cb752 100644 (file)
@@ -38,7 +38,15 @@ defmodule Pleroma.Web.Websub do
     end
   end
 
-  def publish(topic, user, activity) do
+  @supported_activities [
+    "Create",
+    "Follow",
+    "Like",
+    "Announce",
+    "Undo",
+    "Delete"
+  ]
+  def publish(topic, user, %{data: %{"type" => type}} = activity) when type in @supported_activities do
     # TODO: Only send to still valid subscriptions.
     query = from sub in WebsubServerSubscription,
     where: sub.topic == ^topic and sub.state == "active"
@@ -58,6 +66,7 @@ defmodule Pleroma.Web.Websub do
       Pleroma.Web.Federator.enqueue(:publish_single_websub, data)
     end)
   end
+  def publish(_,_,_), do: ""
 
   def sign(secret, doc) do
     :crypto.hmac(:sha, secret, to_string(doc)) |> Base.encode16 |> String.downcase
@@ -142,11 +151,7 @@ defmodule Pleroma.Web.Websub do
     requester.(subscription)
   end
 
-  def long_get(url) do
-    @httpoison.get(url, [], timeout: 10_000, recv_timeout: 20_000)
-  end
-
-  def gather_feed_data(topic, getter \\ &long_get/1) do
+  def gather_feed_data(topic, getter \\ &@httpoison.get/1) do
     with {:ok, response} <- getter.(topic),
          status_code when status_code in 200..299 <- response.status_code,
          body <- response.body,