diff options
8 files changed, 33 insertions, 9 deletions
| diff --git a/lib/pleroma/web/activity_pub/activity_pub.ex b/lib/pleroma/web/activity_pub/activity_pub.ex index ec9c5e970..75e4101f2 100644 --- a/lib/pleroma/web/activity_pub/activity_pub.ex +++ b/lib/pleroma/web/activity_pub/activity_pub.ex @@ -54,6 +54,12 @@ defmodule Pleroma.Web.ActivityPub.ActivityPub do      query = from activity in query,        where: activity.id > ^since_id +    query = if opts["max_id"] do +      from activity in query, where: activity.id < ^opts["max_id"] +    else +      query +    end +      Repo.all(query)      |> Enum.reverse    end diff --git a/lib/pleroma/web/twitter_api/representers/activity_representer.ex b/lib/pleroma/web/twitter_api/representers/activity_representer.ex index 5fe0df359..b0dd85bbb 100644 --- a/lib/pleroma/web/twitter_api/representers/activity_representer.ex +++ b/lib/pleroma/web/twitter_api/representers/activity_representer.ex @@ -33,7 +33,7 @@ defmodule Pleroma.Web.TwitterAPI.Representers.ActivityRepresenter do        "user" => UserRepresenter.to_map(user, opts),        "attentions" => [],        "statusnet_html" => content, -      "text" => content, +      "text" => HtmlSanitizeEx.strip_tags(content),        "is_local" => true,        "is_post_verb" => true,        "created_at" => published, diff --git a/lib/pleroma/web/twitter_api/twitter_api.ex b/lib/pleroma/web/twitter_api/twitter_api.ex index 0a942e880..0217b28d6 100644 --- a/lib/pleroma/web/twitter_api/twitter_api.ex +++ b/lib/pleroma/web/twitter_api/twitter_api.ex @@ -69,7 +69,7 @@ defmodule Pleroma.Web.TwitterAPI.TwitterAPI do    end    def fetch_friend_statuses(user, opts \\ %{}) do -    ActivityPub.fetch_activities(user.following, opts) +    ActivityPub.fetch_activities([user.ap_id | user.following], opts)      |> activities_to_statuses(%{for: user})    end diff --git a/lib/pleroma/web/twitter_api/twitter_api_controller.ex b/lib/pleroma/web/twitter_api/twitter_api_controller.ex index f2c893e96..c3a58b63a 100644 --- a/lib/pleroma/web/twitter_api/twitter_api_controller.ex +++ b/lib/pleroma/web/twitter_api/twitter_api_controller.ex @@ -44,7 +44,7 @@ defmodule Pleroma.Web.TwitterAPI.Controller do    end    def follow(%{assigns: %{user: user}} = conn, %{ "user_id" => followed_id }) do -    { :ok, _user, follower, _activity } = TwitterAPI.follow(user, followed_id) +    { :ok, user, follower, _activity } = TwitterAPI.follow(user, followed_id)      response = follower |> UserRepresenter.to_json(%{for: user}) diff --git a/test/web/activity_pub/activity_pub_test.exs b/test/web/activity_pub/activity_pub_test.exs index 2c6f67621..5cfd46238 100644 --- a/test/web/activity_pub/activity_pub_test.exs +++ b/test/web/activity_pub/activity_pub_test.exs @@ -94,6 +94,20 @@ defmodule Pleroma.Web.ActivityPub.ActivityPubTest do        assert length(activities) == 10        assert last == last_expected      end + +    test "retrieves ids up to max_id" do +      _first_activities = ActivityBuilder.insert_list(10) +      activities = ActivityBuilder.insert_list(20) +      later_activities = ActivityBuilder.insert_list(10) +      max_id = List.first(later_activities).id +      last_expected = List.last(activities) + +      activities = ActivityPub.fetch_public_activities(%{"max_id" => max_id}) +      last = List.last(activities) + +      assert length(activities) == 20 +      assert last == last_expected +    end    end    describe "uploading files" do diff --git a/test/web/twitter_api/representers/activity_representer_test.exs b/test/web/twitter_api/representers/activity_representer_test.exs index 256d920c0..6b0da810f 100644 --- a/test/web/twitter_api/representers/activity_representer_test.exs +++ b/test/web/twitter_api/representers/activity_representer_test.exs @@ -23,7 +23,8 @@ defmodule Pleroma.Web.TwitterAPI.Representers.ActivityRepresenterTest do        }      } -    content = "Some content mentioning @shp" +    content_html = "Some content mentioning <a href='shp'>@shp</shp>" +    content = HtmlSanitizeEx.strip_tags(content_html)      date = DateTime.utc_now() |> DateTime.to_iso8601      activity = %Activity{ @@ -39,7 +40,7 @@ defmodule Pleroma.Web.TwitterAPI.Representers.ActivityRepresenterTest do          "object" => %{            "published" => date,            "type" => "Note", -          "content" => content, +          "content" => content_html,            "inReplyToStatusId" => 213123,            "statusnetConversationId" => 4711,            "attachment" => [ @@ -56,7 +57,7 @@ defmodule Pleroma.Web.TwitterAPI.Representers.ActivityRepresenterTest do        "user" => UserRepresenter.to_map(user, %{for: follower}),        "is_local" => true,        "attentions" => [], -      "statusnet_html" => content, +      "statusnet_html" => content_html,        "text" => content,        "is_post_verb" => true,        "created_at" => date, diff --git a/test/web/twitter_api/twitter_api_controller_test.exs b/test/web/twitter_api/twitter_api_controller_test.exs index 5aad12593..7c75ff757 100644 --- a/test/web/twitter_api/twitter_api_controller_test.exs +++ b/test/web/twitter_api/twitter_api_controller_test.exs @@ -127,7 +127,7 @@ defmodule Pleroma.Web.TwitterAPI.ControllerTest do        current_user = Repo.get(User, current_user.id)        assert current_user.following == [User.ap_followers(followed)] -      assert json_response(conn, 200) == UserRepresenter.to_map(followed) +      assert json_response(conn, 200) == UserRepresenter.to_map(followed, %{for: current_user})      end    end @@ -150,7 +150,7 @@ defmodule Pleroma.Web.TwitterAPI.ControllerTest do        current_user = Repo.get(User, current_user.id)        assert current_user.following == [] -      assert json_response(conn, 200) == UserRepresenter.to_map(followed) +      assert json_response(conn, 200) == UserRepresenter.to_map(followed, %{for: current_user})      end    end diff --git a/test/web/twitter_api/twitter_api_test.exs b/test/web/twitter_api/twitter_api_test.exs index ad932131a..e8853a910 100644 --- a/test/web/twitter_api/twitter_api_test.exs +++ b/test/web/twitter_api/twitter_api_test.exs @@ -82,15 +82,18 @@ defmodule Pleroma.Web.TwitterAPI.TwitterAPITest do    test "fetch friends' statuses" do      ActivityBuilder.public_and_non_public +      {:ok, activity} = ActivityBuilder.insert(%{"to" => ["someguy/followers"]}) +    {:ok, direct_activity} = ActivityBuilder.insert(%{"to" => ["some other id"]})      {:ok, user} = UserBuilder.insert(%{ap_id: "some other id", following: ["someguy/followers"]})      statuses = TwitterAPI.fetch_friend_statuses(user)      activity_user = Repo.get_by(User, ap_id: activity.data["actor"]) -    assert length(statuses) == 1 +    assert length(statuses) == 2      assert Enum.at(statuses, 0) == ActivityRepresenter.to_map(activity, %{user: activity_user}) +    assert Enum.at(statuses, 1) == ActivityRepresenter.to_map(direct_activity, %{user: activity_user, mentioned: [user]})    end    test "fetch a single status" do | 
