Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Introduce NotifySubjectType #16320

Merged
merged 3 commits into from
Jul 1, 2021
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 4 additions & 4 deletions modules/convert/notification.go
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ func ToNotificationThread(n *models.Notification) *api.NotificationThread {
//handle Subject
switch n.Source {
case models.NotificationSourceIssue:
result.Subject = &api.NotificationSubject{Type: "Issue"}
result.Subject = &api.NotificationSubject{Type: api.NotifySubjectIssue}
if n.Issue != nil {
result.Subject.Title = n.Issue.Title
result.Subject.URL = n.Issue.APIURL()
Expand All @@ -38,7 +38,7 @@ func ToNotificationThread(n *models.Notification) *api.NotificationThread {
}
}
case models.NotificationSourcePullRequest:
result.Subject = &api.NotificationSubject{Type: "Pull"}
result.Subject = &api.NotificationSubject{Type: api.NotifySubjectPull}
if n.Issue != nil {
result.Subject.Title = n.Issue.Title
result.Subject.URL = n.Issue.APIURL()
Expand All @@ -55,13 +55,13 @@ func ToNotificationThread(n *models.Notification) *api.NotificationThread {
}
case models.NotificationSourceCommit:
result.Subject = &api.NotificationSubject{
Type: "Commit",
Type: api.NotifySubjectCommit,
Title: n.CommitID,
URL: n.Repository.HTMLURL() + "/commit/" + n.CommitID,
}
case models.NotificationSourceRepository:
result.Subject = &api.NotificationSubject{
Type: "Repository",
Type: api.NotifySubjectRepository,
Title: n.Repository.FullName(),
URL: n.Repository.Link(),
}
Expand Down
24 changes: 19 additions & 5 deletions modules/structs/notifications.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,14 +21,28 @@ type NotificationThread struct {

// NotificationSubject contains the notification subject (Issue/Pull/Commit)
type NotificationSubject struct {
Title string `json:"title"`
URL string `json:"url"`
LatestCommentURL string `json:"latest_comment_url"`
Type string `json:"type" binding:"In(Issue,Pull,Commit)"`
State StateType `json:"state"`
Title string `json:"title"`
URL string `json:"url"`
LatestCommentURL string `json:"latest_comment_url"`
Type NotifySubjectType `json:"type"`
6543 marked this conversation as resolved.
Show resolved Hide resolved
State StateType `json:"state"`
}

// NotificationCount number of unread notifications
type NotificationCount struct {
New int64 `json:"new"`
}

// NotifySubjectType represent type of notification subject
type NotifySubjectType string

const (
// NotifySubjectIssue an issue is subject of an notification
NotifySubjectIssue NotifySubjectType = "Issue"
// NotifySubjectPull an pull is subject of an notification
NotifySubjectPull NotifySubjectType = "Pull"
// NotifySubjectCommit an commit is subject of an notification
NotifySubjectCommit NotifySubjectType = "Commit"
// NotifySubjectRepository an repository is subject of an notification
NotifySubjectRepository NotifySubjectType = "Repository"
)