From a61e8ac15473aca6d0ec9ef20df981bcef9d5897 Mon Sep 17 00:00:00 2001 From: lain Date: Fri, 20 Apr 2018 13:10:57 +0200 Subject: [PATCH] Formatting. --- .../mastodon_api/mastodon_api_controller.ex | 4 +-- .../twitter_api/views/notification_view.ex | 36 ++++++++++++++----- .../twitter_api_controller_test.exs | 8 ++--- .../views/notification_view_test.exs | 22 ++++++++---- 4 files changed, 48 insertions(+), 22 deletions(-) diff --git a/lib/pleroma/web/mastodon_api/mastodon_api_controller.ex b/lib/pleroma/web/mastodon_api/mastodon_api_controller.ex index 10531ec15..8b3492332 100644 --- a/lib/pleroma/web/mastodon_api/mastodon_api_controller.ex +++ b/lib/pleroma/web/mastodon_api/mastodon_api_controller.ex @@ -217,8 +217,8 @@ def user_statuses(%{assigns: %{user: user}} = conn, params) do activities = [] else activities = - ActivityPub.fetch_public_activities(params) - |> Enum.reverse() + ActivityPub.fetch_public_activities(params) + |> Enum.reverse() end conn diff --git a/lib/pleroma/web/twitter_api/views/notification_view.ex b/lib/pleroma/web/twitter_api/views/notification_view.ex index 4e1ba0b54..f41edea0b 100644 --- a/lib/pleroma/web/twitter_api/views/notification_view.ex +++ b/lib/pleroma/web/twitter_api/views/notification_view.ex @@ -23,16 +23,34 @@ defp get_user(ap_id, opts) do end 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 - def render("notification.json", %{notification: %Notification{id: id, seen: seen, 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 + def render( + "notification.json", + %{ + notification: %Notification{ + id: id, + seen: seen, + 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) %{ @@ -40,7 +58,7 @@ def render("notification.json", %{notification: %Notification{id: id, seen: seen "ntype" => ntype, "notice" => ActivityView.render("activity.json", %{activity: activity, 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() } end diff --git a/test/web/twitter_api/twitter_api_controller_test.exs b/test/web/twitter_api/twitter_api_controller_test.exs index 18a3243f5..406dace1c 100644 --- a/test/web/twitter_api/twitter_api_controller_test.exs +++ b/test/web/twitter_api/twitter_api_controller_test.exs @@ -270,10 +270,10 @@ test "with credentials", %{conn: conn, user: current_user} do assert length(response) == 1 assert response == - NotificationView.render( - "notification.json", - %{notifications: Notification.for_user(current_user), for: current_user} - ) + NotificationView.render("notification.json", %{ + notifications: Notification.for_user(current_user), + for: current_user + }) end end diff --git a/test/web/twitter_api/views/notification_view_test.exs b/test/web/twitter_api/views/notification_view_test.exs index 33aaa89e1..e3b140657 100644 --- a/test/web/twitter_api/views/notification_view_test.exs +++ b/test/web/twitter_api/views/notification_view_test.exs @@ -36,14 +36,17 @@ test "A follow notification" do "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 test "A mention notification" do 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) represented = %{ @@ -55,7 +58,8 @@ test "A mention notification" do "ntype" => "mention" } - assert represented == NotificationView.render("notification.json", %{notification: notification, for: user}) + assert represented == + NotificationView.render("notification.json", %{notification: notification, for: user}) end test "A retweet notification" do @@ -71,11 +75,13 @@ test "A retweet notification" do "from_profile" => UserView.render("show.json", %{user: repeater, for: user}), "id" => notification.id, "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" } - assert represented == NotificationView.render("notification.json", %{notification: notification, for: user}) + assert represented == + NotificationView.render("notification.json", %{notification: notification, for: user}) end test "A like notification" do @@ -91,10 +97,12 @@ test "A like notification" do "from_profile" => UserView.render("show.json", %{user: liker, for: user}), "id" => notification.id, "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" } - assert represented == NotificationView.render("notification.json", %{notification: notification, for: user}) + assert represented == + NotificationView.render("notification.json", %{notification: notification, for: user}) end end