2020-01-26 20:36:50 +00:00
|
|
|
defmodule Mobilizon.Web.PageView do
|
2018-10-11 15:37:39 +00:00
|
|
|
@moduledoc """
|
|
|
|
View for our webapp
|
|
|
|
"""
|
2020-01-22 01:14:42 +00:00
|
|
|
|
2020-01-26 20:36:50 +00:00
|
|
|
use Mobilizon.Web, :view
|
2020-01-22 01:14:42 +00:00
|
|
|
|
2019-05-02 11:04:21 +00:00
|
|
|
alias Mobilizon.Actors.Actor
|
2020-07-09 15:24:28 +00:00
|
|
|
alias Mobilizon.Discussions.{Comment, Discussion}
|
2020-02-18 07:57:00 +00:00
|
|
|
alias Mobilizon.Events.Event
|
2020-12-16 08:54:56 +00:00
|
|
|
alias Mobilizon.Posts.Post
|
2020-02-18 07:57:00 +00:00
|
|
|
alias Mobilizon.Resources.Resource
|
2019-12-03 10:29:51 +00:00
|
|
|
alias Mobilizon.Tombstone
|
2020-01-22 01:14:42 +00:00
|
|
|
|
2019-07-04 15:34:59 +00:00
|
|
|
alias Mobilizon.Service.Metadata
|
2019-10-10 14:47:38 +00:00
|
|
|
alias Mobilizon.Service.Metadata.Instance
|
2020-01-22 01:14:42 +00:00
|
|
|
|
|
|
|
alias Mobilizon.Federation.ActivityPub.Utils
|
2020-01-22 21:40:40 +00:00
|
|
|
alias Mobilizon.Federation.ActivityStream.Convertible
|
2020-06-18 13:23:05 +00:00
|
|
|
import Mobilizon.Web.Views.Utils
|
2019-05-02 11:04:21 +00:00
|
|
|
|
2019-12-03 10:29:51 +00:00
|
|
|
def render("actor.activity-json", %{conn: %{assigns: %{object: %Actor{} = actor}}}) do
|
|
|
|
actor
|
|
|
|
|> Convertible.model_to_as()
|
2019-05-02 11:04:21 +00:00
|
|
|
|> Map.merge(Utils.make_json_ld_header())
|
|
|
|
end
|
|
|
|
|
2019-12-03 10:29:51 +00:00
|
|
|
def render("event.activity-json", %{conn: %{assigns: %{object: %Event{} = event}}}) do
|
2019-07-30 14:40:59 +00:00
|
|
|
event
|
2019-12-03 10:29:51 +00:00
|
|
|
|> Convertible.model_to_as()
|
2019-05-02 11:04:21 +00:00
|
|
|
|> Map.merge(Utils.make_json_ld_header())
|
|
|
|
end
|
|
|
|
|
2019-12-03 10:29:51 +00:00
|
|
|
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 11:04:21 +00:00
|
|
|
|
2019-12-03 10:29:51 +00:00
|
|
|
def render("comment.activity-json", %{conn: %{assigns: %{object: %Comment{} = comment}}}) do
|
|
|
|
comment
|
|
|
|
|> Convertible.model_to_as()
|
2019-05-02 11:04:21 +00:00
|
|
|
|> Map.merge(Utils.make_json_ld_header())
|
|
|
|
end
|
2019-07-04 15:34:59 +00:00
|
|
|
|
2020-07-09 15:24:28 +00:00
|
|
|
def render("discussion.activity-json", %{conn: %{assigns: %{object: %Discussion{} = resource}}}) do
|
|
|
|
resource
|
|
|
|
|> Convertible.model_to_as()
|
|
|
|
|> Map.merge(Utils.make_json_ld_header())
|
|
|
|
end
|
|
|
|
|
2020-02-18 07:57:00 +00:00
|
|
|
def render("resource.activity-json", %{conn: %{assigns: %{object: %Resource{} = resource}}}) do
|
|
|
|
resource
|
|
|
|
|> Convertible.model_to_as()
|
|
|
|
|> Map.merge(Utils.make_json_ld_header())
|
|
|
|
end
|
2019-12-03 10:29:51 +00:00
|
|
|
|
2020-12-16 08:54:56 +00:00
|
|
|
def render("post.activity-json", %{conn: %{assigns: %{object: %Post{} = post}}}) do
|
|
|
|
post
|
|
|
|
|> Convertible.model_to_as()
|
|
|
|
|> Map.merge(Utils.make_json_ld_header())
|
|
|
|
end
|
|
|
|
|
2020-02-18 07:57:00 +00:00
|
|
|
def render(page, %{object: object, conn: conn} = _assigns)
|
2020-07-09 15:24:28 +00:00
|
|
|
when page in ["actor.html", "event.html", "comment.html", "post.html"] do
|
2020-06-15 14:20:58 +00:00
|
|
|
locale = get_locale(conn)
|
|
|
|
tags = object |> Metadata.build_tags(locale)
|
|
|
|
inject_tags(tags, locale)
|
2020-02-18 07:57:00 +00:00
|
|
|
end
|
2019-12-03 10:29:51 +00:00
|
|
|
|
2020-07-09 15:24:28 +00:00
|
|
|
# Discussions are private, no need to embed metadata
|
|
|
|
def render("discussion.html", params), do: render("index.html", params)
|
|
|
|
|
2020-02-18 07:57:00 +00:00
|
|
|
def render("index.html", %{conn: conn}) do
|
|
|
|
tags = Instance.build_tags()
|
2020-06-15 14:20:58 +00:00
|
|
|
inject_tags(tags, get_locale(conn))
|
2019-07-04 15:34:59 +00:00
|
|
|
end
|
2018-10-11 15:37:39 +00:00
|
|
|
end
|