Skip to content Search Apps Documentation Source Content Run Reset Eval Playground File Folder Download Copy Actions State String Boolean Number Struct Map Slice Pointer Function Closure Reference Nil Package Type Interface Unknown

Community realm. Read the code first. Community realm, deployed by its author. Read the code before you interact or send coins.

names.gno

2.36 Kb · 79 lines
 1package home
 2
 3import (
 4	"strings"
 5
 6	roles "gno.land/p/nym-alexiscolin000/gnoradio/role/v0"
 7	"gno.land/p/nym-alexiscolin000/gnoradio/safe/v0"
 8	"gno.land/p/nym-alexiscolin000/gnoradio/svg/v0"
 9
10	"gno.land/p/nym-alexiscolin000/gnoradio/text/v0"
11	"gno.land/r/sys/users"
12)
13
14// nickname is the app's readable stand-in for an address without a gno.land
15// name ("Coral Vinyl 4F"), ported from app/src/lib/nickname.ts: the same word
16// lists and FNV-1a hash, so one address reads the same on both.
17func nickname(addr address) string {
18	colours := [24]string{
19		"Coral", "Amber", "Indigo", "Teal", "Olive", "Ivory", "Cobalt", "Saffron", "Jade", "Ruby", "Slate", "Sienna",
20		"Azure", "Plum", "Mint", "Ochre", "Pearl", "Cedar", "Sage", "Copper", "Lilac", "Denim", "Lemon", "Cherry",
21	}
22	words := [20]string{
23		"Listener", "Tuner", "Echo", "Melody", "Rhythm", "Chord", "Groove", "Tempo", "Signal", "Wave",
24		"Dial", "Record", "Vinyl", "Cassette", "Bassline", "Encore", "Chorus", "Remix", "Beat", "Tune",
25	}
26	h := svg.FNV(addr.String())
27	const hex = "0123456789ABCDEF"
28	return colours[h%24] + " " + words[h/24%20] + " " + string(hex[h>>28]) + string(hex[h>>24&15])
29}
30
31// userName is the address's gno.land name (r/sys/users), "" when it has
32// none or the name holds a blocked word (the app shows the nickname then too).
33func userName(addr address) string {
34	d := users.ResolveAddress(addr)
35	if d == nil {
36		return ""
37	}
38	n := d.Name()
39	if n == "" || safe.Blocked(n) {
40		return ""
41	}
42	return n
43}
44
45// displayName is "@name" when the address registered one, else its nickname.
46func displayName(addr address) string {
47	if n := userName(addr); n != "" {
48		return "@" + n
49	}
50	return nickname(addr)
51}
52
53// role links an address GnoRadio itself uses under its role, not a nickname.
54func role(addr address, label string) string {
55	if !roles.Canonical(addr) {
56		return label
57	}
58	return "[" + label + "](" + page("listener/"+addr.String()) + ")"
59}
60
61// plural is "1 track", "2 tracks".
62func plural(n int, word string) string {
63	if n == 1 {
64		return "1 " + word
65	}
66	return text.Itoa(n) + " " + word + "s"
67}
68
69// removedNote words why content is gone: "Removed · <reason>" for the
70// moderator, the artist's own note otherwise.
71func removedNote(note string) string {
72	if r, ok := strings.CutPrefix(note, "Removed by moderation: "); ok {
73		return "Removed · " + r
74	}
75	if note == "" {
76		return "This is no longer available."
77	}
78	return note
79}