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
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
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
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)
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)])
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"]})