clacks/lib/clacks_web/controllers/inbox_controller.ex

34 lines
755 B
Elixir

defmodule ClacksWeb.InboxController do
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
Inbox.handle_create(activity)
conn
|> put_status(200)
end
def handle(conn, %{"type" => "Follow", "object" => object} = activity) when is_binary(object) do
Inbox.handle_follow(activity)
conn
|> put_status(200)
end
# def handle(conn, _) do
# # todo: figure out how handle unhandled activity types
# end
end