51 lines
1.1 KiB
Elixir
51 lines
1.1 KiB
Elixir
defmodule ClacksWeb.InboxController do
|
|
require Logger
|
|
use ClacksWeb, :controller
|
|
alias Clacks.Inbox
|
|
|
|
plug Plug.Parsers, parsers: [:urlencoded, :json], json_decoder: Jason
|
|
plug ClacksWeb.Plug.HTTPSignature
|
|
|
|
def shared(conn, _params) do
|
|
handle(conn, conn.body_params)
|
|
end
|
|
|
|
def user_specific(conn, _params) do
|
|
handle(conn, conn.body_params)
|
|
end
|
|
|
|
def handle(conn, %{"type" => "Create"} = activity) do
|
|
case Inbox.handle_create(activity) do
|
|
:ok ->
|
|
conn
|
|
|> put_status(200)
|
|
|
|
{:error, reason} ->
|
|
Logger.error("Could not handle incoming Create: #{inspect(reason)}")
|
|
|
|
conn
|
|
|> put_status(500)
|
|
end
|
|
|> json(%{})
|
|
end
|
|
|
|
def handle(conn, %{"type" => "Follow", "object" => object} = activity) when is_binary(object) do
|
|
case Inbox.handle_follow(activity) do
|
|
:ok ->
|
|
conn
|
|
|> put_status(200)
|
|
|
|
{:error, reason} ->
|
|
Logger.error("Could not handle incoming follow: #{inspect(reason)}")
|
|
|
|
conn
|
|
|> put_status(500)
|
|
end
|
|
|> json(%{})
|
|
end
|
|
|
|
# def handle(conn, _) do
|
|
# # todo: figure out how handle unhandled activity types
|
|
# end
|
|
end
|