Skip to content Search Apps Documentation Source Content 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.

echo.gno

1.15 Kb · 31 lines
 1// Package echo is gnotif's demo realm: Echo sends a message back to its
 2// caller as a browser notification.
 3package echo
 4
 5import (
 6	"chain"
 7
 8	"gno.land/r/g13rqvks880v0hmlfepcj0kkudq0js38d3pc5k6a/gnotif/v1"
 9)
10
11// This realm's gnotif identity opens its handle and sets its trigger at
12// deploy. It keeps no handle, so the trigger never changes.
13func init(cur realm) {
14	me := cur.Sub(gnotif.Subpath)
15	h := gnotif.Open(cross(me))
16	h.Set(cross(me), "echo", gnotif.Trigger{Event: "Echo", Param: "to", Title: "Echo", Body: "{msg}", Link: "/"})
17}
18
19// Echo sends msg to the browsers that opted in with the caller's address.
20// The recipient is always the caller, so nobody can notify another address.
21func Echo(cur realm, msg string) {
22	chain.Emit("Echo", "to", cur.Previous().Address().String(), "msg", msg)
23}
24
25// Render serves one page for every path: what Echo does and where to try it.
26func Render(_ string) string {
27	return "# Echo\n\n" +
28		"Call `Echo` with a message, and gnotif shows it as a notification in the browsers " +
29		"that turned on notifications for your own address. Nobody else can send one to you.\n\n" +
30		"Try it on [demo.gnotif.xyz](https://demo.gnotif.xyz).\n"
31}