summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--models/notification.go8
-rw-r--r--models/notification_test.go9
-rw-r--r--routers/api/v1/notify/repo.go13
-rw-r--r--routers/api/v1/notify/threads.go10
-rw-r--r--routers/api/v1/notify/user.go12
-rw-r--r--routers/web/user/notification.go2
-rw-r--r--templates/swagger/v1_json.tmpl6
7 files changed, 37 insertions, 23 deletions
diff --git a/models/notification.go b/models/notification.go
index 5a35c4d732..fcd0c57dbd 100644
--- a/models/notification.go
+++ b/models/notification.go
@@ -772,20 +772,20 @@ func setRepoNotificationStatusReadIfUnread(e Engine, userID, repoID int64) error
}
// SetNotificationStatus change the notification status
-func SetNotificationStatus(notificationID int64, user *User, status NotificationStatus) error {
+func SetNotificationStatus(notificationID int64, user *User, status NotificationStatus) (*Notification, error) {
notification, err := getNotificationByID(x, notificationID)
if err != nil {
- return err
+ return notification, err
}
if notification.UserID != user.ID {
- return fmt.Errorf("Can't change notification of another user: %d, %d", notification.UserID, user.ID)
+ return nil, fmt.Errorf("Can't change notification of another user: %d, %d", notification.UserID, user.ID)
}
notification.Status = status
_, err = x.ID(notificationID).Update(notification)
- return err
+ return notification, err
}
// GetNotificationByID return notification by ID
diff --git a/models/notification_test.go b/models/notification_test.go
index 07b9f97de5..440b6ed4c6 100644
--- a/models/notification_test.go
+++ b/models/notification_test.go
@@ -76,12 +76,15 @@ func TestSetNotificationStatus(t *testing.T) {
user := AssertExistsAndLoadBean(t, &User{ID: 2}).(*User)
notf := AssertExistsAndLoadBean(t,
&Notification{UserID: user.ID, Status: NotificationStatusRead}).(*Notification)
- assert.NoError(t, SetNotificationStatus(notf.ID, user, NotificationStatusPinned))
+ _, err := SetNotificationStatus(notf.ID, user, NotificationStatusPinned)
+ assert.NoError(t, err)
AssertExistsAndLoadBean(t,
&Notification{ID: notf.ID, Status: NotificationStatusPinned})
- assert.Error(t, SetNotificationStatus(1, user, NotificationStatusRead))
- assert.Error(t, SetNotificationStatus(NonexistentID, user, NotificationStatusRead))
+ _, err = SetNotificationStatus(1, user, NotificationStatusRead)
+ assert.Error(t, err)
+ _, err = SetNotificationStatus(NonexistentID, user, NotificationStatusRead)
+ assert.Error(t, err)
}
func TestUpdateNotificationStatuses(t *testing.T) {
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)
}
diff --git a/routers/web/user/notification.go b/routers/web/user/notification.go
index a444669b74..ec3395cbc1 100644
--- a/routers/web/user/notification.go
+++ b/routers/web/user/notification.go
@@ -160,7 +160,7 @@ func NotificationStatusPost(c *context.Context) {
return
}
- if err := models.SetNotificationStatus(notificationID, c.User, status); err != nil {
+ if _, err := models.SetNotificationStatus(notificationID, c.User, status); err != nil {
c.ServerError("SetNotificationStatus", err)
return
}
diff --git a/templates/swagger/v1_json.tmpl b/templates/swagger/v1_json.tmpl
index e99e092843..9b5f059504 100644
--- a/templates/swagger/v1_json.tmpl
+++ b/templates/swagger/v1_json.tmpl
@@ -739,7 +739,7 @@
],
"responses": {
"205": {
- "$ref": "#/responses/empty"
+ "$ref": "#/responses/NotificationThreadList"
}
}
}
@@ -822,7 +822,7 @@
],
"responses": {
"205": {
- "$ref": "#/responses/empty"
+ "$ref": "#/responses/NotificationThread"
},
"403": {
"$ref": "#/responses/forbidden"
@@ -7058,7 +7058,7 @@
],
"responses": {
"205": {
- "$ref": "#/responses/empty"
+ "$ref": "#/responses/NotificationThreadList"
}
}
}