106
lib/eventos_web/controllers/activity_pub_controller.ex
Normal file
106
lib/eventos_web/controllers/activity_pub_controller.ex
Normal file
@@ -0,0 +1,106 @@
|
||||
defmodule EventosWeb.ActivityPubController do
|
||||
use EventosWeb, :controller
|
||||
alias Eventos.{Accounts, Accounts.Account, Events, Events.Event}
|
||||
alias EventosWeb.ActivityPub.{ObjectView, AccountView}
|
||||
alias Eventos.Service.ActivityPub
|
||||
alias Eventos.Service.Federator
|
||||
|
||||
require Logger
|
||||
|
||||
action_fallback(:errors)
|
||||
|
||||
def account(conn, %{"username" => username}) do
|
||||
with %Account{} = account <- Accounts.get_account_by_username(username) do
|
||||
conn
|
||||
|> put_resp_header("content-type", "application/activity+json")
|
||||
|> json(AccountView.render("account.json", %{account: account}))
|
||||
end
|
||||
end
|
||||
|
||||
def event(conn, %{"username" => username, "slug" => slug}) do
|
||||
with %Event{} = event <- Events.get_event_full_by_username_and_slug!(username, slug) do
|
||||
conn
|
||||
|> put_resp_header("content-type", "application/activity+json")
|
||||
|> json(ObjectView.render("event.json", %{event: event}))
|
||||
end
|
||||
end
|
||||
|
||||
# def following(conn, %{"username" => username, "page" => page}) do
|
||||
# with %Account{} = account <- Accounts.get_account_by_username(username) do
|
||||
# {page, _} = Integer.parse(page)
|
||||
#
|
||||
# conn
|
||||
# |> put_resp_header("content-type", "application/activity+json")
|
||||
# |> json(UserView.render("following.json", %{account: account, page: page}))
|
||||
# end
|
||||
# end
|
||||
#
|
||||
# def following(conn, %{"nickname" => nickname}) do
|
||||
# with %User{} = user <- User.get_cached_by_nickname(nickname),
|
||||
# {:ok, user} <- Pleroma.Web.WebFinger.ensure_keys_present(user) do
|
||||
# conn
|
||||
# |> put_resp_header("content-type", "application/activity+json")
|
||||
# |> json(UserView.render("following.json", %{user: user}))
|
||||
# end
|
||||
# end
|
||||
#
|
||||
# def followers(conn, %{"nickname" => nickname, "page" => page}) do
|
||||
# with %User{} = user <- User.get_cached_by_nickname(nickname),
|
||||
# {:ok, user} <- Pleroma.Web.WebFinger.ensure_keys_present(user) do
|
||||
# {page, _} = Integer.parse(page)
|
||||
#
|
||||
# conn
|
||||
# |> put_resp_header("content-type", "application/activity+json")
|
||||
# |> json(UserView.render("followers.json", %{user: user, page: page}))
|
||||
# end
|
||||
# end
|
||||
#
|
||||
# def followers(conn, %{"nickname" => nickname}) do
|
||||
# with %User{} = user <- User.get_cached_by_nickname(nickname),
|
||||
# {:ok, user} <- Pleroma.Web.WebFinger.ensure_keys_present(user) do
|
||||
# conn
|
||||
# |> put_resp_header("content-type", "application/activity+json")
|
||||
# |> json(UserView.render("followers.json", %{user: user}))
|
||||
# end
|
||||
# end
|
||||
|
||||
def outbox(conn, %{"username" => username, "page" => page}) do
|
||||
with {page, ""} = Integer.parse(page),
|
||||
%Account{} = account <- Accounts.get_account_by_username(username) do
|
||||
conn
|
||||
|> put_resp_header("content-type", "application/activity+json")
|
||||
|> json(AccountView.render("outbox.json", %{account: account, page: page}))
|
||||
end
|
||||
end
|
||||
|
||||
def outbox(conn, %{"username" => username}) do
|
||||
outbox(conn, %{"username" => username, "page" => "0"})
|
||||
end
|
||||
|
||||
# TODO: Ensure that this inbox is a recipient of the message
|
||||
def inbox(%{assigns: %{valid_signature: true}} = conn, params) do
|
||||
Federator.enqueue(:incoming_ap_doc, params)
|
||||
json(conn, "ok")
|
||||
end
|
||||
|
||||
def inbox(conn, params) do
|
||||
headers = Enum.into(conn.req_headers, %{})
|
||||
|
||||
if !String.contains?(headers["signature"] || "", params["actor"]) do
|
||||
Logger.info("Signature not from author, relayed message, fetching from source")
|
||||
ActivityPub.fetch_event_from_url(params["object"]["id"])
|
||||
else
|
||||
Logger.info("Signature error")
|
||||
Logger.info("Could not validate #{params["actor"]}")
|
||||
Logger.info(inspect(conn.req_headers))
|
||||
end
|
||||
|
||||
json(conn, "ok")
|
||||
end
|
||||
|
||||
def errors(conn, _e) do
|
||||
conn
|
||||
|> put_status(500)
|
||||
|> json("error")
|
||||
end
|
||||
end
|
||||
42
lib/eventos_web/controllers/comment_controller.ex
Normal file
42
lib/eventos_web/controllers/comment_controller.ex
Normal file
@@ -0,0 +1,42 @@
|
||||
defmodule EventosWeb.CommentController do
|
||||
use EventosWeb, :controller
|
||||
|
||||
alias Eventos.Events
|
||||
alias Eventos.Events.Comment
|
||||
|
||||
action_fallback EventosWeb.FallbackController
|
||||
|
||||
def index(conn, _params) do
|
||||
comments = Events.list_comments()
|
||||
render(conn, "index.json", comments: comments)
|
||||
end
|
||||
|
||||
def create(conn, %{"comment" => comment_params}) do
|
||||
with {:ok, %Comment{} = comment} <- Events.create_comment(comment_params) do
|
||||
conn
|
||||
|> put_status(:created)
|
||||
|> put_resp_header("location", comment_path(conn, :show, comment))
|
||||
|> render("show.json", comment: comment)
|
||||
end
|
||||
end
|
||||
|
||||
def show(conn, %{"id" => id}) do
|
||||
comment = Events.get_comment!(id)
|
||||
render(conn, "show.json", comment: comment)
|
||||
end
|
||||
|
||||
def update(conn, %{"id" => id, "comment" => comment_params}) do
|
||||
comment = Events.get_comment!(id)
|
||||
|
||||
with {:ok, %Comment{} = comment} <- Events.update_comment(comment, comment_params) do
|
||||
render(conn, "show.json", comment: comment)
|
||||
end
|
||||
end
|
||||
|
||||
def delete(conn, %{"id" => id}) do
|
||||
comment = Events.get_comment!(id)
|
||||
with {:ok, %Comment{}} <- Events.delete_comment(comment) do
|
||||
send_resp(conn, :no_content, "")
|
||||
end
|
||||
end
|
||||
end
|
||||
@@ -15,7 +15,6 @@ defmodule EventosWeb.GroupController do
|
||||
end
|
||||
|
||||
def create(conn, %{"group" => group_params}) do
|
||||
group_params = Map.put(group_params, "uri", "h")
|
||||
group_params = Map.put(group_params, "url", "h")
|
||||
with {:ok, %Group{} = group} <- Groups.create_group(group_params) do
|
||||
conn
|
||||
|
||||
8
lib/eventos_web/controllers/inboxes_controller.ex
Normal file
8
lib/eventos_web/controllers/inboxes_controller.ex
Normal file
@@ -0,0 +1,8 @@
|
||||
defmodule EventosWeb.InboxesController do
|
||||
|
||||
use EventosWeb, :controller
|
||||
|
||||
def create(conn) do
|
||||
|
||||
end
|
||||
end
|
||||
67
lib/eventos_web/controllers/nodeinfo_controller.ex
Normal file
67
lib/eventos_web/controllers/nodeinfo_controller.ex
Normal file
@@ -0,0 +1,67 @@
|
||||
defmodule EventosWeb.NodeinfoController do
|
||||
use EventosWeb, :controller
|
||||
|
||||
alias EventosWeb
|
||||
alias Eventos.{Accounts, Events}
|
||||
|
||||
@instance Application.get_env(:eventos, :instance)
|
||||
|
||||
def schemas(conn, _params) do
|
||||
response = %{
|
||||
links: [
|
||||
%{
|
||||
rel: "http://nodeinfo.diaspora.software/ns/schema/2.0",
|
||||
href: EventosWeb.Endpoint.url() <> "/nodeinfo/2.0.json"
|
||||
}
|
||||
]
|
||||
}
|
||||
|
||||
json(conn, response)
|
||||
end
|
||||
|
||||
# Schema definition: https://github.com/jhass/nodeinfo/blob/master/schemas/2.0/schema.json
|
||||
def nodeinfo(conn, %{"version" => "2.0.json"}) do
|
||||
import Logger
|
||||
Logger.debug(inspect @instance)
|
||||
#stats = Stats.get_stats()
|
||||
|
||||
response = %{
|
||||
version: "2.0",
|
||||
software: %{
|
||||
name: "eventos",
|
||||
version: Keyword.get(@instance, :version)
|
||||
},
|
||||
protocols: ["activitypub"],
|
||||
services: %{
|
||||
inbound: [],
|
||||
outbound: []
|
||||
},
|
||||
openRegistrations: Keyword.get(@instance, :registrations_open),
|
||||
usage: %{
|
||||
users: %{
|
||||
#total: stats.user_count || 0
|
||||
total: Accounts.count_users()
|
||||
},
|
||||
localPosts: Events.count_local_events(),
|
||||
localComments: Events.count_local_comments(),
|
||||
#localPosts: stats.status_count || 0
|
||||
},
|
||||
metadata: %{
|
||||
nodeName: Keyword.get(@instance, :name)
|
||||
}
|
||||
}
|
||||
|
||||
conn
|
||||
|> put_resp_header(
|
||||
"content-type",
|
||||
"application/json; profile=http://nodeinfo.diaspora.software/ns/schema/2.0#; charset=utf-8"
|
||||
)
|
||||
|> json(response)
|
||||
end
|
||||
|
||||
def nodeinfo(conn, _) do
|
||||
conn
|
||||
|> put_status(404)
|
||||
|> json(%{error: "Nodeinfo schema version not handled"})
|
||||
end
|
||||
end
|
||||
11
lib/eventos_web/controllers/outboxes_controller.ex
Normal file
11
lib/eventos_web/controllers/outboxes_controller.ex
Normal file
@@ -0,0 +1,11 @@
|
||||
defmodule EventosWeb.OutboxesController do
|
||||
|
||||
use EventosWeb, :controller
|
||||
|
||||
def show(conn) do
|
||||
account = Guardian.Plug.current_resource(conn).account
|
||||
events = account.events
|
||||
|
||||
render(conn, "index.json", events: events)
|
||||
end
|
||||
end
|
||||
21
lib/eventos_web/controllers/web_finger_controller.ex
Normal file
21
lib/eventos_web/controllers/web_finger_controller.ex
Normal file
@@ -0,0 +1,21 @@
|
||||
defmodule EventosWeb.WebFingerController do
|
||||
use EventosWeb, :controller
|
||||
|
||||
alias Eventos.Service.WebFinger
|
||||
|
||||
def host_meta(conn, _params) do
|
||||
xml = WebFinger.host_meta()
|
||||
|
||||
conn
|
||||
|> put_resp_content_type("application/xrd+xml")
|
||||
|> send_resp(200, xml)
|
||||
end
|
||||
|
||||
def webfinger(conn, %{"resource" => resource}) do
|
||||
with {:ok, response} <- WebFinger.webfinger(resource, "JSON") do
|
||||
json(conn, response)
|
||||
else
|
||||
_e -> send_resp(conn, 404, "Couldn't find user")
|
||||
end
|
||||
end
|
||||
end
|
||||
43
lib/eventos_web/http_signature.ex
Normal file
43
lib/eventos_web/http_signature.ex
Normal file
@@ -0,0 +1,43 @@
|
||||
defmodule EventosWeb.HTTPSignaturePlug do
|
||||
alias Eventos.Service.HTTPSignatures
|
||||
import Plug.Conn
|
||||
require Logger
|
||||
|
||||
def init(options) do
|
||||
options
|
||||
end
|
||||
|
||||
def call(%{assigns: %{valid_signature: true}} = conn, _opts) do
|
||||
conn
|
||||
end
|
||||
|
||||
def call(conn, _opts) do
|
||||
user = conn.params["actor"]
|
||||
Logger.debug("Checking sig for #{user}")
|
||||
with [signature | _] <- get_req_header(conn, "signature") do
|
||||
cond do
|
||||
signature && String.contains?(signature, user) ->
|
||||
conn =
|
||||
conn
|
||||
|> put_req_header(
|
||||
"(request-target)",
|
||||
String.downcase("#{conn.method}") <> " #{conn.request_path}"
|
||||
)
|
||||
|
||||
assign(conn, :valid_signature, HTTPSignatures.validate_conn(conn))
|
||||
|
||||
signature ->
|
||||
Logger.debug("Signature not from actor")
|
||||
assign(conn, :valid_signature, false)
|
||||
|
||||
true ->
|
||||
Logger.debug("No signature header!")
|
||||
conn
|
||||
end
|
||||
else
|
||||
_ ->
|
||||
Logger.debug("No signature header!")
|
||||
conn
|
||||
end
|
||||
end
|
||||
end
|
||||
@@ -8,6 +8,15 @@ defmodule EventosWeb.Router do
|
||||
plug :accepts, ["json"]
|
||||
end
|
||||
|
||||
pipeline :well_known do
|
||||
plug :accepts, ["json/application"]
|
||||
end
|
||||
|
||||
pipeline :activity_pub do
|
||||
plug :accepts, ["activity-json"]
|
||||
plug(EventosWeb.HTTPSignaturePlug)
|
||||
end
|
||||
|
||||
pipeline :api_auth do
|
||||
plug :accepts, ["json"]
|
||||
plug EventosWeb.AuthPipeline
|
||||
@@ -24,43 +33,73 @@ defmodule EventosWeb.Router do
|
||||
scope "/api", EventosWeb do
|
||||
pipe_through :api
|
||||
|
||||
post "/users", UserController, :register
|
||||
post "/login", UserSessionController, :sign_in
|
||||
resources "/groups", GroupController, only: [:index, :show]
|
||||
resources "/events", EventController, only: [:index, :show]
|
||||
get "/events/:id/ics", EventController, :export_to_ics
|
||||
get "/events/:id/tracks", TrackController, :show_tracks_for_event
|
||||
get "/events/:id/sessions", SessionController, :show_sessions_for_event
|
||||
resources "/accounts", AccountController, only: [:index, :show]
|
||||
resources "/tags", TagController, only: [:index, :show]
|
||||
resources "/categories", CategoryController, only: [:index, :show]
|
||||
resources "/sessions", SessionController, only: [:index, :show]
|
||||
resources "/tracks", TrackController, only: [:index, :show]
|
||||
resources "/addresses", AddressController, only: [:index, :show]
|
||||
scope "/v1" do
|
||||
|
||||
post "/users", UserController, :register
|
||||
post "/login", UserSessionController, :sign_in
|
||||
resources "/groups", GroupController, only: [:index, :show]
|
||||
resources "/events", EventController, only: [:index, :show]
|
||||
resources "/comments", CommentController, only: [:show]
|
||||
get "/events/:id/ics", EventController, :export_to_ics
|
||||
get "/events/:id/tracks", TrackController, :show_tracks_for_event
|
||||
get "/events/:id/sessions", SessionController, :show_sessions_for_event
|
||||
resources "/accounts", AccountController, only: [:index, :show]
|
||||
resources "/tags", TagController, only: [:index, :show]
|
||||
resources "/categories", CategoryController, only: [:index, :show]
|
||||
resources "/sessions", SessionController, only: [:index, :show]
|
||||
resources "/tracks", TrackController, only: [:index, :show]
|
||||
resources "/addresses", AddressController, only: [:index, :show]
|
||||
end
|
||||
end
|
||||
|
||||
# Other scopes may use custom stacks.
|
||||
scope "/api", EventosWeb do
|
||||
pipe_through :api_auth
|
||||
|
||||
get "/user", UserController, :show_current_account
|
||||
post "/sign-out", UserSessionController, :sign_out
|
||||
resources "/users", UserController, except: [:new, :edit, :show]
|
||||
resources "/accounts", AccountController, except: [:new, :edit]
|
||||
resources "/events", EventController
|
||||
post "/events/:id/request", EventRequestController, :create_for_event
|
||||
resources "/participants", ParticipantController
|
||||
resources "/requests", EventRequestController
|
||||
resources "/groups", GroupController, except: [:index, :show]
|
||||
post "/groups/:id/request", GroupRequestController, :create_for_group
|
||||
resources "/members", MemberController
|
||||
resources "/requests", GroupRequestController
|
||||
resources "/sessions", SessionController, except: [:index, :show]
|
||||
resources "/tracks", TrackController, except: [:index, :show]
|
||||
get "/tracks/:id/sessions", SessionController, :show_sessions_for_track
|
||||
resources "/categories", CategoryController
|
||||
resources "/tags", TagController
|
||||
resources "/addresses", AddressController, except: [:index, :show]
|
||||
scope "/v1" do
|
||||
|
||||
get "/user", UserController, :show_current_account
|
||||
post "/sign-out", UserSessionController, :sign_out
|
||||
resources "/users", UserController, except: [:new, :edit, :show]
|
||||
resources "/accounts", AccountController, except: [:new, :edit]
|
||||
resources "/events", EventController
|
||||
resources "/comments", CommentController, except: [:new, :edit]
|
||||
post "/events/:id/request", EventRequestController, :create_for_event
|
||||
resources "/participant", ParticipantController
|
||||
resources "/requests", EventRequestController
|
||||
resources "/groups", GroupController, except: [:index, :show]
|
||||
post "/groups/:id/request", GroupRequestController, :create_for_group
|
||||
resources "/members", MemberController
|
||||
resources "/requests", GroupRequestController
|
||||
resources "/sessions", SessionController, except: [:index, :show]
|
||||
resources "/tracks", TrackController, except: [:index, :show]
|
||||
get "/tracks/:id/sessions", SessionController, :show_sessions_for_track
|
||||
resources "/categories", CategoryController
|
||||
resources "/tags", TagController
|
||||
resources "/addresses", AddressController, except: [:index, :show]
|
||||
end
|
||||
end
|
||||
|
||||
scope "/.well-known", EventosWeb do
|
||||
pipe_through :well_known
|
||||
|
||||
get "/host-meta", WebFingerController, :host_meta
|
||||
get "/webfinger", WebFingerController, :webfinger
|
||||
get "/nodeinfo", NodeinfoController, :schemas
|
||||
end
|
||||
|
||||
scope "/nodeinfo", EventosWeb do
|
||||
get("/:version", NodeinfoController, :nodeinfo)
|
||||
end
|
||||
|
||||
scope "/", EventosWeb do
|
||||
pipe_through :activity_pub
|
||||
|
||||
get "/@:username", ActivityPubController, :account
|
||||
get "/@:username/outbox", ActivityPubController, :outbox
|
||||
get "/@:username/:slug", ActivityPubController, :event
|
||||
post "/@:username/inbox", ActivityPubController, :inbox
|
||||
post "/inbox", ActivityPubController, :inbox
|
||||
end
|
||||
|
||||
scope "/", EventosWeb do
|
||||
|
||||
@@ -25,7 +25,6 @@ defmodule EventosWeb.AccountView do
|
||||
description: account.description,
|
||||
# public_key: account.public_key,
|
||||
suspended: account.suspended,
|
||||
uri: account.uri,
|
||||
url: account.url,
|
||||
avatar_url: account.avatar_url,
|
||||
banner_url: account.banner_url,
|
||||
@@ -40,7 +39,6 @@ defmodule EventosWeb.AccountView do
|
||||
description: account.description,
|
||||
# public_key: account.public_key,
|
||||
suspended: account.suspended,
|
||||
uri: account.uri,
|
||||
url: account.url,
|
||||
avatar_url: account.avatar_url,
|
||||
banner_url: account.banner_url,
|
||||
|
||||
117
lib/eventos_web/views/activity_pub/account_view.ex
Normal file
117
lib/eventos_web/views/activity_pub/account_view.ex
Normal file
@@ -0,0 +1,117 @@
|
||||
defmodule EventosWeb.ActivityPub.AccountView do
|
||||
use EventosWeb, :view
|
||||
|
||||
alias EventosWeb.ActivityPub.AccountView
|
||||
alias EventosWeb.ActivityPub.ObjectView
|
||||
alias EventosWeb.WebFinger
|
||||
alias Eventos.Accounts.Account
|
||||
alias Eventos.Repo
|
||||
alias Eventos.Service.ActivityPub
|
||||
alias Eventos.Service.ActivityPub.Transmogrifier
|
||||
alias Eventos.Service.ActivityPub.Utils
|
||||
import Ecto.Query
|
||||
|
||||
def render("account.json", %{account: account}) do
|
||||
{:ok, public_key} = Account.get_public_key_for_account(account)
|
||||
|
||||
%{
|
||||
"id" => account.url,
|
||||
"type" => "Person",
|
||||
#"following" => "#{account.url}/following",
|
||||
#"followers" => "#{account.url}/followers",
|
||||
"inbox" => "#{account.url}/inbox",
|
||||
"outbox" => "#{account.url}/outbox",
|
||||
"preferredUsername" => account.username,
|
||||
"name" => account.display_name,
|
||||
"summary" => account.description,
|
||||
"url" => account.url,
|
||||
#"manuallyApprovesFollowers" => false,
|
||||
"publicKey" => %{
|
||||
"id" => "#{account.url}#main-key",
|
||||
"owner" => account.url,
|
||||
"publicKeyPem" => public_key
|
||||
},
|
||||
"endpoints" => %{
|
||||
"sharedInbox" => "#{EventosWeb.Endpoint.url()}/inbox"
|
||||
},
|
||||
# "icon" => %{
|
||||
# "type" => "Image",
|
||||
# "url" => User.avatar_url(account)
|
||||
# },
|
||||
# "image" => %{
|
||||
# "type" => "Image",
|
||||
# "url" => User.banner_url(account)
|
||||
# }
|
||||
}
|
||||
|> Map.merge(Utils.make_json_ld_header())
|
||||
end
|
||||
|
||||
def render("outbox.json", %{account: account, page: page}) do
|
||||
{page, no_page} = if page == 0 do
|
||||
{1, true}
|
||||
else
|
||||
{page, false}
|
||||
end
|
||||
|
||||
{activities, total} = ActivityPub.fetch_public_activities_for_account(account, page)
|
||||
|
||||
collection =
|
||||
Enum.map(activities, fn act ->
|
||||
{:ok, data} = Transmogrifier.prepare_outgoing(act.data)
|
||||
data
|
||||
end)
|
||||
|
||||
iri = "#{account.url}/outbox"
|
||||
|
||||
page = %{
|
||||
"id" => "#{iri}?page=#{page}",
|
||||
"type" => "OrderedCollectionPage",
|
||||
"partOf" => iri,
|
||||
"totalItems" => total,
|
||||
"orderedItems" => render_many(activities, AccountView, "activity.json", as: :activity),
|
||||
"next" => "#{iri}?page=#{page + 1}"
|
||||
}
|
||||
|
||||
if no_page do
|
||||
%{
|
||||
"id" => iri,
|
||||
"type" => "OrderedCollection",
|
||||
"totalItems" => total,
|
||||
"first" => page
|
||||
}
|
||||
|> Map.merge(Utils.make_json_ld_header())
|
||||
else
|
||||
page |> Map.merge(Utils.make_json_ld_header())
|
||||
end
|
||||
end
|
||||
|
||||
def render("activity.json", %{activity: activity}) do
|
||||
%{
|
||||
"id" => activity.data.url <> "/activity",
|
||||
"type" => "Create",
|
||||
"actor" => activity.data.organizer_account.url,
|
||||
"published" => Timex.now(),
|
||||
"to" => ["https://www.w3.org/ns/activitystreams#Public"],
|
||||
"object" => render_one(activity.data, ObjectView, "event.json", as: :event)
|
||||
}
|
||||
end
|
||||
|
||||
def collection(collection, iri, page, total \\ nil) do
|
||||
offset = (page - 1) * 10
|
||||
items = Enum.slice(collection, offset, 10)
|
||||
items = Enum.map(items, fn user -> user.ap_id end)
|
||||
total = total || length(collection)
|
||||
|
||||
map = %{
|
||||
"id" => "#{iri}?page=#{page}",
|
||||
"type" => "OrderedCollectionPage",
|
||||
"partOf" => iri,
|
||||
"totalItems" => total,
|
||||
"orderedItems" => items
|
||||
}
|
||||
|
||||
if offset < total do
|
||||
Map.put(map, "next", "#{iri}?page=#{page + 1}")
|
||||
end
|
||||
end
|
||||
end
|
||||
37
lib/eventos_web/views/activity_pub/object_view.ex
Normal file
37
lib/eventos_web/views/activity_pub/object_view.ex
Normal file
@@ -0,0 +1,37 @@
|
||||
defmodule EventosWeb.ActivityPub.ObjectView do
|
||||
use EventosWeb, :view
|
||||
alias Eventos.Service.ActivityPub.Transmogrifier
|
||||
@base %{
|
||||
"@context" => [
|
||||
"https://www.w3.org/ns/activitystreams",
|
||||
"https://w3id.org/security/v1",
|
||||
%{
|
||||
"manuallyApprovesFollowers" => "as:manuallyApprovesFollowers",
|
||||
"sensitive" => "as:sensitive",
|
||||
"Hashtag" => "as:Hashtag",
|
||||
"toot" => "http://joinmastodon.org/ns#",
|
||||
"Emoji" => "toot:Emoji"
|
||||
}
|
||||
]
|
||||
}
|
||||
|
||||
def render("event.json", %{event: event}) do
|
||||
|
||||
|
||||
event = %{
|
||||
"type" => "Event",
|
||||
"id" => event.url,
|
||||
"name" => event.title,
|
||||
"category" => %{"title" => event.category.title},
|
||||
"content" => event.description,
|
||||
"mediaType" => "text/markdown",
|
||||
"published" => Timex.format!(event.inserted_at, "{ISO:Extended}"),
|
||||
"updated" => Timex.format!(event.updated_at, "{ISO:Extended}"),
|
||||
}
|
||||
Map.merge(event, @base)
|
||||
end
|
||||
|
||||
def render("category.json", %{category: category}) do
|
||||
category
|
||||
end
|
||||
end
|
||||
18
lib/eventos_web/views/comment_view.ex
Normal file
18
lib/eventos_web/views/comment_view.ex
Normal file
@@ -0,0 +1,18 @@
|
||||
defmodule EventosWeb.CommentView do
|
||||
use EventosWeb, :view
|
||||
alias EventosWeb.CommentView
|
||||
|
||||
def render("index.json", %{comments: comments}) do
|
||||
%{data: render_many(comments, CommentView, "comment.json")}
|
||||
end
|
||||
|
||||
def render("show.json", %{comment: comment}) do
|
||||
%{data: render_one(comment, CommentView, "comment.json")}
|
||||
end
|
||||
|
||||
def render("comment.json", %{comment: comment}) do
|
||||
%{id: comment.id,
|
||||
url: comment.url,
|
||||
text: comment.text}
|
||||
end
|
||||
end
|
||||
@@ -23,7 +23,6 @@ defmodule EventosWeb.GroupView do
|
||||
description: group.description,
|
||||
suspended: group.suspended,
|
||||
url: group.url,
|
||||
uri: group.uri
|
||||
}
|
||||
end
|
||||
|
||||
@@ -33,7 +32,6 @@ defmodule EventosWeb.GroupView do
|
||||
description: group.description,
|
||||
suspended: group.suspended,
|
||||
url: group.url,
|
||||
uri: group.uri,
|
||||
members: render_many(group.members, AccountView, "acccount_basic.json"),
|
||||
events: render_many(group.organized_events, EventView, "event_simple.json")
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user