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)
%{
"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
"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 = %{
"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
"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
"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