types.gno

0.79 Kb ยท 36 lines
 1package minisocial
 2
 3import (
 4	"std"  // The standard Gno package
 5	"time" // For handling time operations
 6
 7	"gno.land/p/demo/seqid"
 8	"gno.land/p/demo/ufmt"
 9
10	"gno.land/r/sys/users"
11)
12
13// Post defines the main data we keep about each post
14type Post struct {
15	id        seqid.ID
16	text      string
17	author    std.Address
18	createdAt time.Time
19	updatedAt time.Time
20}
21
22func (p Post) String() string {
23	out := p.text + "\n\n"
24
25	author := p.author.String()
26	// We can import and use the r/sys/users package to resolve addresses
27	user := users.ResolveAddress(p.author)
28	if user != nil {
29		// RenderLink provides a link that is clickable
30		// The link goes to the user's profile page
31		author = user.RenderLink("")
32	}
33
34	out += ufmt.Sprintf("_by %s on %s_\n\n", author, p.createdAt.Format("02 Jan 2006, 15:04"))
35	return out
36}