Add grouped notifications API
This commit is contained in:
parent
093b156c65
commit
1e65c7a69e
9 changed files with 850 additions and 24 deletions
|
|
@ -91,6 +91,79 @@ defmodule Pleroma.Web.ApiSpec.NotificationOperation do
|
|||
}
|
||||
end
|
||||
|
||||
def grouped_index_operation do
|
||||
%Operation{
|
||||
tags: ["Notifications"],
|
||||
summary: "Retrieve grouped notifications",
|
||||
description: "Notifications concerning the user, grouped by supported notification types.",
|
||||
operationId: "NotificationController.grouped_index",
|
||||
security: [%{"oAuth" => ["read:notifications"]}],
|
||||
parameters: grouped_notification_params() ++ pagination_params(),
|
||||
responses: %{
|
||||
200 => Operation.response("Grouped notifications", "application/json", grouped_result()),
|
||||
404 => Operation.response("Error", "application/json", ApiError)
|
||||
}
|
||||
}
|
||||
end
|
||||
|
||||
def show_group_operation do
|
||||
%Operation{
|
||||
tags: ["Notifications"],
|
||||
summary: "Retrieve a notification group",
|
||||
operationId: "NotificationController.show_group",
|
||||
security: [%{"oAuth" => ["read:notifications"]}],
|
||||
parameters: [group_key_param()],
|
||||
responses: %{
|
||||
200 => Operation.response("Grouped notifications", "application/json", grouped_result()),
|
||||
404 => Operation.response("Error", "application/json", ApiError)
|
||||
}
|
||||
}
|
||||
end
|
||||
|
||||
def group_accounts_operation do
|
||||
%Operation{
|
||||
tags: ["Notifications"],
|
||||
summary: "Retrieve notification group accounts",
|
||||
operationId: "NotificationController.group_accounts",
|
||||
security: [%{"oAuth" => ["write:notifications"]}],
|
||||
parameters: [group_key_param()],
|
||||
responses: %{
|
||||
200 =>
|
||||
Operation.response("Accounts", "application/json", %Schema{
|
||||
type: :array,
|
||||
items: Account
|
||||
})
|
||||
}
|
||||
}
|
||||
end
|
||||
|
||||
def unread_count_operation do
|
||||
%Operation{
|
||||
tags: ["Notifications"],
|
||||
summary: "Retrieve unread grouped notification count",
|
||||
operationId: "NotificationController.unread_count",
|
||||
security: [%{"oAuth" => ["read:notifications"]}],
|
||||
parameters:
|
||||
grouped_notification_params() ++
|
||||
[
|
||||
Operation.parameter(
|
||||
:limit,
|
||||
:query,
|
||||
%Schema{type: :integer},
|
||||
"Maximum number of notifications to count"
|
||||
)
|
||||
],
|
||||
responses: %{
|
||||
200 =>
|
||||
Operation.response("Unread notification group count", "application/json", %Schema{
|
||||
type: :object,
|
||||
properties: %{count: %Schema{type: :integer}}
|
||||
}),
|
||||
404 => Operation.response("Error", "application/json", ApiError)
|
||||
}
|
||||
}
|
||||
end
|
||||
|
||||
def clear_operation do
|
||||
%Operation{
|
||||
tags: ["Notifications"],
|
||||
|
|
@ -114,6 +187,18 @@ defmodule Pleroma.Web.ApiSpec.NotificationOperation do
|
|||
}
|
||||
end
|
||||
|
||||
def dismiss_group_operation do
|
||||
%Operation{
|
||||
tags: ["Notifications"],
|
||||
summary: "Dismiss a notification group",
|
||||
description: "Clear all notifications in a notification group from the server.",
|
||||
operationId: "NotificationController.dismiss_group",
|
||||
parameters: [group_key_param()],
|
||||
security: [%{"oAuth" => ["write:notifications"]}],
|
||||
responses: %{200 => empty_object_response()}
|
||||
}
|
||||
end
|
||||
|
||||
def dismiss_via_body_operation do
|
||||
%Operation{
|
||||
tags: ["Notifications"],
|
||||
|
|
@ -194,6 +279,73 @@ defmodule Pleroma.Web.ApiSpec.NotificationOperation do
|
|||
}
|
||||
end
|
||||
|
||||
defp grouped_result do
|
||||
%Schema{
|
||||
title: "GroupedNotificationsResults",
|
||||
type: :object,
|
||||
properties: %{
|
||||
accounts: %Schema{type: :array, items: Account},
|
||||
statuses: %Schema{type: :array, items: Status},
|
||||
notification_groups: %Schema{type: :array, items: notification_group()}
|
||||
},
|
||||
required: [:accounts, :statuses, :notification_groups]
|
||||
}
|
||||
end
|
||||
|
||||
defp notification_group do
|
||||
%Schema{
|
||||
title: "NotificationGroup",
|
||||
type: :object,
|
||||
properties: %{
|
||||
group_key: %Schema{type: :string},
|
||||
notifications_count: %Schema{type: :integer},
|
||||
type: notification_type(),
|
||||
most_recent_notification_id: %Schema{type: :string},
|
||||
page_min_id: %Schema{type: :string, nullable: true},
|
||||
page_max_id: %Schema{type: :string, nullable: true},
|
||||
latest_page_notification_at: %Schema{type: :string, format: :"date-time", nullable: true},
|
||||
sample_account_ids: %Schema{type: :array, items: %Schema{type: :string}},
|
||||
status_id: %Schema{type: :string, nullable: true}
|
||||
},
|
||||
required: [
|
||||
:group_key,
|
||||
:notifications_count,
|
||||
:type,
|
||||
:most_recent_notification_id,
|
||||
:sample_account_ids
|
||||
]
|
||||
}
|
||||
end
|
||||
|
||||
defp grouped_notification_params do
|
||||
[
|
||||
Operation.parameter(
|
||||
:exclude_types,
|
||||
:query,
|
||||
%Schema{type: :array, items: notification_type()},
|
||||
"Array of types to exclude"
|
||||
),
|
||||
Operation.parameter(
|
||||
:account_id,
|
||||
:query,
|
||||
%Schema{type: :string},
|
||||
"Return only notifications received from this account"
|
||||
),
|
||||
Operation.parameter(
|
||||
:types,
|
||||
:query,
|
||||
%Schema{type: :array, items: notification_type()},
|
||||
"Include the notifications for activities with the given types"
|
||||
),
|
||||
Operation.parameter(
|
||||
:grouped_types,
|
||||
:query,
|
||||
%Schema{type: :array, items: notification_type()},
|
||||
"Notification types that may be grouped"
|
||||
)
|
||||
]
|
||||
end
|
||||
|
||||
defp notification_type do
|
||||
%Schema{
|
||||
type: :string,
|
||||
|
|
@ -239,4 +391,11 @@ defmodule Pleroma.Web.ApiSpec.NotificationOperation do
|
|||
required: true
|
||||
)
|
||||
end
|
||||
|
||||
defp group_key_param do
|
||||
Operation.parameter(:group_key, :path, :string, "Notification group key",
|
||||
example: "favourite-123",
|
||||
required: true
|
||||
)
|
||||
end
|
||||
end
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue