2020-01-26 21:36:50 +01:00
|
|
|
defmodule Mobilizon.Web.PageView do
|
2018-10-11 17:37:39 +02:00
|
|
|
@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
|
2020-07-09 17:24:28 +02:00
|
|
|
alias Mobilizon.Discussions.{Comment, Discussion}
|
2020-02-18 08:57:00 +01:00
|
|
|
alias Mobilizon.Events.Event
|
2020-12-16 09:54:56 +01:00
|
|
|
alias Mobilizon.Posts.Post
|
2020-02-18 08:57:00 +01:00
|
|
|
alias Mobilizon.Resources.Resource
|
2019-12-03 11:29:51 +01:00
|
|
|
alias Mobilizon.Tombstone
|
2020-01-22 02:14:42 +01:00
|
|
|
|
2019-07-04 17:34:59 +02:00
|
|
|
alias Mobilizon.Service.Metadata
|
2019-10-10 16:47:38 +02:00
|
|
|
alias Mobilizon.Service.Metadata.Instance
|
2020-01-22 02:14:42 +01:00
|
|
|
|
|
|
|
alias Mobilizon.Federation.ActivityPub.Utils
|
2020-01-22 22:40:40 +01:00
|
|
|
alias Mobilizon.Federation.ActivityStream.Convertible
|
2020-06-18 15:23:05 +02:00
|
|
|
import Mobilizon.Web.Views.Utils
|
2019-05-02 13:04:21 +02:00
|
|
|
|
2021-09-27 09:41:36 +02:00
|
|
|
@doc false
|
|
|
|
@spec render(String.t(), %{conn: Plug.Conn.t()}) :: map() | String.t() | Plug.Conn.t()
|
2019-12-03 11:29:51 +01: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
|
|
|
|
|
2019-12-03 11:29:51 +01:00
|
|
|
def render("event.activity-json", %{conn: %{assigns: %{object: %Event{} = event}}}) do
|
2019-07-30 16:40:59 +02:00
|
|
|
event
|
2019-12-03 11:29:51 +01:00
|
|
|
|> Convertible.model_to_as()
|
2019-05-02 13:04:21 +02:00
|
|
|
|> Map.merge(Utils.make_json_ld_header())
|
|
|
|
end
|
|
|
|
|
2019-12-03 11:29:51 +01: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 13:04:21 +02:00
|
|
|
|
2019-12-03 11:29:51 +01: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
|
2019-07-04 17:34:59 +02:00
|
|
|
|
2020-07-09 17:24:28 +02: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 08:57:00 +01: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 11:29:51 +01:00
|
|
|
|
2020-12-16 09:54:56 +01: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
|
|
|
|
|
2022-07-12 10:55:28 +02:00
|
|
|
def render(page, %{object: object, conn: conn} = assigns)
|
2020-07-09 17:24:28 +02:00
|
|
|
when page in ["actor.html", "event.html", "comment.html", "post.html"] do
|
2021-03-09 19:39:54 +01:00
|
|
|
with locale <- get_locale(conn),
|
|
|
|
tags <- object |> Metadata.build_tags(locale),
|
2022-07-12 10:55:28 +02:00
|
|
|
assigns <- Map.put(assigns, :tags, tags) do
|
|
|
|
render("index.html", assigns)
|
2021-03-09 19:39:54 +01:00
|
|
|
end
|
2020-02-18 08:57:00 +01:00
|
|
|
end
|
2019-12-03 11:29:51 +01:00
|
|
|
|
2020-07-09 17:24:28 +02:00
|
|
|
# Discussions are private, no need to embed metadata
|
|
|
|
def render("discussion.html", params), do: render("index.html", params)
|
|
|
|
|
2022-07-12 10:55:28 +02:00
|
|
|
def tags(assigns) do
|
|
|
|
Map.get(assigns, :tags, Instance.build_tags())
|
|
|
|
end
|
|
|
|
|
|
|
|
def theme_color do
|
|
|
|
"#ffd599"
|
|
|
|
end
|
|
|
|
|
|
|
|
def language_direction(assigns) do
|
2022-09-21 08:32:42 +02:00
|
|
|
assigns |> Map.get(:locale, "en") |> get_language_direction()
|
2019-07-04 17:34:59 +02:00
|
|
|
end
|
2022-10-11 17:49:13 +02:00
|
|
|
|
|
|
|
@spec is_root(map()) :: boolean()
|
|
|
|
def is_root(assigns) do
|
|
|
|
assigns |> Map.get(:conn, %{request_path: "/"}) |> Map.get(:request_path, "/") == "/"
|
|
|
|
end
|
2018-10-11 17:37:39 +02:00
|
|
|
end
|