Search Apps Documentation Source Content File Folder Download Copy Actions Download State String Boolean Number Struct Map Slice Pointer Function Closure Reference Nil Package Type Interface Unknown

palette.gno

2.38 Kb Β· 64 lines
 1package reactions
 2
 3// The palette: the closed set of reactions, and the only moderation policy
 4// this package has.
 5//
 6// It is closed on purpose. A free-text reaction is a comment, a comment needs
 7// moderation, and moderation is the thing worth not building. Six is enough to
 8// say something and few enough to fit on one line on a phone.
 9//
10// Every glyph here is a SINGLE codepoint with no variation selector (no
11// U+FE0F) and no zero-width joiner. That is a constraint, not a coincidence:
12// these strings pass through a markdown escaper that strips zero-width and
13// bidi characters, and a glyph that needs U+FE0F to render would come out the
14// other side as its bare monochrome form. ❀️ is the obvious casualty, which is
15// why "heart" is πŸ’œ (U+1F49C), a codepoint that is a colour emoji on its own.
16const (
17	// KeyUp is the default, first in the strip.
18	KeyUp = "up"
19	// KeyHeart is affection rather than agreement.
20	KeyHeart = "heart"
21	// KeyFire is "this is good".
22	KeyFire = "fire"
23	// KeyParty is a congratulation.
24	KeyParty = "party"
25	// KeyRocket is "ship it".
26	KeyRocket = "rocket"
27	// KeyEyes is "I am watching this", the only one that is not praise.
28	KeyEyes = "eyes"
29)
30
31// order is the display order of the palette, which is also the order the
32// strip renders in. A slice and not a map range: gno map iteration order is
33// unspecified, and a Render that reshuffles between identical calls is a
34// consensus bug.
35var order = []string{KeyUp, KeyHeart, KeyFire, KeyParty, KeyRocket, KeyEyes}
36
37// palette maps a key to its glyph. Written as \U escapes rather than literal
38// emoji so that the source says exactly which codepoint it means and a review
39// diff cannot hide a lookalike.
40var palette = map[string]string{
41	KeyUp:     "\U0001F44D", // πŸ‘
42	KeyHeart:  "\U0001F49C", // πŸ’œ
43	KeyFire:   "\U0001F525", // πŸ”₯
44	KeyParty:  "\U0001F389", // πŸŽ‰
45	KeyRocket: "\U0001F680", // πŸš€
46	KeyEyes:   "\U0001F440", // πŸ‘€
47}
48
49// Keys returns the palette keys in display order. The returned slice is a copy,
50// so a caller cannot reorder the palette for everyone else.
51func Keys() []string {
52	out := make([]string, len(order))
53	copy(out, order)
54	return out
55}
56
57// Valid reports whether key names a reaction in the palette.
58func Valid(key string) bool {
59	_, ok := palette[key]
60	return ok
61}
62
63// Emoji returns the glyph for a palette key, or "" when the key is not one.
64func Emoji(key string) string { return palette[key] }