2018-10-11 17:37:39 +02:00
|
|
|
defmodule MobilizonWeb.PageController do
|
2018-01-14 17:56:50 +01:00
|
|
|
@moduledoc """
|
|
|
|
Controller to load our webapp
|
|
|
|
"""
|
2018-10-11 17:37:39 +02:00
|
|
|
use MobilizonWeb, :controller
|
2019-03-04 17:20:18 +01:00
|
|
|
alias Mobilizon.Actors
|
|
|
|
alias Mobilizon.Actors.Actor
|
|
|
|
alias Mobilizon.Events
|
|
|
|
alias Mobilizon.Events.{Event, Comment}
|
2018-01-13 23:33:03 +01:00
|
|
|
|
2019-03-05 10:13:19 +01:00
|
|
|
action_fallback(MobilizonWeb.FallbackController)
|
2017-12-08 09:58:14 +01:00
|
|
|
|
|
|
|
def index(conn, _params) do
|
2019-04-30 13:16:29 +02:00
|
|
|
render(conn, "app.html")
|
2017-12-08 09:58:14 +01:00
|
|
|
end
|
2019-03-04 17:20:18 +01:00
|
|
|
|
|
|
|
def actor(conn, %{"name" => name}) do
|
|
|
|
case get_format(conn) do
|
|
|
|
"html" ->
|
|
|
|
with {status, %Actor{} = actor} when status in [:ok, :commit] <-
|
|
|
|
Actors.get_cached_local_actor_by_name(name) do
|
|
|
|
render_with_meta(conn, actor)
|
2019-03-05 10:13:19 +01:00
|
|
|
else
|
|
|
|
_ -> {:error, :not_found}
|
2019-03-04 17:20:18 +01:00
|
|
|
end
|
|
|
|
|
2019-03-05 10:13:19 +01:00
|
|
|
# "activity-json" matches "application/activity+json" inside our config
|
|
|
|
"activity-json" ->
|
2019-03-04 17:20:18 +01:00
|
|
|
MobilizonWeb.ActivityPubController.call(conn, :actor)
|
|
|
|
|
|
|
|
_ ->
|
|
|
|
{:error, :not_found}
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
def event(conn, %{"uuid" => uuid}) do
|
|
|
|
case get_format(conn) do
|
|
|
|
"html" ->
|
|
|
|
with {status, %Event{} = event} when status in [:ok, :commit] <-
|
|
|
|
Events.get_cached_event_full_by_uuid(uuid),
|
|
|
|
true <- event.visibility in [:public, :unlisted] do
|
|
|
|
render_with_meta(conn, event)
|
2019-03-05 10:13:19 +01:00
|
|
|
else
|
|
|
|
_ -> {:error, :not_found}
|
2019-03-04 17:20:18 +01:00
|
|
|
end
|
|
|
|
|
2019-03-05 10:13:19 +01:00
|
|
|
"activity-json" ->
|
2019-03-04 17:20:18 +01:00
|
|
|
MobilizonWeb.ActivityPubController.call(conn, :event)
|
|
|
|
|
|
|
|
_ ->
|
|
|
|
{:error, :not_found}
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
def comment(conn, %{"uuid" => uuid}) do
|
|
|
|
case get_format(conn) do
|
|
|
|
"html" ->
|
|
|
|
with {status, %Comment{} = comment} when status in [:ok, :commit] <-
|
2019-04-26 09:56:25 +02:00
|
|
|
Events.get_cached_comment_full_by_uuid(uuid),
|
|
|
|
true <- comment.visibility in [:public, :unlisted] do
|
2019-03-04 17:20:18 +01:00
|
|
|
render_with_meta(conn, comment)
|
2019-03-05 10:13:19 +01:00
|
|
|
else
|
|
|
|
_ -> {:error, :not_found}
|
2019-03-04 17:20:18 +01:00
|
|
|
end
|
|
|
|
|
2019-03-05 10:13:19 +01:00
|
|
|
"activity-json" ->
|
2019-03-04 17:20:18 +01:00
|
|
|
MobilizonWeb.ActivityPubController.call(conn, :comment)
|
|
|
|
|
|
|
|
_ ->
|
|
|
|
{:error, :not_found}
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
# Inject OpenGraph information
|
|
|
|
defp render_with_meta(conn, object) do
|
2019-04-30 13:16:29 +02:00
|
|
|
render(conn, "app.html", object: object)
|
2019-03-04 17:20:18 +01:00
|
|
|
end
|
2017-12-08 09:58:14 +01:00
|
|
|
end
|