aboutsummaryrefslogtreecommitdiff
path: root/lib/pleroma/web
diff options
context:
space:
mode:
authorlambda <pleromagit@rogerbraun.net>2018-06-12 07:19:45 +0000
committerlambda <pleromagit@rogerbraun.net>2018-06-12 07:19:45 +0000
commit564c73ab2496bee24ba46f69fc48662296041db6 (patch)
tree6769262a7969684022abc30f71e8b935c36151c7 /lib/pleroma/web
parenta6e0c31518ff60bd5e147941446779d719afaeb2 (diff)
parent5d3fdbc08223a1b8b6f36f2621214285c383b840 (diff)
downloadpleroma-564c73ab2496bee24ba46f69fc48662296041db6.tar.gz
Merge branch 'feature/list-streaming' into 'develop'
MastoAPI: Add streaming for lists. See merge request pleroma/pleroma!183
Diffstat (limited to 'lib/pleroma/web')
-rw-r--r--lib/pleroma/web/activity_pub/activity_pub.ex1
-rw-r--r--lib/pleroma/web/mastodon_api/mastodon_socket.ex7
-rw-r--r--lib/pleroma/web/streamer.ex13
3 files changed, 19 insertions, 2 deletions
diff --git a/lib/pleroma/web/activity_pub/activity_pub.ex b/lib/pleroma/web/activity_pub/activity_pub.ex
index 3c2875548..e2d7cbb6e 100644
--- a/lib/pleroma/web/activity_pub/activity_pub.ex
+++ b/lib/pleroma/web/activity_pub/activity_pub.ex
@@ -57,6 +57,7 @@ defmodule Pleroma.Web.ActivityPub.ActivityPub do
if activity.data["type"] in ["Create", "Announce"] do
Pleroma.Web.Streamer.stream("user", activity)
+ Pleroma.Web.Streamer.stream("list", activity)
if Enum.member?(activity.data["to"], public) do
Pleroma.Web.Streamer.stream("public", activity)
diff --git a/lib/pleroma/web/mastodon_api/mastodon_socket.ex b/lib/pleroma/web/mastodon_api/mastodon_socket.ex
index 080f62b31..46648c366 100644
--- a/lib/pleroma/web/mastodon_api/mastodon_socket.ex
+++ b/lib/pleroma/web/mastodon_api/mastodon_socket.ex
@@ -15,10 +15,13 @@ defmodule Pleroma.Web.MastodonAPI.MastodonSocket do
with token when not is_nil(token) <- params["access_token"],
%Token{user_id: user_id} <- Repo.get_by(Token, token: token),
%User{} = user <- Repo.get(User, user_id),
- stream when stream in ["public", "public:local", "user", "direct"] <- params["stream"] do
+ stream when stream in ["public", "public:local", "user", "direct", "list"] <-
+ params["stream"] do
+ topic = if stream == "list", do: "list:#{params["list"]}", else: stream
+
socket =
socket
- |> assign(:topic, params["stream"])
+ |> assign(:topic, topic)
|> assign(:user, user)
Pleroma.Web.Streamer.add_socket(params["stream"], socket)
diff --git a/lib/pleroma/web/streamer.ex b/lib/pleroma/web/streamer.ex
index 6ed9035fb..0c9e95485 100644
--- a/lib/pleroma/web/streamer.ex
+++ b/lib/pleroma/web/streamer.ex
@@ -59,6 +59,19 @@ defmodule Pleroma.Web.Streamer do
{:noreply, topics}
end
+ def handle_cast(%{action: :stream, topic: "list", item: item}, topics) do
+ recipient_topics =
+ Pleroma.List.get_lists_from_activity(item)
+ |> Enum.map(fn %{id: id} -> "list:#{id}" end)
+
+ Enum.each(recipient_topics || [], fn list_topic ->
+ Logger.debug("Trying to push message to #{list_topic}\n\n")
+ push_to_socket(topics, list_topic, item)
+ end)
+
+ {:noreply, topics}
+ end
+
def handle_cast(%{action: :stream, topic: "user", item: %Notification{} = item}, topics) do
topic = "user:#{item.user_id}"