summaryrefslogtreecommitdiffstats
path: root/models/issue_comment.go
diff options
context:
space:
mode:
authorUnknwon <u@gogs.io>2016-08-26 13:40:53 -0700
committerUnknwon <u@gogs.io>2016-08-26 13:40:53 -0700
commit6b98d58906e4df063a2af59f97bd74c1c4cc1c84 (patch)
tree55ee0ed0cf2ce7984f3e724ba6a8675ece4771c1 /models/issue_comment.go
parent8dca9f95fab909c52cd34fb401f171d22f0065ae (diff)
downloadgitea-6b98d58906e4df063a2af59f97bd74c1c4cc1c84.tar.gz
gitea-6b98d58906e4df063a2af59f97bd74c1c4cc1c84.zip
#2966 code cleanup
Diffstat (limited to 'models/issue_comment.go')
-rw-r--r--models/issue_comment.go46
1 files changed, 37 insertions, 9 deletions
diff --git a/models/issue_comment.go b/models/issue_comment.go
index 8abc063328..c914e0a56f 100644
--- a/models/issue_comment.go
+++ b/models/issue_comment.go
@@ -11,6 +11,7 @@ import (
"github.com/Unknwon/com"
"github.com/go-xorm/xorm"
+
api "github.com/gogits/go-gogs-client"
"github.com/gogits/gogs/modules/log"
@@ -59,6 +60,8 @@ type Comment struct {
Created time.Time `xorm:"-"`
CreatedUnix int64
+ Updated time.Time `xorm:"-"`
+ UpdatedUnix int64
// Reference issue in commit message
CommitSHA string `xorm:"VARCHAR(40)"`
@@ -71,6 +74,11 @@ type Comment struct {
func (c *Comment) BeforeInsert() {
c.CreatedUnix = time.Now().Unix()
+ c.UpdatedUnix = c.CreatedUnix
+}
+
+func (c *Comment) BeforeUpdate() {
+ c.UpdatedUnix = time.Now().Unix()
}
func (c *Comment) AfterSet(colName string, _ xorm.Cell) {
@@ -94,6 +102,8 @@ func (c *Comment) AfterSet(colName string, _ xorm.Cell) {
}
case "created_unix":
c.Created = time.Unix(c.CreatedUnix, 0).Local()
+ case "updated_unix":
+ c.Updated = time.Unix(c.UpdatedUnix, 0).Local()
}
}
@@ -105,16 +115,14 @@ func (c *Comment) AfterDelete() {
}
}
-// APIFormat convert Comment struct to api.Comment struct
func (c *Comment) APIFormat() *api.Comment {
- apiComment := &api.Comment{
+ return &api.Comment{
ID: c.ID,
Poster: c.Poster.APIFormat(),
Body: c.Content,
Created: c.Created,
+ Updated: c.Updated,
}
-
- return apiComment
}
// HashTag returns unique hash tag for comment.
@@ -341,15 +349,32 @@ func GetCommentByID(id int64) (*Comment, error) {
if err != nil {
return nil, err
} else if !has {
- return nil, ErrCommentNotExist{id}
+ return nil, ErrCommentNotExist{id, 0}
}
return c, nil
}
-// GetCommentsByIssueID returns all comments of issue by given ID.
-func GetCommentsByIssueID(issueID int64) ([]*Comment, error) {
+func getCommentsByIssueIDSince(e Engine, issueID, since int64) ([]*Comment, error) {
comments := make([]*Comment, 0, 10)
- return comments, x.Where("issue_id=?", issueID).Asc("created_unix").Find(&comments)
+ sess := e.Where("issue_id = ?", issueID).Asc("created_unix")
+ if since > 0 {
+ sess.And("created_unix >= ?", since)
+ }
+ return comments, sess.Find(&comments)
+}
+
+func getCommentsByIssueID(e Engine, issueID int64) ([]*Comment, error) {
+ return getCommentsByIssueIDSince(e, issueID, -1)
+}
+
+// GetCommentsByIssueID returns all comments of an issue.
+func GetCommentsByIssueID(issueID int64) ([]*Comment, error) {
+ return getCommentsByIssueID(x, issueID)
+}
+
+// GetCommentsByIssueID returns a list of comments of an issue since a given time point.
+func GetCommentsByIssueIDSince(issueID, since int64) ([]*Comment, error) {
+ return getCommentsByIssueIDSince(x, issueID, since)
}
// UpdateComment updates information of comment.
@@ -358,10 +383,13 @@ func UpdateComment(c *Comment) error {
return err
}
-// DeleteCommentByID deletes a comment by given ID.
+// DeleteCommentByID deletes the comment by given ID.
func DeleteCommentByID(id int64) error {
comment, err := GetCommentByID(id)
if err != nil {
+ if IsErrCommentNotExist(err) {
+ return nil
+ }
return err
}