From 923584d0467b2213bef0d3d78c8713f34b7b21d7 Mon Sep 17 00:00:00 2001 From: Roger Braun Date: Sat, 22 Apr 2017 14:37:54 +0200 Subject: [PATCH] Remove unknown activities from feed. --- lib/pleroma/web/ostatus/activity_representer.ex | 2 ++ lib/pleroma/web/ostatus/feed_representer.ex | 1 + lib/pleroma/web/websub/websub.ex | 1 - test/web/ostatus/activity_representer_test.exs | 7 ++++++- 4 files changed, 9 insertions(+), 2 deletions(-) diff --git a/lib/pleroma/web/ostatus/activity_representer.ex b/lib/pleroma/web/ostatus/activity_representer.ex index daaa4ef03..590abc8bb 100644 --- a/lib/pleroma/web/ostatus/activity_representer.ex +++ b/lib/pleroma/web/ostatus/activity_representer.ex @@ -22,4 +22,6 @@ defmodule Pleroma.Web.OStatus.ActivityRepresenter do {:updated, h.(updated_at)} ] ++ attachments end + + def to_simple_form(_,_), do: nil end diff --git a/lib/pleroma/web/ostatus/feed_representer.ex b/lib/pleroma/web/ostatus/feed_representer.ex index 42be5f793..c9cd12937 100644 --- a/lib/pleroma/web/ostatus/feed_representer.ex +++ b/lib/pleroma/web/ostatus/feed_representer.ex @@ -11,6 +11,7 @@ defmodule Pleroma.Web.OStatus.FeedRepresenter do entries = Enum.map(activities, fn(activity) -> {:entry, ActivityRepresenter.to_simple_form(activity, user)} end) + |> Enum.filter(fn ({_, form}) -> form end) [{ :feed, [ diff --git a/lib/pleroma/web/websub/websub.ex b/lib/pleroma/web/websub/websub.ex index cf819afd1..cc66b52dd 100644 --- a/lib/pleroma/web/websub/websub.ex +++ b/lib/pleroma/web/websub/websub.ex @@ -1,6 +1,5 @@ defmodule Pleroma.Web.Websub do alias Pleroma.Repo - alias Pleroma.Websub alias Pleroma.Web.Websub.WebsubServerSubscription alias Pleroma.Web.OStatus.FeedRepresenter alias Pleroma.Web.OStatus diff --git a/test/web/ostatus/activity_representer_test.exs b/test/web/ostatus/activity_representer_test.exs index de79717b1..61df41a1d 100644 --- a/test/web/ostatus/activity_representer_test.exs +++ b/test/web/ostatus/activity_representer_test.exs @@ -2,7 +2,7 @@ defmodule Pleroma.Web.OStatus.ActivityRepresenterTest do use Pleroma.DataCase alias Pleroma.Web.OStatus.ActivityRepresenter - alias Pleroma.User + alias Pleroma.{User, Activity} import Pleroma.Factory @@ -32,6 +32,11 @@ defmodule Pleroma.Web.OStatus.ActivityRepresenterTest do assert clean(res) == clean(expected) end + test "an unknown activity" do + tuple = ActivityRepresenter.to_simple_form(%Activity{}, nil) + assert is_nil(tuple) + end + defp clean(string) do String.replace(string, ~r/\s/, "") end