Federated via graft
1.3 kB
29 lines
1package state
2
3import "strings"
4
5// mirrorMarker tags a comment body as graft's own mirrored output, using
6// zero-width characters a person can't type by accident — or, short of
7// deliberately pasting raw Unicode escapes into a comment box, at all.
8// The earlier guard matched on the visible "**via Forgejo:**" etc. prefix
9// text itself, which meant a real user typing that same phrase at the
10// start of their own comment got it silently excluded from mirroring.
11// Low severity (it only suppresses mirroring their own comment, nothing
12// escalates), but easy to close: the visible attribution text stays for
13// humans reading it, this invisible marker is what the guard actually
14// checks.
15const mirrorMarker = "graft:mirrored"
16
17// MarkMirrored appends the invisible marker to a comment body that's
18// about to be posted as a mirror of content from elsewhere.
19func MarkMirrored(body string) string {
20 return body + mirrorMarker
21}
22
23// IsMirroredComment reports whether body carries graft's own mirror
24// marker — i.e. whether a comment-sync pass produced it, directly or via
25// the ActivityPub/AT Proto reply bridges, and so must never be mirrored
26// back out.
27func IsMirroredComment(body string) bool {
28 return strings.Contains(body, mirrorMarker)
29}