more effective masking

This commit is contained in:
Umputun
2018-01-08 01:44:06 -06:00
parent b9ba52b2a1
commit e1e629a159
2 changed files with 5 additions and 3 deletions
+4 -2
View File
@@ -117,14 +117,16 @@ func (a *admin) checkBlocked(locator store.Locator, user store.User) bool {
// processes comments and hides text of all comments for blocked users.
// resets score and votes too
func (a *admin) maskBlockedUsers(comments []store.Comment) (res []store.Comment) {
for _, c := range comments {
res = make([]store.Comment, len(comments))
for i, c := range comments {
if a.dataService.IsBlocked(c.Locator, c.User.ID) {
c.User.Blocked = true
c.Text = "this comment was deleted"
c.Score = 0
c.Votes = map[string]bool{}
c.Edit = nil
}
res = append(res, c)
res[i] = c
}
return res
}
+1 -1
View File
@@ -241,7 +241,7 @@ func (s *Server) findCommentsCtrl(w http.ResponseWriter, r *http.Request) {
})
if err != nil {
common.SendErrorJSON(w, r, http.StatusInternalServerError, err, "can't find comments")
common.SendErrorJSON(w, r, http.StatusBadRequest, err, "can't find comments")
return
}
renderJSONFromBytes(w, r, data)