alias Pleroma.Object
alias Pleroma.Repo
alias Pleroma.User
+ alias Pleroma.Plugs.OAuthScopesPlug
alias Pleroma.Web.CommonAPI
alias Pleroma.Web.PleromaAPI.ChatView
alias Pleroma.Web.PleromaAPI.ChatMessageView
import Ecto.Query
# TODO
- # - Oauth stuff
- # - Views / Representers
# - Error handling
+ plug(
+ OAuthScopesPlug,
+ %{scopes: ["write:statuses"]} when action in [:post_chat_message, :create]
+ )
+
+ plug(
+ OAuthScopesPlug,
+ %{scopes: ["read:statuses"]} when action in [:messages, :index]
+ )
+
defdelegate open_api_operation(action), to: Pleroma.Web.ApiSpec.ChatOperation
def post_chat_message(%{assigns: %{user: %{id: user_id} = user}} = conn, %{
conn
|> put_view(ChatMessageView)
|> render("index.json", for: user, objects: messages, chat: chat)
+ else
+ _ ->
+ conn
+ |> put_status(:not_found)
+ |> json(%{error: "not found"})
end
end