Backport #12164 This PR extends the notifications API to allow specific notification statuses to be searched for and to allow setting of notifications to statuses other than read. By default unread and pinned statuses will be returned when querying for notifications - however pinned statuses will not be marked as read. Close #12152 Signed-off-by: Andrew Thornton art27@cantab.net
This commit is contained in:
parent
5e62137fe3
commit
489e9162fc
7 changed files with 206 additions and 24 deletions
|
@ -29,6 +29,14 @@ func ListNotifications(ctx *context.APIContext) {
|
|||
// description: If true, show notifications marked as read. Default value is false
|
||||
// type: string
|
||||
// required: false
|
||||
// - name: status-types
|
||||
// in: query
|
||||
// description: "Show notifications with the provided status types. Options are: unread, read and/or pinned. Defaults to unread & pinned."
|
||||
// type: array
|
||||
// collectionFormat: multi
|
||||
// items:
|
||||
// type: string
|
||||
// required: false
|
||||
// - name: since
|
||||
// in: query
|
||||
// description: Only show notifications updated after the given time. This is a timestamp in RFC 3339 format
|
||||
|
@ -64,9 +72,9 @@ func ListNotifications(ctx *context.APIContext) {
|
|||
UpdatedBeforeUnix: before,
|
||||
UpdatedAfterUnix: since,
|
||||
}
|
||||
qAll := strings.Trim(ctx.Query("all"), " ")
|
||||
if qAll != "true" {
|
||||
opts.Status = models.NotificationStatusUnread
|
||||
if !ctx.QueryBool("all") {
|
||||
statuses := ctx.QueryStrings("status-types")
|
||||
opts.Status = statusStringsToNotificationStatuses(statuses, []string{"unread", "pinned"})
|
||||
}
|
||||
nl, err := models.GetNotifications(opts)
|
||||
if err != nil {
|
||||
|
@ -82,11 +90,11 @@ func ListNotifications(ctx *context.APIContext) {
|
|||
ctx.JSON(http.StatusOK, nl.APIFormat())
|
||||
}
|
||||
|
||||
// ReadNotifications mark notification threads as read
|
||||
// ReadNotifications mark notification threads as read, unread, or pinned
|
||||
func ReadNotifications(ctx *context.APIContext) {
|
||||
// swagger:operation PUT /notifications notification notifyReadList
|
||||
// ---
|
||||
// summary: Mark notification threads as read
|
||||
// summary: Mark notification threads as read, pinned or unread
|
||||
// consumes:
|
||||
// - application/json
|
||||
// produces:
|
||||
|
@ -98,6 +106,24 @@ func ReadNotifications(ctx *context.APIContext) {
|
|||
// type: string
|
||||
// format: date-time
|
||||
// required: false
|
||||
// - name: all
|
||||
// in: query
|
||||
// description: If true, mark all notifications on this repo. Default value is false
|
||||
// type: string
|
||||
// required: false
|
||||
// - name: status-types
|
||||
// in: query
|
||||
// description: "Mark notifications with the provided status types. Options are: unread, read and/or pinned. Defaults to unread."
|
||||
// type: array
|
||||
// collectionFormat: multi
|
||||
// items:
|
||||
// type: string
|
||||
// required: false
|
||||
// - name: to-status
|
||||
// in: query
|
||||
// description: Status to mark notifications as, Defaults to read.
|
||||
// type: string
|
||||
// required: false
|
||||
// responses:
|
||||
// "205":
|
||||
// "$ref": "#/responses/empty"
|
||||
|
@ -117,7 +143,10 @@ func ReadNotifications(ctx *context.APIContext) {
|
|||
opts := models.FindNotificationOptions{
|
||||
UserID: ctx.User.ID,
|
||||
UpdatedBeforeUnix: lastRead,
|
||||
Status: models.NotificationStatusUnread,
|
||||
}
|
||||
if !ctx.QueryBool("all") {
|
||||
statuses := ctx.QueryStrings("status-types")
|
||||
opts.Status = statusStringsToNotificationStatuses(statuses, []string{"unread"})
|
||||
}
|
||||
nl, err := models.GetNotifications(opts)
|
||||
if err != nil {
|
||||
|
@ -125,8 +154,13 @@ func ReadNotifications(ctx *context.APIContext) {
|
|||
return
|
||||
}
|
||||
|
||||
targetStatus := statusStringToNotificationStatus(ctx.Query("to-status"))
|
||||
if targetStatus == 0 {
|
||||
targetStatus = models.NotificationStatusRead
|
||||
}
|
||||
|
||||
for _, n := range nl {
|
||||
err := models.SetNotificationStatus(n.ID, ctx.User, models.NotificationStatusRead)
|
||||
err := models.SetNotificationStatus(n.ID, ctx.User, targetStatus)
|
||||
if err != nil {
|
||||
ctx.InternalServerError(err)
|
||||
return
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue