moderation_state.gno
1.46 Kb · 46 lines
1package memba_reviews_v2
2
3import (
4 "crypto/sha256"
5 "encoding/hex"
6)
7
8// ModerationState is a bounded copied snapshot, including hidden/deleted items.
9// No pointer or body is exposed. BodyHash binds edits even within the same block.
10// Reactions and cumulative flag counts are not moderation authorization inputs.
11type ModerationState struct {
12 ID uint64
13 Review bool
14 ParentID uint64
15 Subject string
16 Author address
17 Rating int
18 BodyHash string
19 CreatedAt int64
20 EditedAt int64
21 Hidden bool
22 Deleted bool
23 Flagged bool
24}
25
26func moderationBodyHash(body string) string {
27 sum := sha256.Sum256([]byte(body))
28 return hex.EncodeToString(sum[:])
29}
30
31// GetModerationState returns a zero value for an absent ID. The flagged-index
32// bit is distinct from historical flags; Unhide removes only the index entry.
33func GetModerationState(id uint64) ModerationState {
34 _, flagged := flaggedIDs.Get(strID(id))
35 if r, ok := getReview(id); ok {
36 return ModerationState{ID: r.ID, Review: true, Subject: r.Subject, Author: r.Author,
37 Rating: r.Rating, BodyHash: moderationBodyHash(r.Body), CreatedAt: r.CreatedAt,
38 EditedAt: r.EditedAt, Hidden: r.Hidden, Deleted: r.Deleted, Flagged: flagged}
39 }
40 if c, ok := getComment(id); ok {
41 return ModerationState{ID: c.ID, ParentID: c.ReviewID, Author: c.Author,
42 BodyHash: moderationBodyHash(c.Body), CreatedAt: c.CreatedAt, EditedAt: c.EditedAt,
43 Hidden: c.Hidden, Deleted: c.Deleted, Flagged: flagged}
44 }
45 return ModerationState{}
46}