Merge branch 'twitter-api-direct-messages' into 'develop'
Twitter api direct messages See merge request pleroma/pleroma!449
This commit is contained in:
commit
69d557e86d
|
@ -278,9 +278,12 @@ def user_statuses(%{assigns: %{user: reading_user}} = conn, params) do
|
|||
end
|
||||
end
|
||||
|
||||
def dm_timeline(%{assigns: %{user: user}} = conn, _params) do
|
||||
def dm_timeline(%{assigns: %{user: user}} = conn, params) do
|
||||
query =
|
||||
ActivityPub.fetch_activities_query([user.ap_id], %{"type" => "Create", visibility: "direct"})
|
||||
ActivityPub.fetch_activities_query(
|
||||
[user.ap_id],
|
||||
Map.merge(params, %{"type" => "Create", visibility: "direct"})
|
||||
)
|
||||
|
||||
activities = Repo.all(query)
|
||||
|
||||
|
|
|
@ -270,6 +270,7 @@ defmodule Pleroma.Web.Router do
|
|||
get("/statuses/friends_timeline", TwitterAPI.Controller, :friends_timeline)
|
||||
get("/statuses/mentions", TwitterAPI.Controller, :mentions_timeline)
|
||||
get("/statuses/mentions_timeline", TwitterAPI.Controller, :mentions_timeline)
|
||||
get("/statuses/dm_timeline", TwitterAPI.Controller, :dm_timeline)
|
||||
get("/qvitter/statuses/notifications", TwitterAPI.Controller, :notifications)
|
||||
|
||||
# XXX: this is really a pleroma API, but we want to keep the pleroma namespace clean
|
||||
|
|
|
@ -126,6 +126,19 @@ def mentions_timeline(%{assigns: %{user: user}} = conn, params) do
|
|||
|> render(ActivityView, "index.json", %{activities: activities, for: user})
|
||||
end
|
||||
|
||||
def dm_timeline(%{assigns: %{user: user}} = conn, params) do
|
||||
query =
|
||||
ActivityPub.fetch_activities_query(
|
||||
[user.ap_id],
|
||||
Map.merge(params, %{"type" => "Create", visibility: "direct"})
|
||||
)
|
||||
|
||||
activities = Repo.all(query)
|
||||
|
||||
conn
|
||||
|> render(ActivityView, "index.json", %{activities: activities, for: user})
|
||||
end
|
||||
|
||||
def notifications(%{assigns: %{user: user}} = conn, params) do
|
||||
notifications = Notification.for_user(user, params)
|
||||
|
||||
|
|
|
@ -178,6 +178,32 @@ test "direct timeline", %{conn: conn} do
|
|||
|> get("api/v1/timelines/home")
|
||||
|
||||
[_s1, _s2] = json_response(res_conn, 200)
|
||||
|
||||
# Test pagination
|
||||
Enum.each(1..20, fn _ ->
|
||||
{:ok, _} =
|
||||
CommonAPI.post(user_one, %{
|
||||
"status" => "Hi @#{user_two.nickname}!",
|
||||
"visibility" => "direct"
|
||||
})
|
||||
end)
|
||||
|
||||
res_conn =
|
||||
conn
|
||||
|> assign(:user, user_two)
|
||||
|> get("api/v1/timelines/direct")
|
||||
|
||||
statuses = json_response(res_conn, 200)
|
||||
assert length(statuses) == 20
|
||||
|
||||
res_conn =
|
||||
conn
|
||||
|> assign(:user, user_two)
|
||||
|> get("api/v1/timelines/direct", %{max_id: List.last(statuses)["id"]})
|
||||
|
||||
[status] = json_response(res_conn, 200)
|
||||
|
||||
assert status["url"] != direct.data["id"]
|
||||
end
|
||||
|
||||
test "replying to a status", %{conn: conn} do
|
||||
|
|
|
@ -271,6 +271,36 @@ test "with credentials", %{conn: conn, user: current_user} do
|
|||
end
|
||||
end
|
||||
|
||||
describe "GET /statuses/dm_timeline.json" do
|
||||
test "it show direct messages", %{conn: conn} do
|
||||
user_one = insert(:user)
|
||||
user_two = insert(:user)
|
||||
|
||||
{:ok, user_two} = User.follow(user_two, user_one)
|
||||
|
||||
{:ok, direct} =
|
||||
CommonAPI.post(user_one, %{
|
||||
"status" => "Hi @#{user_two.nickname}!",
|
||||
"visibility" => "direct"
|
||||
})
|
||||
|
||||
{:ok, _follower_only} =
|
||||
CommonAPI.post(user_one, %{
|
||||
"status" => "Hi @#{user_two.nickname}!",
|
||||
"visibility" => "private"
|
||||
})
|
||||
|
||||
# Only direct should be visible here
|
||||
res_conn =
|
||||
conn
|
||||
|> assign(:user, user_two)
|
||||
|> get("/api/statuses/dm_timeline.json")
|
||||
|
||||
[status] = json_response(res_conn, 200)
|
||||
assert status["id"] == direct.id
|
||||
end
|
||||
end
|
||||
|
||||
describe "GET /statuses/mentions.json" do
|
||||
setup [:valid_user]
|
||||
|
||||
|
|
Loading…
Reference in New Issue