RepoID int64
IssueID int64
Status []NotificationStatus
+ Source []NotificationSource
UpdatedAfterUnix int64
UpdatedBeforeUnix int64
}
if len(opts.Status) > 0 {
cond = cond.And(builder.In("notification.status", opts.Status))
}
+ if len(opts.Source) > 0 {
+ cond = cond.And(builder.In("notification.source", opts.Source))
+ }
if opts.UpdatedAfterUnix != 0 {
cond = cond.And(builder.Gte{"notification.updated_unix": opts.UpdatedAfterUnix})
}
return sess
}
-func getNotifications(e Engine, options FindNotificationOptions) (nl NotificationList, err error) {
+func getNotifications(e Engine, options *FindNotificationOptions) (nl NotificationList, err error) {
err = options.ToSession(e).OrderBy("notification.updated_unix DESC").Find(&nl)
return
}
// GetNotifications returns all notifications that fit to the given options.
-func GetNotifications(opts FindNotificationOptions) (NotificationList, error) {
+func GetNotifications(opts *FindNotificationOptions) (NotificationList, error) {
return getNotifications(x, opts)
}
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
// "$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
+}
"code.gitea.io/gitea/modules/context"
"code.gitea.io/gitea/modules/convert"
"code.gitea.io/gitea/modules/log"
- "code.gitea.io/gitea/routers/api/v1/utils"
)
func statusStringToNotificationStatus(status string) models.NotificationStatus {
// in: query
// 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"
// collectionFormat: multi
// items:
// type: string
- // required: false
+ // - name: subject-type
+ // in: query
+ // description: "filter notifications by subject type"
+ // type: array
+ // collectionFormat: multi
+ // items:
+ // type: string
+ // enum: [issue,pull,commit,repository]
// - name: since
// in: query
// description: Only show notifications updated after the given time. This is a timestamp in RFC 3339 format
// type: string
// format: date-time
- // required: false
// - name: before
// in: query
// description: Only show notifications updated before the given time. This is a timestamp in RFC 3339 format
// type: string
// format: date-time
- // required: false
// - name: page
// in: query
// description: page number of results to return (1-based)
// responses:
// "200":
// "$ref": "#/responses/NotificationThreadList"
-
- before, since, err := utils.GetQueryBeforeSince(ctx)
- if err != nil {
- ctx.Error(http.StatusUnprocessableEntity, "GetQueryBeforeSince", err)
+ opts := getFindNotificationOptions(ctx)
+ if ctx.Written() {
return
}
- opts := models.FindNotificationOptions{
- ListOptions: utils.GetListOptions(ctx),
- UserID: ctx.User.ID,
- RepoID: ctx.Repo.Repository.ID,
- UpdatedBeforeUnix: before,
- UpdatedAfterUnix: since,
- }
+ opts.RepoID = ctx.Repo.Repository.ID
- if !ctx.QueryBool("all") {
- statuses := ctx.QueryStrings("status-types")
- opts.Status = statusStringsToNotificationStatuses(statuses, []string{"unread", "pinned"})
- }
nl, err := models.GetNotifications(opts)
if err != nil {
ctx.InternalServerError(err)
}
}
- opts := models.FindNotificationOptions{
+ opts := &models.FindNotificationOptions{
UserID: ctx.User.ID,
RepoID: ctx.Repo.Repository.ID,
UpdatedBeforeUnix: lastRead,
"code.gitea.io/gitea/models"
"code.gitea.io/gitea/modules/context"
"code.gitea.io/gitea/modules/convert"
- "code.gitea.io/gitea/routers/api/v1/utils"
)
// ListNotifications list users's notification threads
// in: query
// 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."
// collectionFormat: multi
// items:
// type: string
- // required: false
+ // - name: subject-type
+ // in: query
+ // description: "filter notifications by subject type"
+ // type: array
+ // collectionFormat: multi
+ // items:
+ // type: string
+ // enum: [issue,pull,commit,repository]
// - name: since
// in: query
// description: Only show notifications updated after the given time. This is a timestamp in RFC 3339 format
// type: string
// format: date-time
- // required: false
// - name: before
// in: query
// description: Only show notifications updated before the given time. This is a timestamp in RFC 3339 format
// type: string
// format: date-time
- // required: false
// - name: page
// in: query
// description: page number of results to return (1-based)
// responses:
// "200":
// "$ref": "#/responses/NotificationThreadList"
-
- before, since, err := utils.GetQueryBeforeSince(ctx)
- if err != nil {
- ctx.Error(http.StatusUnprocessableEntity, "GetQueryBeforeSince", err)
+ opts := getFindNotificationOptions(ctx)
+ if ctx.Written() {
return
}
- 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"})
- }
+
nl, err := models.GetNotifications(opts)
if err != nil {
ctx.InternalServerError(err)
lastRead = tmpLastRead.Unix()
}
}
- opts := models.FindNotificationOptions{
+ opts := &models.FindNotificationOptions{
UserID: ctx.User.ID,
UpdatedBeforeUnix: lastRead,
}
"name": "status-types",
"in": "query"
},
+ {
+ "type": "array",
+ "items": {
+ "enum": [
+ "issue",
+ "pull",
+ "commit",
+ "repository"
+ ],
+ "type": "string"
+ },
+ "collectionFormat": "multi",
+ "description": "filter notifications by subject type",
+ "name": "subject-type",
+ "in": "query"
+ },
{
"type": "string",
"format": "date-time",
"name": "status-types",
"in": "query"
},
+ {
+ "type": "array",
+ "items": {
+ "enum": [
+ "issue",
+ "pull",
+ "commit",
+ "repository"
+ ],
+ "type": "string"
+ },
+ "collectionFormat": "multi",
+ "description": "filter notifications by subject type",
+ "name": "subject-type",
+ "in": "query"
+ },
{
"type": "string",
"format": "date-time",