externalize MaskComment

This commit is contained in:
Umputun
2018-02-04 18:54:06 -06:00
parent 3aecd5cbc1
commit 614eb83984
3 changed files with 11 additions and 8 deletions
+1 -4
View File
@@ -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
View File
@@ -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)
+9
View File
@@ -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
}