Formatting.

This commit is contained in:
lain 2018-04-20 13:10:57 +02:00
parent 18c3ca7844
commit a61e8ac154
4 changed files with 48 additions and 22 deletions

View File

@ -217,8 +217,8 @@ defmodule Pleroma.Web.MastodonAPI.MastodonAPIController do
activities = [] activities = []
else else
activities = activities =
ActivityPub.fetch_public_activities(params) ActivityPub.fetch_public_activities(params)
|> Enum.reverse() |> Enum.reverse()
end end
conn conn

View File

@ -23,16 +23,34 @@ defmodule Pleroma.Web.TwitterAPI.NotificationView do
end end
def render("notification.json", %{notifications: notifications, for: user}) do def render("notification.json", %{notifications: notifications, for: user}) do
render_many(notifications, Pleroma.Web.TwitterAPI.NotificationView, "notification.json", for: user) render_many(
notifications,
Pleroma.Web.TwitterAPI.NotificationView,
"notification.json",
for: user
)
end end
def render("notification.json", %{notification: %Notification{id: id, seen: seen, activity: activity, inserted_at: created_at}, for: user} = opts) do def render(
ntype = case activity.data["type"] do "notification.json",
"Create" -> "mention" %{
"Like" -> "like" notification: %Notification{
"Announce" -> "repeat" id: id,
"Follow" -> "follow" seen: seen,
end activity: activity,
inserted_at: created_at
},
for: user
} = opts
) do
ntype =
case activity.data["type"] do
"Create" -> "mention"
"Like" -> "like"
"Announce" -> "repeat"
"Follow" -> "follow"
end
from = get_user(activity.data["actor"], opts) from = get_user(activity.data["actor"], opts)
%{ %{
@ -40,7 +58,7 @@ defmodule Pleroma.Web.TwitterAPI.NotificationView do
"ntype" => ntype, "ntype" => ntype,
"notice" => ActivityView.render("activity.json", %{activity: activity, for: user}), "notice" => ActivityView.render("activity.json", %{activity: activity, for: user}),
"from_profile" => UserView.render("show.json", %{user: from, for: user}), "from_profile" => UserView.render("show.json", %{user: from, for: user}),
"is_seen" => (if seen, do: 1, else: 0), "is_seen" => if(seen, do: 1, else: 0),
"created_at" => created_at |> Utils.format_naive_asctime() "created_at" => created_at |> Utils.format_naive_asctime()
} }
end end

View File

@ -270,10 +270,10 @@ defmodule Pleroma.Web.TwitterAPI.ControllerTest do
assert length(response) == 1 assert length(response) == 1
assert response == assert response ==
NotificationView.render( NotificationView.render("notification.json", %{
"notification.json", notifications: Notification.for_user(current_user),
%{notifications: Notification.for_user(current_user), for: current_user} for: current_user
) })
end end
end end

View File

@ -36,14 +36,17 @@ defmodule Pleroma.Web.TwitterAPI.NotificationViewTest do
"ntype" => "follow" "ntype" => "follow"
} }
assert represented == NotificationView.render("notification.json", %{notification: follow_notif, for: user}) assert represented ==
NotificationView.render("notification.json", %{notification: follow_notif, for: user})
end end
test "A mention notification" do test "A mention notification" do
user = insert(:user) user = insert(:user)
other_user = insert(:user) other_user = insert(:user)
{:ok, activity} = TwitterAPI.create_status(other_user, %{"status" => "Päivää, @#{user.nickname}"}) {:ok, activity} =
TwitterAPI.create_status(other_user, %{"status" => "Päivää, @#{user.nickname}"})
[notification] = Notification.for_user(user) [notification] = Notification.for_user(user)
represented = %{ represented = %{
@ -55,7 +58,8 @@ defmodule Pleroma.Web.TwitterAPI.NotificationViewTest do
"ntype" => "mention" "ntype" => "mention"
} }
assert represented == NotificationView.render("notification.json", %{notification: notification, for: user}) assert represented ==
NotificationView.render("notification.json", %{notification: notification, for: user})
end end
test "A retweet notification" do test "A retweet notification" do
@ -71,11 +75,13 @@ defmodule Pleroma.Web.TwitterAPI.NotificationViewTest do
"from_profile" => UserView.render("show.json", %{user: repeater, for: user}), "from_profile" => UserView.render("show.json", %{user: repeater, for: user}),
"id" => notification.id, "id" => notification.id,
"is_seen" => 0, "is_seen" => 0,
"notice" => ActivityView.render("activity.json", %{activity: notification.activity, for: user}), "notice" =>
ActivityView.render("activity.json", %{activity: notification.activity, for: user}),
"ntype" => "repeat" "ntype" => "repeat"
} }
assert represented == NotificationView.render("notification.json", %{notification: notification, for: user}) assert represented ==
NotificationView.render("notification.json", %{notification: notification, for: user})
end end
test "A like notification" do test "A like notification" do
@ -91,10 +97,12 @@ defmodule Pleroma.Web.TwitterAPI.NotificationViewTest do
"from_profile" => UserView.render("show.json", %{user: liker, for: user}), "from_profile" => UserView.render("show.json", %{user: liker, for: user}),
"id" => notification.id, "id" => notification.id,
"is_seen" => 0, "is_seen" => 0,
"notice" => ActivityView.render("activity.json", %{activity: notification.activity, for: user}), "notice" =>
ActivityView.render("activity.json", %{activity: notification.activity, for: user}),
"ntype" => "like" "ntype" => "like"
} }
assert represented == NotificationView.render("notification.json", %{notification: notification, for: user}) assert represented ==
NotificationView.render("notification.json", %{notification: notification, for: user})
end end
end end