1 # Pleroma: A lightweight social networking server
2 # Copyright © 2017-2019 Pleroma Authors <https://pleroma.social/>
3 # SPDX-License-Identifier: AGPL-3.0-only
5 defmodule Pleroma.Web.StaticFE.StaticFEController do
6 use Pleroma.Web, :controller
11 alias Pleroma.Web.ActivityPub.ActivityPub
12 alias Pleroma.Web.Router.Helpers
14 plug(:put_layout, :static_fe)
15 plug(:put_view, Pleroma.Web.StaticFE.StaticFEView)
17 action_fallback(:not_found)
19 defp get_title(%Object{data: %{"name" => name}}) when is_binary(name),
22 defp get_title(%Object{data: %{"summary" => summary}}) when is_binary(summary),
25 defp get_title(_), do: nil
27 def get_counts(%Activity{} = activity) do
28 %Object{data: data} = Object.normalize(activity)
31 likes: data["like_count"] || 0,
32 replies: data["repliesCount"] || 0,
33 announces: data["announcement_count"] || 0
37 def represent(%Activity{object: %Object{data: data}} = activity, selected) do
38 {:ok, user} = User.get_or_fetch(activity.object.data["actor"])
42 Helpers.o_status_url(Pleroma.Web.Endpoint, :notice, activity)
44 data["url"] || data["external_url"] || data["id"]
49 title: get_title(activity.object),
50 content: data["content"] || nil,
51 attachment: data["attachment"],
53 published: data["published"],
54 sensitive: data["sensitive"],
56 counts: get_counts(activity)
60 def show_notice(%{assigns: %{notice_id: notice_id}} = conn, _params) do
61 instance_name = Pleroma.Config.get([:instance, :name], "Pleroma")
62 activity = Activity.get_by_id_with_object(notice_id)
63 context = activity.object.data["context"]
64 activities = ActivityPub.fetch_activities_for_context(context, %{})
67 for a <- Enum.reverse(activities) do
68 represent(a, a.object.id == activity.object.id)
71 render(conn, "conversation.html", %{activities: represented, instance_name: instance_name})
74 def show_user(%{assigns: %{username_or_id: username_or_id}} = conn, _params) do
75 instance_name = Pleroma.Config.get([:instance, :name], "Pleroma")
76 %User{} = user = User.get_cached_by_nickname_or_id(username_or_id)
79 for activity <- ActivityPub.fetch_user_activities(user, nil, %{}) do
80 represent(activity, false)
83 render(conn, "profile.html", %{user: user, timeline: timeline, instance_name: instance_name})
86 def assign_id(%{path_info: ["notice", notice_id]} = conn, _opts),
87 do: assign(conn, :notice_id, notice_id)
89 def assign_id(%{path_info: ["users", user_id]} = conn, _opts),
90 do: assign(conn, :username_or_id, user_id)
92 def assign_id(%{path_info: [user_id]} = conn, _opts),
93 do: assign(conn, :username_or_id, user_id)
95 def assign_id(conn, _opts), do: conn
97 # Fallback for unhandled types
98 def not_found(conn, _opts) do