summaryrefslogtreecommitdiffstats
path: root/services
diff options
context:
space:
mode:
authorJimmy Praet <jimmy.praet@telenet.be>2021-11-22 13:20:16 +0100
committerGitHub <noreply@github.com>2021-11-22 20:20:16 +0800
commita3efd048a7770aff898096df55eda76e80a4972e (patch)
treeaea86e365fed219016a2d2e106572fde6a5b7e84 /services
parent49b2cb998b6ebaf98e89dd9dba8ba9d46d2fd82c (diff)
downloadgitea-a3efd048a7770aff898096df55eda76e80a4972e.tar.gz
gitea-a3efd048a7770aff898096df55eda76e80a4972e.zip
Improvements to content history (#17746)
* Improvements to content history * initialize content history when making an edit to an old item created before the introduction of content history * show edit history for code comments on pull request files tab * Fix a flaw in keepLimitedContentHistory Fix a flaw in keepLimitedContentHistory, the first and the last should never be deleted * Remove obsolete eager initialization of content history
Diffstat (limited to 'services')
-rw-r--r--services/comments/comments.go21
1 files changed, 16 insertions, 5 deletions
diff --git a/services/comments/comments.go b/services/comments/comments.go
index d1e5ea4d88..2477f2d2b0 100644
--- a/services/comments/comments.go
+++ b/services/comments/comments.go
@@ -25,10 +25,6 @@ func CreateIssueComment(doer *models.User, repo *models.Repository, issue *model
if err != nil {
return nil, err
}
- err = issues.SaveIssueContentHistory(db.GetEngine(db.DefaultContext), doer.ID, issue.ID, comment.ID, timeutil.TimeStampNow(), comment.Content, true)
- if err != nil {
- return nil, err
- }
mentions, err := issue.FindAndUpdateIssueMentions(db.DefaultContext, doer, comment.Content)
if err != nil {
@@ -42,11 +38,26 @@ func CreateIssueComment(doer *models.User, repo *models.Repository, issue *model
// UpdateComment updates information of comment.
func UpdateComment(c *models.Comment, doer *models.User, oldContent string) error {
+ var needsContentHistory = c.Content != oldContent &&
+ (c.Type == models.CommentTypeComment || c.Type == models.CommentTypeReview || c.Type == models.CommentTypeCode)
+ if needsContentHistory {
+ hasContentHistory, err := issues.HasIssueContentHistory(db.DefaultContext, c.IssueID, c.ID)
+ if err != nil {
+ return err
+ }
+ if !hasContentHistory {
+ if err = issues.SaveIssueContentHistory(db.GetEngine(db.DefaultContext), c.PosterID, c.IssueID, c.ID,
+ c.CreatedUnix, oldContent, true); err != nil {
+ return err
+ }
+ }
+ }
+
if err := models.UpdateComment(c, doer); err != nil {
return err
}
- if c.Type == models.CommentTypeComment && c.Content != oldContent {
+ if needsContentHistory {
err := issues.SaveIssueContentHistory(db.GetEngine(db.DefaultContext), doer.ID, c.IssueID, c.ID, timeutil.TimeStampNow(), c.Content, false)
if err != nil {
return err