debianize-mobilizon/lib/web/views/page_view.ex

72 lines
2.1 KiB
Elixir
Raw Normal View History

2020-01-26 21:36:50 +01:00
defmodule Mobilizon.Web.PageView do
@moduledoc """
View for our webapp
"""
2020-01-22 02:14:42 +01:00
2020-01-26 21:36:50 +01:00
use Mobilizon.Web, :view
2020-01-22 02:14:42 +01:00
2019-05-02 13:04:21 +02:00
alias Mobilizon.Actors.Actor
alias Mobilizon.Discussions.{Comment, Discussion}
alias Mobilizon.Events.Event
alias Mobilizon.Resources.Resource
alias Mobilizon.Tombstone
2020-01-22 02:14:42 +01:00
alias Mobilizon.Service.Metadata
alias Mobilizon.Service.Metadata.Instance
2020-01-22 02:14:42 +01:00
alias Mobilizon.Federation.ActivityPub.Utils
alias Mobilizon.Federation.ActivityStream.Convertible
import Mobilizon.Web.Views.Utils
2019-05-02 13:04:21 +02:00
def render("actor.activity-json", %{conn: %{assigns: %{object: %Actor{} = actor}}}) do
actor
|> Convertible.model_to_as()
2019-05-02 13:04:21 +02:00
|> Map.merge(Utils.make_json_ld_header())
end
def render("event.activity-json", %{conn: %{assigns: %{object: %Event{} = event}}}) do
event
|> Convertible.model_to_as()
2019-05-02 13:04:21 +02:00
|> Map.merge(Utils.make_json_ld_header())
end
def render("event.activity-json", %{conn: %{assigns: %{object: %Tombstone{} = event}}}) do
event
|> Convertible.model_to_as()
|> Map.merge(Utils.make_json_ld_header())
end
2019-05-02 13:04:21 +02:00
def render("comment.activity-json", %{conn: %{assigns: %{object: %Comment{} = comment}}}) do
comment
|> Convertible.model_to_as()
2019-05-02 13:04:21 +02:00
|> Map.merge(Utils.make_json_ld_header())
end
def render("discussion.activity-json", %{conn: %{assigns: %{object: %Discussion{} = resource}}}) do
resource
|> Convertible.model_to_as()
|> Map.merge(Utils.make_json_ld_header())
end
def render("resource.activity-json", %{conn: %{assigns: %{object: %Resource{} = resource}}}) do
resource
|> Convertible.model_to_as()
|> Map.merge(Utils.make_json_ld_header())
end
def render(page, %{object: object, conn: conn} = _assigns)
when page in ["actor.html", "event.html", "comment.html", "post.html"] do
locale = get_locale(conn)
tags = object |> Metadata.build_tags(locale)
inject_tags(tags, locale)
end
# Discussions are private, no need to embed metadata
def render("discussion.html", params), do: render("index.html", params)
def render("index.html", %{conn: conn}) do
tags = Instance.build_tags()
inject_tags(tags, get_locale(conn))
end
end