diff options
author | Norwin <noerw@users.noreply.github.com> | 2021-09-18 01:40:50 +0200 |
---|---|---|
committer | GitHub <noreply@github.com> | 2021-09-17 19:40:50 -0400 |
commit | 0ffad31b9285044fc8a2b424a1fe65522cc287d6 (patch) | |
tree | b4d183480410296505ddcae1da722b6728bdc0a3 /routers/api/v1/notify | |
parent | ba2e600d17bab8870f4ab33eb5816dff19a060c3 (diff) | |
download | gitea-0ffad31b9285044fc8a2b424a1fe65522cc287d6.tar.gz gitea-0ffad31b9285044fc8a2b424a1fe65522cc287d6.zip |
Notifications API: respond with updated notifications (#17064)
* notifications api: return updated notifications in response
* make generate-swagger
* openapi fix
Co-authored-by: zeripath <art27@cantab.net>
Diffstat (limited to 'routers/api/v1/notify')
-rw-r--r-- | routers/api/v1/notify/repo.go | 13 | ||||
-rw-r--r-- | routers/api/v1/notify/threads.go | 10 | ||||
-rw-r--r-- | routers/api/v1/notify/user.go | 12 |
3 files changed, 23 insertions, 12 deletions
diff --git a/routers/api/v1/notify/repo.go b/routers/api/v1/notify/repo.go index 1a36642b6a..382d221b85 100644 --- a/routers/api/v1/notify/repo.go +++ b/routers/api/v1/notify/repo.go @@ -13,6 +13,7 @@ import ( "code.gitea.io/gitea/modules/context" "code.gitea.io/gitea/modules/convert" "code.gitea.io/gitea/modules/log" + "code.gitea.io/gitea/modules/structs" ) func statusStringToNotificationStatus(status string) models.NotificationStatus { @@ -176,7 +177,7 @@ func ReadRepoNotifications(ctx *context.APIContext) { // required: false // responses: // "205": - // "$ref": "#/responses/empty" + // "$ref": "#/responses/NotificationThreadList" lastRead := int64(0) qLastRead := ctx.FormTrim("last_read_at") @@ -213,14 +214,16 @@ func ReadRepoNotifications(ctx *context.APIContext) { targetStatus = models.NotificationStatusRead } + changed := make([]*structs.NotificationThread, len(nl)) + for _, n := range nl { - err := models.SetNotificationStatus(n.ID, ctx.User, targetStatus) + notif, err := models.SetNotificationStatus(n.ID, ctx.User, targetStatus) if err != nil { ctx.InternalServerError(err) return } - ctx.Status(http.StatusResetContent) + _ = notif.LoadAttributes() + changed = append(changed, convert.ToNotificationThread(notif)) } - - ctx.Status(http.StatusResetContent) + ctx.JSON(http.StatusResetContent, changed) } diff --git a/routers/api/v1/notify/threads.go b/routers/api/v1/notify/threads.go index 1774c0b412..2e241080b4 100644 --- a/routers/api/v1/notify/threads.go +++ b/routers/api/v1/notify/threads.go @@ -71,7 +71,7 @@ func ReadThread(ctx *context.APIContext) { // required: false // responses: // "205": - // "$ref": "#/responses/empty" + // "$ref": "#/responses/NotificationThread" // "403": // "$ref": "#/responses/forbidden" // "404": @@ -87,12 +87,16 @@ func ReadThread(ctx *context.APIContext) { targetStatus = models.NotificationStatusRead } - err := models.SetNotificationStatus(n.ID, ctx.User, targetStatus) + notif, err := models.SetNotificationStatus(n.ID, ctx.User, targetStatus) if err != nil { ctx.InternalServerError(err) return } - ctx.Status(http.StatusResetContent) + if err = notif.LoadAttributes(); err != nil { + ctx.InternalServerError(err) + return + } + ctx.JSON(http.StatusResetContent, convert.ToNotificationThread(notif)) } func getThread(ctx *context.APIContext) *models.Notification { diff --git a/routers/api/v1/notify/user.go b/routers/api/v1/notify/user.go index e4626cb719..6e4c19d1bf 100644 --- a/routers/api/v1/notify/user.go +++ b/routers/api/v1/notify/user.go @@ -11,6 +11,7 @@ import ( "code.gitea.io/gitea/models" "code.gitea.io/gitea/modules/context" "code.gitea.io/gitea/modules/convert" + "code.gitea.io/gitea/modules/structs" ) // ListNotifications list users's notification threads @@ -125,7 +126,7 @@ func ReadNotifications(ctx *context.APIContext) { // required: false // responses: // "205": - // "$ref": "#/responses/empty" + // "$ref": "#/responses/NotificationThreadList" lastRead := int64(0) qLastRead := ctx.FormTrim("last_read_at") @@ -158,14 +159,17 @@ func ReadNotifications(ctx *context.APIContext) { targetStatus = models.NotificationStatusRead } + changed := make([]*structs.NotificationThread, 0, len(nl)) + for _, n := range nl { - err := models.SetNotificationStatus(n.ID, ctx.User, targetStatus) + notif, err := models.SetNotificationStatus(n.ID, ctx.User, targetStatus) if err != nil { ctx.InternalServerError(err) return } - ctx.Status(http.StatusResetContent) + _ = notif.LoadAttributes() + changed = append(changed, convert.ToNotificationThread(notif)) } - ctx.Status(http.StatusResetContent) + ctx.JSON(http.StatusResetContent, changed) } |