Add twkn timeline.
authorRoger Braun <roger@rogerbraun.net>
Tue, 2 May 2017 12:12:43 +0000 (14:12 +0200)
committerRoger Braun <roger@rogerbraun.net>
Tue, 2 May 2017 12:12:43 +0000 (14:12 +0200)
lib/pleroma/web/activity_pub/activity_pub.ex
lib/pleroma/web/router.ex
lib/pleroma/web/twitter_api/twitter_api.ex
lib/pleroma/web/twitter_api/twitter_api_controller.ex
test/web/twitter_api/twitter_api_test.exs

index 4eab2e2d040aa1d60a5bb3e07b2aaf17fbdf9486..0fb8db52048b0390cf1569dc4b23238df6a018fb 100644 (file)
@@ -149,6 +149,12 @@ defmodule Pleroma.Web.ActivityPub.ActivityPub do
     query = from activity in query,
       where: activity.id > ^since_id
 
+    query = if opts["local_only"] do
+      from activity in query, where: activity.local == true
+    else
+      query
+    end
+
     query = if opts["max_id"] do
       from activity in query, where: activity.id < ^opts["max_id"]
     else
index e1475a03eea26e0f1d85225ef92e3bd4f4b4c33e..b0c1dcd9177b77990b11032141aaa69ee91d8bf7 100644 (file)
@@ -30,7 +30,7 @@ defmodule Pleroma.Web.Router do
     get "/statusnet/config", TwitterAPI.Controller, :config
 
     get "/statuses/public_timeline", TwitterAPI.Controller, :public_timeline
-    get "/statuses/public_and_external_timeline", TwitterAPI.Controller, :public_timeline
+    get "/statuses/public_and_external_timeline", TwitterAPI.Controller, :public_and_external_timeline
     get "/statuses/user_timeline", TwitterAPI.Controller, :user_timeline
 
     get "/statuses/show/:id", TwitterAPI.Controller, :fetch_status
index e6f5fc90645807c61cc9a2b903a167ebb6120c5e..b1759a6f00c606734a6dc3736d9b0e6c34f2bd70 100644 (file)
@@ -84,6 +84,12 @@ defmodule Pleroma.Web.TwitterAPI.TwitterAPI do
   end
 
   def fetch_public_statuses(user, opts \\ %{}) do
+    opts = Map.put(opts, "local_only", true)
+    ActivityPub.fetch_public_activities(opts)
+    |> activities_to_statuses(%{for: user})
+  end
+
+  def fetch_public_and_external_statuses(user, opts \\ %{}) do
     ActivityPub.fetch_public_activities(opts)
     |> activities_to_statuses(%{for: user})
   end
index b5b829ca0532d8fd539e303f853dc21fa358bdd6..4b329a21f791e018e880271c31df5f6dc4da4cb8 100644 (file)
@@ -41,6 +41,14 @@ defmodule Pleroma.Web.TwitterAPI.Controller do
     end
   end
 
+  def public_and_external_timeline(%{assigns: %{user: user}} = conn, params) do
+    statuses = TwitterAPI.fetch_public_and_external_statuses(user, params)
+    {:ok, json} = Poison.encode(statuses)
+
+    conn
+    |> json_reply(200, json)
+  end
+
   def public_timeline(%{assigns: %{user: user}} = conn, params) do
     statuses = TwitterAPI.fetch_public_statuses(user, params)
     {:ok, json} = Poison.encode(statuses)
index 57dcddd4c16de7a71a64395f7d50743486d37d76..4e17f3298f6b421389981d8c54559b9dc6402487 100644 (file)
@@ -73,8 +73,9 @@ defmodule Pleroma.Web.TwitterAPI.TwitterAPITest do
     assert Enum.member?(get_in(reply.data, ["to"]), "some_cool_id")
   end
 
-  test "fetch public statuses" do
+  test "fetch public statuses, excluding remote ones." do
     %{ public: activity, user: user } = ActivityBuilder.public_and_non_public
+    insert(:note_activity, %{local: false})
 
     follower = insert(:user, following: [User.ap_followers(user)])
 
@@ -84,6 +85,18 @@ defmodule Pleroma.Web.TwitterAPI.TwitterAPITest do
     assert Enum.at(statuses, 0) == ActivityRepresenter.to_map(activity, %{user: user, for: follower})
   end
 
+  test "fetch whole known network statuses" do
+    %{ public: activity, user: user } = ActivityBuilder.public_and_non_public
+    insert(:note_activity, %{local: false})
+
+    follower = insert(:user, following: [User.ap_followers(user)])
+
+    statuses = TwitterAPI.fetch_public_and_external_statuses(follower)
+
+    assert length(statuses) == 2
+    assert Enum.at(statuses, 0) == ActivityRepresenter.to_map(activity, %{user: user, for: follower})
+  end
+
   test "fetch friends' statuses" do
     user = insert(:user, %{following: ["someguy/followers"]})
     {:ok, activity} = ActivityBuilder.insert(%{"to" => ["someguy/followers"]})