From e80abd8ee92c7fb3c918f917992657c3a517d735 Mon Sep 17 00:00:00 2001 From: Thomas Citharel Date: Wed, 6 Jun 2018 18:33:05 +0200 Subject: [PATCH] Remove pleroma mentions Signed-off-by: Thomas Citharel --- lib/service/activity_pub/activity_pub.ex | 14 ----- lib/service/activity_pub/transmogrifier.ex | 51 ---------------- lib/service/streamer.ex | 68 ---------------------- 3 files changed, 133 deletions(-) diff --git a/lib/service/activity_pub/activity_pub.ex b/lib/service/activity_pub/activity_pub.ex index bbbc456e..fe974b41 100644 --- a/lib/service/activity_pub/activity_pub.ex +++ b/lib/service/activity_pub/activity_pub.ex @@ -37,20 +37,6 @@ defmodule Eventos.Service.ActivityPub do end end -# def stream_out(%Activity{} = activity) do -# if activity.data["type"] in ["Create", "Announce"] do -# Pleroma.Web.Streamer.stream("user", activity) -# -# if Enum.member?(activity.data["to"], "https://www.w3.org/ns/activitystreams#Public") do -# Pleroma.Web.Streamer.stream("public", activity) -# -# if activity.local do -# Pleroma.Web.Streamer.stream("public:local", activity) -# end -# end -# end -# end - def fetch_event_from_url(url) do if object = Events.get_event_by_url!(url) do {:ok, object} diff --git a/lib/service/activity_pub/transmogrifier.ex b/lib/service/activity_pub/transmogrifier.ex index 3954de89..12c0d382 100644 --- a/lib/service/activity_pub/transmogrifier.ex +++ b/lib/service/activity_pub/transmogrifier.ex @@ -20,7 +20,6 @@ defmodule Eventos.Service.ActivityPub.Transmogrifier do |> fix_attachments |> fix_context #|> fix_in_reply_to - |> fix_emoji |> fix_tag end @@ -62,29 +61,6 @@ defmodule Eventos.Service.ActivityPub.Transmogrifier do |> Map.put("attachment", attachments) end - def fix_emoji(object) do - tags = object["tag"] || [] - emoji = tags |> Enum.filter(fn data -> data["type"] == "Emoji" and data["icon"] end) - - emoji = - emoji - |> Enum.reduce(%{}, fn data, mapping -> - name = data["name"] - - if String.starts_with?(name, ":") do - name = name |> String.slice(1..-2) - end - - mapping |> Map.put(name, data["icon"]["url"]) - end) - - # we merge mastodon and pleroma emoji into a single mapping, to allow for both wire formats - emoji = Map.merge(object["emoji"] || %{}, emoji) - - object - |> Map.put("emoji", emoji) - end - def fix_tag(object) do tags = (object["tag"] || []) @@ -308,21 +284,6 @@ defmodule Eventos.Service.ActivityPub.Transmogrifier do # end # end # -# def add_hashtags(object) do -# tags = -# (object["tag"] || []) -# |> Enum.map(fn tag -> -# %{ -# "href" => Pleroma.Web.Endpoint.url() <> "/tags/#{tag}", -# "name" => "##{tag}", -# "type" => "Hashtag" -# } -# end) -# -# object -# |> Map.put("tag", tags) -# end -# # def add_mention_tags(object) do # recipients = object["to"] ++ (object["cc"] || []) # @@ -468,16 +429,4 @@ defmodule Eventos.Service.ActivityPub.Transmogrifier do # end # end # -# def maybe_retire_websub(ap_id) do -# # some sanity checks -# if is_binary(ap_id) && String.length(ap_id) > 8 do -# q = -# from( -# ws in Pleroma.Web.Websub.WebsubClientSubscription, -# where: fragment("? like ?", ws.topic, ^"#{ap_id}%") -# ) -# -# Repo.delete_all(q) -# end -# end end diff --git a/lib/service/streamer.ex b/lib/service/streamer.ex index 2656e36b..fc9904ca 100644 --- a/lib/service/streamer.ex +++ b/lib/service/streamer.ex @@ -46,49 +46,6 @@ defmodule Eventos.Service.Streamer do {:noreply, topics} end -# def handle_cast(%{action: :stream, topic: "user", item: %Notification{} = item}, topics) do -# topic = "user:#{item.user_id}" -# -# Enum.each(topics[topic] || [], fn socket -> -# json = -# %{ -# event: "notification", -# payload: -# Pleroma.Web.MastodonAPI.MastodonAPIController.render_notification( -# socket.assigns["user"], -# item -# ) -# |> Jason.encode!() -# } -# |> Jason.encode!() -# -# send(socket.transport_pid, {:text, json}) -# end) -# -# {:noreply, topics} -# end - - def handle_cast(%{action: :stream, topic: "user", item: item}, topics) do - Logger.debug("Trying to push to users") - - recipient_topics = - User.get_recipients_from_activity(item) - |> Enum.map(fn %{id: id} -> "user:#{id}" end) - - Enum.each(recipient_topics, fn topic -> - push_to_socket(topics, topic, item) - end) - - {:noreply, topics} - end - - def handle_cast(%{action: :stream, topic: topic, item: item}, topics) do - Logger.debug("Trying to push to #{topic}") - Logger.debug("Pushing item to #{topic}") - push_to_socket(topics, topic, item) - {:noreply, topics} - end - def handle_cast(%{action: :add, topic: topic, socket: socket}, sockets) do topic = internal_topic(topic, socket) sockets_for_topic = sockets[topic] || [] @@ -112,31 +69,6 @@ defmodule Eventos.Service.Streamer do {:noreply, state} end - def push_to_socket(topics, topic, item) do - Enum.each(topics[topic] || [], fn socket -> - # Get the current user so we have up-to-date blocks etc. - user = User.get_cached_by_ap_id(socket.assigns[:user].ap_id) - blocks = user.info["blocks"] || [] - - unless item.actor in blocks do - json = - %{ - event: "update", - payload: - Pleroma.Web.MastodonAPI.StatusView.render( - "status.json", - activity: item, - for: user - ) - |> Jason.encode!() - } - |> Jason.encode!() - - send(socket.transport_pid, {:text, json}) - end - end) - end - defp internal_topic("user", socket) do "user:#{socket.assigns[:user].id}" end