include more details in comments' shadow copies

(useful in case the comment was deleted)
This commit is contained in:
floss4good 2025-04-04 00:08:28 +03:00
parent e483517c7c
commit 957cda9f09
No known key found for this signature in database
GPG key ID: 5B948B4F4DAF819D

View file

@ -14,6 +14,8 @@ import (
// CommentData represents a trimmed down comment that is used for preserving
// only the fields needed for abusive content reports (mainly string fields).
type CommentData struct {
PosterID int64
IssueID int64
Content string
ContentVersion int
CreatedUnix timeutil.TimeStamp
@ -24,6 +26,8 @@ type CommentData struct {
// (keeping only the fields relevant for moderation purposes)
func newCommentData(comment *Comment) CommentData {
return CommentData{
PosterID: comment.PosterID,
IssueID: comment.IssueID,
Content: comment.Content,
ContentVersion: comment.ContentVersion,
CreatedUnix: comment.CreatedUnix,
@ -33,9 +37,8 @@ func newCommentData(comment *Comment) CommentData {
// IfNeededCreateShadowCopyForComment checks if for the given comment there are any reports of abusive content submitted
// and if found a shadow copy of relevant comment fields will be stored into DB and linked to the above report(s).
// This function should be called when a comment is deleted or updated.
// This function should be called before a comment is deleted or updated.
func IfNeededCreateShadowCopyForComment(ctx context.Context, comment *Comment) error {
// TODO check comment.Type?
if moderation.IsReported(ctx, moderation.ReportedContentTypeComment, comment.ID) {
commentData := newCommentData(comment)
content, err := json.Marshal(commentData)