Merge branch 'remove-conversation-api' into 'develop'
Add API endpoint to remove a conversation Closes #2488 See merge request pleroma/pleroma!3321
This commit is contained in:
commit
158f9f18ee
8 changed files with 76 additions and 9 deletions
|
|
@ -61,9 +61,8 @@ defmodule Pleroma.Conversation do
|
|||
"Create" <- activity.data["type"],
|
||||
%Object{} = object <- Object.normalize(activity, fetch: false),
|
||||
true <- object.data["type"] in ["Note", "Question"],
|
||||
ap_id when is_binary(ap_id) and byte_size(ap_id) > 0 <- object.data["context"] do
|
||||
{:ok, conversation} = create_for_ap_id(ap_id)
|
||||
|
||||
ap_id when is_binary(ap_id) and byte_size(ap_id) > 0 <- object.data["context"],
|
||||
{:ok, conversation} <- create_for_ap_id(ap_id) do
|
||||
users = User.get_users_from_set(activity.recipients, local_only: false)
|
||||
|
||||
participations =
|
||||
|
|
|
|||
|
|
@ -220,4 +220,8 @@ defmodule Pleroma.Conversation.Participation do
|
|||
select: %{count: count(p.id)}
|
||||
)
|
||||
end
|
||||
|
||||
def delete(%__MODULE__{} = participation) do
|
||||
Repo.delete(participation)
|
||||
end
|
||||
end
|
||||
|
|
|
|||
|
|
@ -46,16 +46,31 @@ defmodule Pleroma.Web.ApiSpec.ConversationOperation do
|
|||
tags: ["Conversations"],
|
||||
summary: "Mark conversation as read",
|
||||
operationId: "ConversationController.mark_as_read",
|
||||
parameters: [
|
||||
Operation.parameter(:id, :path, :string, "Conversation ID",
|
||||
example: "123",
|
||||
required: true
|
||||
)
|
||||
],
|
||||
parameters: [id_param()],
|
||||
security: [%{"oAuth" => ["write:conversations"]}],
|
||||
responses: %{
|
||||
200 => Operation.response("Conversation", "application/json", Conversation)
|
||||
}
|
||||
}
|
||||
end
|
||||
|
||||
def delete_operation do
|
||||
%Operation{
|
||||
tags: ["Conversations"],
|
||||
summary: "Remove conversation",
|
||||
operationId: "ConversationController.delete",
|
||||
parameters: [id_param()],
|
||||
security: [%{"oAuth" => ["write:conversations"]}],
|
||||
responses: %{
|
||||
200 => empty_object_response()
|
||||
}
|
||||
}
|
||||
end
|
||||
|
||||
def id_param do
|
||||
Operation.parameter(:id, :path, :string, "Conversation ID",
|
||||
example: "123",
|
||||
required: true
|
||||
)
|
||||
end
|
||||
end
|
||||
|
|
|
|||
|
|
@ -36,4 +36,13 @@ defmodule Pleroma.Web.MastodonAPI.ConversationController do
|
|||
render(conn, "participation.json", participation: participation, for: user)
|
||||
end
|
||||
end
|
||||
|
||||
@doc "DELETE /api/v1/conversations/:id"
|
||||
def delete(%{assigns: %{user: user}} = conn, %{id: participation_id}) do
|
||||
with %Participation{} = participation <-
|
||||
Repo.get_by(Participation, id: participation_id, user_id: user.id),
|
||||
{:ok, _} <- Participation.delete(participation) do
|
||||
json(conn, %{})
|
||||
end
|
||||
end
|
||||
end
|
||||
|
|
|
|||
|
|
@ -443,6 +443,7 @@ defmodule Pleroma.Web.Router do
|
|||
|
||||
get("/conversations", ConversationController, :index)
|
||||
post("/conversations/:id/read", ConversationController, :mark_as_read)
|
||||
delete("/conversations/:id", ConversationController, :delete)
|
||||
|
||||
get("/domain_blocks", DomainBlockController, :index)
|
||||
post("/domain_blocks", DomainBlockController, :create)
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue