mirror of
https://codeberg.org/forgejo/forgejo.git
synced 2025-06-21 09:57:14 -04:00
Add subject-type filter to list notification API endpoints (#16177)
Close #15886
This commit is contained in:
parent
f4d3bf7867
commit
9273601064
5 changed files with 105 additions and 43 deletions
|
@ -6,10 +6,12 @@ package notify
|
|||
|
||||
import (
|
||||
"net/http"
|
||||
"strings"
|
||||
|
||||
"code.gitea.io/gitea/models"
|
||||
"code.gitea.io/gitea/modules/context"
|
||||
api "code.gitea.io/gitea/modules/structs"
|
||||
"code.gitea.io/gitea/routers/api/v1/utils"
|
||||
)
|
||||
|
||||
// NewAvailable check if unread notifications exist
|
||||
|
@ -22,3 +24,44 @@ func NewAvailable(ctx *context.APIContext) {
|
|||
// "$ref": "#/responses/NotificationCount"
|
||||
ctx.JSON(http.StatusOK, api.NotificationCount{New: models.CountUnread(ctx.User)})
|
||||
}
|
||||
|
||||
func getFindNotificationOptions(ctx *context.APIContext) *models.FindNotificationOptions {
|
||||
before, since, err := utils.GetQueryBeforeSince(ctx)
|
||||
if err != nil {
|
||||
ctx.Error(http.StatusUnprocessableEntity, "GetQueryBeforeSince", err)
|
||||
return nil
|
||||
}
|
||||
opts := &models.FindNotificationOptions{
|
||||
ListOptions: utils.GetListOptions(ctx),
|
||||
UserID: ctx.User.ID,
|
||||
UpdatedBeforeUnix: before,
|
||||
UpdatedAfterUnix: since,
|
||||
}
|
||||
if !ctx.QueryBool("all") {
|
||||
statuses := ctx.QueryStrings("status-types")
|
||||
opts.Status = statusStringsToNotificationStatuses(statuses, []string{"unread", "pinned"})
|
||||
}
|
||||
|
||||
subjectTypes := ctx.QueryStrings("subject-type")
|
||||
if len(subjectTypes) != 0 {
|
||||
opts.Source = subjectToSource(subjectTypes)
|
||||
}
|
||||
|
||||
return opts
|
||||
}
|
||||
|
||||
func subjectToSource(value []string) (result []models.NotificationSource) {
|
||||
for _, v := range value {
|
||||
switch strings.ToLower(v) {
|
||||
case "issue":
|
||||
result = append(result, models.NotificationSourceIssue)
|
||||
case "pull":
|
||||
result = append(result, models.NotificationSourcePullRequest)
|
||||
case "commit":
|
||||
result = append(result, models.NotificationSourceCommit)
|
||||
case "repository":
|
||||
result = append(result, models.NotificationSourceRepository)
|
||||
}
|
||||
}
|
||||
return
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue