[feature] Add support for the exclude_types[] parameter on the notifications endpoint (#784)

* Add support for the exclude_types[] parameter on the notifications endpoint

* Add swagger docs to notifications
This commit is contained in:
Blackle Morisanchetto
2022-08-31 13:20:52 -04:00
committed by GitHub
parent f01492ae48
commit ecb97f4e0b
11 changed files with 172 additions and 12 deletions

View File

@@ -29,7 +29,70 @@ import (
"github.com/superseriousbusiness/gotosocial/internal/oauth"
)
// NotificationsGETHandler serves a list of notifications to the caller, with the desired query parameters
// NotificationsGETHandler swagger:operation GET /api/v1/notifications notifications
//
// Get notifications for currently authorized user.
//
// The notifications will be returned in descending chronological order (newest first), with sequential IDs (bigger = newer).
//
// ---
// tags:
// - notifications
//
// produces:
// - application/json
//
// parameters:
// - name: limit
// type: integer
// description: Number of notifications to return.
// default: 20
// in: query
// required: false
// - name: exclude_types
// type: array
// items:
// type: string
// description: Array of types of notifications to exclude (follow, favourite, reblog, mention, poll, follow_request)
// in: query
// required: false
// - name: max_id
// type: string
// description: |-
// Return only notifications *OLDER* than the given max status ID.
// The status with the specified ID will not be included in the response.
// in: query
// required: false
// - name: since_id
// type: string
// description: |-
// Return only notifications *NEWER* than the given since status ID.
// The status with the specified ID will not be included in the response.
// in: query
// required: false
//
// security:
// - OAuth2 Bearer:
// - read:notifications
//
// responses:
// '200':
// name: notifications
// description: Array of notifications.
// schema:
// type: array
// items:
// "$ref": "#/definitions/notification"
// '400':
// description: bad request
// '401':
// description: unauthorized
// '404':
// description: not found
// '406':
// description: not acceptable
// '500':
// description: internal server error
func (m *Module) NotificationsGETHandler(c *gin.Context) {
authed, err := oauth.Authed(c, true, true, true, true)
if err != nil {
@@ -66,7 +129,9 @@ func (m *Module) NotificationsGETHandler(c *gin.Context) {
sinceID = sinceIDString
}
resp, errWithCode := m.processor.NotificationsGet(c.Request.Context(), authed, limit, maxID, sinceID)
excludeTypes := c.QueryArray(ExcludeTypesKey)
resp, errWithCode := m.processor.NotificationsGet(c.Request.Context(), authed, excludeTypes, limit, maxID, sinceID)
if errWithCode != nil {
api.ErrorHandler(c, errWithCode, m.processor.InstanceGet)
return