static fe: proof of concept
This commit is contained in:
parent
9de593689c
commit
a4d3a8ec03
5 changed files with 228 additions and 0 deletions
42
lib/pleroma/web/static_fe/static_fe_controller.ex
Normal file
42
lib/pleroma/web/static_fe/static_fe_controller.ex
Normal file
|
|
@ -0,0 +1,42 @@
|
|||
# Pleroma: A lightweight social networking server
|
||||
# Copyright © 2017-2019 Pleroma Authors <https://pleroma.social/>
|
||||
# SPDX-License-Identifier: AGPL-3.0-only
|
||||
|
||||
defmodule Pleroma.Web.StaticFE.StaticFEController do
|
||||
use Pleroma.Web, :controller
|
||||
|
||||
alias Pleroma.Repo
|
||||
alias Pleroma.Activity
|
||||
alias Pleroma.Object
|
||||
alias Pleroma.User
|
||||
alias Pleroma.Web.ActivityPub.Visibility
|
||||
|
||||
require Logger
|
||||
|
||||
def show_notice(conn, %{"notice_id" => notice_id}) do
|
||||
with %Activity{} = activity <- Repo.get(Activity, notice_id),
|
||||
true <- Visibility.is_public?(activity),
|
||||
%User{} = user <- User.get_or_fetch(activity.data["actor"]),
|
||||
%Object{} = object <- Object.normalize(activity.data["object"]) do
|
||||
conn
|
||||
|> put_layout(:static_fe)
|
||||
|> put_status(200)
|
||||
|> put_view(Pleroma.Web.StaticFE.StaticFEView)
|
||||
|> render("notice.html", %{notice: activity, object: object, user: user})
|
||||
else
|
||||
_ ->
|
||||
conn
|
||||
|> put_status(404)
|
||||
|> text("Not found")
|
||||
end
|
||||
end
|
||||
|
||||
def show(%{path_info: ["notice", notice_id]} = conn, _params), do: show_notice(conn, %{"notice_id" => notice_id})
|
||||
|
||||
# Fallback for unhandled types
|
||||
def show(conn, _params) do
|
||||
conn
|
||||
|> put_status(404)
|
||||
|> text("Not found")
|
||||
end
|
||||
end
|
||||
19
lib/pleroma/web/static_fe/static_fe_view.ex
Normal file
19
lib/pleroma/web/static_fe/static_fe_view.ex
Normal file
|
|
@ -0,0 +1,19 @@
|
|||
# Pleroma: A lightweight social networking server
|
||||
# Copyright © 2017-2019 Pleroma Authors <https://pleroma.social/>
|
||||
# SPDX-License-Identifier: AGPL-3.0-only
|
||||
|
||||
defmodule Pleroma.Web.StaticFE.StaticFEView do
|
||||
use Pleroma.Web, :view
|
||||
|
||||
alias Pleroma.User
|
||||
alias Pleroma.Web.MediaProxy
|
||||
alias Pleroma.Formatter
|
||||
|
||||
def emoji_for_user(%User{} = user) do
|
||||
(user.info.source_data["tag"] || [])
|
||||
|> Enum.filter(fn %{"type" => t} -> t == "Emoji" end)
|
||||
|> Enum.map(fn %{"icon" => %{"url" => url}, "name" => name} ->
|
||||
{String.trim(name, ":"), url}
|
||||
end)
|
||||
end
|
||||
end
|
||||
Loading…
Add table
Add a link
Reference in a new issue