diff --git a/models/issue.go b/models/issue.go index 850346674b..1421b28da2 100644 --- a/models/issue.go +++ b/models/issue.go @@ -953,6 +953,25 @@ func (issue *Issue) GetTasksDone() int { return len(issueTasksDonePat.FindAllStringIndex(issue.Content, -1)) } +// GetLastEventTimestamp returns the last user visible event timestamp, either the creation of this issue or the close. +func (issue *Issue) GetLastEventTimestamp() util.TimeStamp { + if issue.IsClosed { + return issue.ClosedUnix + } + return issue.CreatedUnix +} + +// GetLastEventLabel returns the localization label for the current issue. +func (issue *Issue) GetLastEventLabel() string { + if issue.IsClosed { + if issue.IsPull && issue.PullRequest.HasMerged { + return "repo.pulls.merged_by" + } + return "repo.issues.closed_by" + } + return "repo.issues.opened_by" +} + // NewIssueOptions represents the options of a new issue. type NewIssueOptions struct { Repo *Repository diff --git a/templates/repo/issue/list.tmpl b/templates/repo/issue/list.tmpl index f42492455c..edf88ebf41 100644 --- a/templates/repo/issue/list.tmpl +++ b/templates/repo/issue/list.tmpl @@ -181,7 +181,6 @@
- {{ $textToTranslate := "repo.issues.opened_by" }} - {{ if not .IsClosed }} - {{ $timeStr = TimeSinceUnix .CreatedUnix $.Lang }} - {{ else if and .IsClosed .IsPull }} - {{ $timeStr = TimeSinceUnix .ClosedUnix $.Lang }} - {{ if .PullRequest.HasMerged }} - {{ $textToTranslate = "repo.pulls.merged_by"}} - {{ else }} - {{ $textToTranslate = "repo.issues.closed_by"}} - {{ end }} - {{ else }} - {{ $timeStr = TimeSinceUnix .ClosedUnix $.Lang }} - {{ $textToTranslate = "repo.issues.closed_by"}} - {{ end }} - - {{$.i18n.Tr $textToTranslate $timeStr .Poster.HomeLink .Poster.Name | Safe}} + {{ $timeStr := TimeSinceUnix .GetLastEventTimestamp $.Lang }} + {{$.i18n.Tr .GetLastEventLabel $timeStr .Poster.HomeLink .Poster.Name | Safe}} {{$tasks := .GetTasks}} {{if gt $tasks 0}}