diff --git a/models/activities/notification.go b/models/activities/notification.go index 2ca1051ed3e..4537e8cd153 100644 --- a/models/activities/notification.go +++ b/models/activities/notification.go @@ -6,6 +6,7 @@ package activities import ( "context" "fmt" + "html/template" "net/url" "strconv" @@ -16,6 +17,7 @@ import ( "code.gitea.io/gitea/modules/git" "code.gitea.io/gitea/modules/gitrepo" "code.gitea.io/gitea/modules/setting" + "code.gitea.io/gitea/modules/svg" "code.gitea.io/gitea/modules/timeutil" "xorm.io/builder" @@ -379,6 +381,22 @@ func (n *Notification) Link(ctx context.Context) string { return "" } +func (n *Notification) IconHTML(ctx context.Context) template.HTML { + switch n.Source { + case NotificationSourceIssue, NotificationSourcePullRequest: + // n.Issue should be loaded before calling this method + return n.Issue.IconHTML(ctx) + case NotificationSourceCommit: + return svg.RenderHTML("octicon-commit", 16, "text grey") + case NotificationSourceRepository: + return svg.RenderHTML("octicon-repo", 16, "text grey") + case NotificationSourceRelease: + return svg.RenderHTML("octicon-tag", 16, "text grey") + default: + return "" + } +} + // APIURL formats a URL-string to the notification func (n *Notification) APIURL() string { return setting.AppURL + "api/v1/notifications/threads/" + strconv.FormatInt(n.ID, 10) diff --git a/models/issues/issue.go b/models/issues/issue.go index a86d50ca9da..bb6d17d334b 100644 --- a/models/issues/issue.go +++ b/models/issues/issue.go @@ -21,6 +21,7 @@ import ( "code.gitea.io/gitea/modules/optional" "code.gitea.io/gitea/modules/setting" api "code.gitea.io/gitea/modules/structs" + "code.gitea.io/gitea/modules/svg" "code.gitea.io/gitea/modules/timeutil" "code.gitea.io/gitea/modules/util" @@ -442,6 +443,30 @@ func (issue *Issue) PatchURL() string { return "" } +/* the logic should be kept the same as getIssueIcon/getIssueColor in TS code */ +func (issue *Issue) IconHTML(ctx context.Context) template.HTML { + if issue.IsPull { + if issue.PullRequest == nil { // pull request should be loaded before calling this function + return template.HTML("No PullRequest") + } + if issue.IsClosed { + if issue.PullRequest.HasMerged { + return svg.RenderHTML("octicon-git-merge", 16, "text purple") + } + return svg.RenderHTML("octicon-git-pull-request-closed", 16, "text red") + } + if issue.PullRequest.IsWorkInProgress(ctx) { + return svg.RenderHTML("octicon-git-pull-request-draft", 16, "text grey") + } + return svg.RenderHTML("octicon-git-pull-request", 16, "text green") + } + + if issue.IsClosed { + return svg.RenderHTML("octicon-issue-closed", 16, "text red") + } + return svg.RenderHTML("octicon-issue-opened", 16, "text green") +} + // State returns string representation of issue status. func (issue *Issue) State() api.StateType { if issue.IsClosed { diff --git a/services/markup/renderhelper_issueicontitle.go b/services/markup/renderhelper_issueicontitle.go index 27b5595fa99..dd5049a4cf6 100644 --- a/services/markup/renderhelper_issueicontitle.go +++ b/services/markup/renderhelper_issueicontitle.go @@ -58,10 +58,6 @@ func renderRepoIssueIconTitle(ctx context.Context, opts markup.RenderIssueIconTi } } - htmlIcon, err := webCtx.RenderToHTML("shared/issueicon", issue) - if err != nil { - return "", err - } - - return htmlutil.HTMLFormat(`%s %s %s`, opts.LinkHref, htmlIcon, issue.Title, textIssueIndex), nil + return htmlutil.HTMLFormat(`%s %s %s`, opts.LinkHref, + issue.IconHTML(ctx), issue.Title, textIssueIndex), nil } diff --git a/templates/repo/diff/compare.tmpl b/templates/repo/diff/compare.tmpl index 4e8ad1326c0..24cf537c055 100644 --- a/templates/repo/diff/compare.tmpl +++ b/templates/repo/diff/compare.tmpl @@ -187,7 +187,7 @@ {{end}} {{if .HasPullRequest}}