commento.js: don't recursively delete comments
This commit is contained in:
parent
3ef4a79547
commit
ee7875cc1e
@ -16,4 +16,5 @@ type comment struct {
|
|||||||
State string `json:"state,omitempty"`
|
State string `json:"state,omitempty"`
|
||||||
CreationDate time.Time `json:"creationDate"`
|
CreationDate time.Time `json:"creationDate"`
|
||||||
Direction int `json:"direction"`
|
Direction int `json:"direction"`
|
||||||
|
Deleted bool `json:"deleted"`
|
||||||
}
|
}
|
||||||
|
@ -10,8 +10,9 @@ func commentDelete(commentHex string) error {
|
|||||||
}
|
}
|
||||||
|
|
||||||
statement := `
|
statement := `
|
||||||
DELETE FROM comments
|
UPDATE comments
|
||||||
WHERE commentHex=$1;
|
SET deleted = true, markdown = '[deleted]', html = '[deleted]', commenterHex = 'anonymous'
|
||||||
|
WHERE commentHex = $1;
|
||||||
`
|
`
|
||||||
_, err := db.Exec(statement, commentHex)
|
_, err := db.Exec(statement, commentHex)
|
||||||
|
|
||||||
|
@ -16,6 +16,7 @@ func commentGetByCommentHex(commentHex string) (comment, error) {
|
|||||||
parentHex,
|
parentHex,
|
||||||
score,
|
score,
|
||||||
state,
|
state,
|
||||||
|
deleted,
|
||||||
creationDate
|
creationDate
|
||||||
FROM comments
|
FROM comments
|
||||||
WHERE comments.commentHex = $1;
|
WHERE comments.commentHex = $1;
|
||||||
@ -31,6 +32,7 @@ func commentGetByCommentHex(commentHex string) (comment, error) {
|
|||||||
&c.ParentHex,
|
&c.ParentHex,
|
||||||
&c.Score,
|
&c.Score,
|
||||||
&c.State,
|
&c.State,
|
||||||
|
&c.Deleted,
|
||||||
&c.CreationDate); err != nil {
|
&c.CreationDate); err != nil {
|
||||||
// TODO: is this the only error?
|
// TODO: is this the only error?
|
||||||
return c, errorNoSuchComment
|
return c, errorNoSuchComment
|
||||||
|
@ -20,6 +20,7 @@ func commentList(commenterHex string, domain string, path string, includeUnappro
|
|||||||
parentHex,
|
parentHex,
|
||||||
score,
|
score,
|
||||||
state,
|
state,
|
||||||
|
deleted,
|
||||||
creationDate
|
creationDate
|
||||||
FROM comments
|
FROM comments
|
||||||
WHERE
|
WHERE
|
||||||
@ -66,6 +67,7 @@ func commentList(commenterHex string, domain string, path string, includeUnappro
|
|||||||
&c.ParentHex,
|
&c.ParentHex,
|
||||||
&c.Score,
|
&c.Score,
|
||||||
&c.State,
|
&c.State,
|
||||||
|
&c.Deleted,
|
||||||
&c.CreationDate); err != nil {
|
&c.CreationDate); err != nil {
|
||||||
return nil, nil, errorInternal
|
return nil, nil, errorInternal
|
||||||
}
|
}
|
||||||
|
6
db/20190913175445-delete-comments.sql
Normal file
6
db/20190913175445-delete-comments.sql
Normal file
@ -0,0 +1,6 @@
|
|||||||
|
DROP TRIGGER IF EXISTS commentsDeleteTrigger ON comments;
|
||||||
|
|
||||||
|
DROP FUNCTION IF EXISTS commentsDeleteTriggerFunction;
|
||||||
|
|
||||||
|
ALTER TABLE comments
|
||||||
|
ADD deleted BOOLEAN NOT NULL DEFAULT false;
|
@ -764,9 +764,9 @@
|
|||||||
}
|
}
|
||||||
|
|
||||||
cur.sort(function(a, b) {
|
cur.sort(function(a, b) {
|
||||||
if (a.commentHex === stickyCommentHex) {
|
if (!a.deleted && a.commentHex === stickyCommentHex) {
|
||||||
return -Infinity;
|
return -Infinity;
|
||||||
} else if (b.commentHex === stickyCommentHex) {
|
} else if (!b.deleted && b.commentHex === stickyCommentHex) {
|
||||||
return Infinity;
|
return Infinity;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -852,7 +852,11 @@
|
|||||||
timeago.title = comment.creationDate.toString();
|
timeago.title = comment.creationDate.toString();
|
||||||
|
|
||||||
card.style["borderLeft"] = "2px solid " + color;
|
card.style["borderLeft"] = "2px solid " + color;
|
||||||
name.innerText = commenter.name;
|
if (comment.deleted) {
|
||||||
|
name.innerText = "[deleted]";
|
||||||
|
} else {
|
||||||
|
name.innerText = commenter.name;
|
||||||
|
}
|
||||||
text.innerHTML = comment.html;
|
text.innerHTML = comment.html;
|
||||||
timeago.innerHTML = timeDifference(curTime, comment.creationDate);
|
timeago.innerHTML = timeDifference(curTime, comment.creationDate);
|
||||||
score.innerText = scorify(comment.score);
|
score.innerText = scorify(comment.score);
|
||||||
@ -947,20 +951,22 @@
|
|||||||
|
|
||||||
append(options, collapse);
|
append(options, collapse);
|
||||||
|
|
||||||
append(options, downvote);
|
if (!comment.deleted) {
|
||||||
append(options, upvote);
|
append(options, downvote);
|
||||||
|
append(options, upvote);
|
||||||
|
}
|
||||||
|
|
||||||
if (comment.commenterHex === selfHex) {
|
if (comment.commenterHex === selfHex) {
|
||||||
append(options, edit);
|
append(options, edit);
|
||||||
} else {
|
} else if (!comment.deleted) {
|
||||||
append(options, reply);
|
append(options, reply);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (isModerator && parentHex === "root") {
|
if (!comment.deleted && (isModerator && parentHex === "root")) {
|
||||||
append(options, sticky);
|
append(options, sticky);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (isModerator || comment.commenterHex === selfHex) {
|
if (!comment.deleted && (isModerator || comment.commenterHex === selfHex)) {
|
||||||
append(options, remove);
|
append(options, remove);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -968,7 +974,7 @@
|
|||||||
append(options, approve);
|
append(options, approve);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!isModerator && stickyCommentHex === comment.commentHex) {
|
if (!comment.deleted && (!isModerator && stickyCommentHex === comment.commentHex)) {
|
||||||
append(options, sticky);
|
append(options, sticky);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -1048,8 +1054,8 @@
|
|||||||
errorHide();
|
errorHide();
|
||||||
}
|
}
|
||||||
|
|
||||||
var card = $(ID_CARD + commentHex);
|
var text = $(ID_TEXT + commentHex);
|
||||||
remove(card);
|
text.innerText = "[deleted]";
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user