externalize MaskComment
This commit is contained in:
+1
-4
@@ -120,11 +120,8 @@ func (a *admin) maskBlockedUsers(comments []store.Comment) (res []store.Comment)
|
||||
res = make([]store.Comment, len(comments))
|
||||
for i, c := range comments {
|
||||
if a.dataService.IsBlocked(c.Locator.SiteID, c.User.ID) {
|
||||
c = store.MaskComment(c)
|
||||
c.User.Blocked = true
|
||||
c.Text = "this comment was deleted"
|
||||
c.Score = 0
|
||||
c.Votes = map[string]bool{}
|
||||
c.Edit = nil
|
||||
}
|
||||
res[i] = c
|
||||
}
|
||||
|
||||
+1
-4
@@ -142,11 +142,8 @@ func (b *BoltDB) Delete(locator Locator, commentID string) error {
|
||||
return errors.Wrapf(err, "can't load key %s from bucket %s", commentID, locator.URL)
|
||||
}
|
||||
// set deleted status and clear fields
|
||||
comment = MaskComment(comment)
|
||||
comment.Deleted = true
|
||||
comment.Text = "this comment was deleted"
|
||||
comment.Score = 0
|
||||
comment.Votes = map[string]bool{}
|
||||
comment.Edit = nil
|
||||
|
||||
if err := b.save(bucket, []byte(commentID), comment); err != nil {
|
||||
return errors.Wrapf(err, "can't save deleted comment for key %s from bucket %s", commentID, locator.URL)
|
||||
|
||||
@@ -133,3 +133,12 @@ func sortComments(comments []Comment, sortFld string) []Comment {
|
||||
})
|
||||
return comments
|
||||
}
|
||||
|
||||
// MaskComment clears comment info, reset to "Deleted/Blocked"
|
||||
func MaskComment(comment Comment) Comment {
|
||||
comment.Text = "this comment was deleted"
|
||||
comment.Score = 0
|
||||
comment.Votes = map[string]bool{}
|
||||
comment.Edit = nil
|
||||
return comment
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user