Merge branch 'develop' into feature/activitypub
[akkoma] / lib / pleroma / web / websub / websub.ex
index 6bbf13130dfb79e91fcdcfa0697620334798bf0a..47a01849df74bc8b5bec01ff4b66954f9e8cb752 100644 (file)
@@ -31,14 +31,22 @@ defmodule Pleroma.Web.Websub do
     do
       changeset = Changeset.change(subscription, %{state: "active"})
       Repo.update(changeset)
-    else _e ->
-      changeset = Changeset.change(subscription, %{state: "rejected"})
-      {:ok, subscription} = Repo.update(changeset)
+    else e ->
+      Logger.debug("Couldn't verify subscription")
+      Logger.debug(inspect(e))
       {:error, subscription}
     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