board.gno
2.41 Kb · 93 lines
1package hub
2
3import (
4 "gno.land/p/gnoland/boards"
5)
6
7// Member defines a type for board members.
8type Member struct {
9 Address address
10 Roles []string
11}
12
13// Board defines a safe type for boards.
14type Board struct {
15 // id is the unique identifier of the board.
16 id uint64
17
18 // name is the current name of the board.
19 name string
20
21 // aliases contains a list of alternative names for the board.
22 aliases []string
23
24 // readonly indicates that the board is readonly.
25 readonly bool
26
27 // threadCount contains the number of threads within the board.
28 threadCount int
29
30 // memberCount contains the number of members of the board.
31 memberCount int
32
33 // creator is the account address that created the board.
34 creator address
35
36 // createdAt is the board's creation time as Unix time.
37 createdAt int64
38
39 // updatedAt is the board's update time as Unix time.
40 updatedAt int64
41}
42
43// ID returns the unique identifier of the board.
44func (b Board) ID() uint64 { return b.id }
45
46// Name returns the current name of the board.
47func (b Board) Name() string { return b.name }
48
49// Aliases returns the list of alternative names for the board.
50func (b Board) Aliases() []string { return b.aliases }
51
52// Readonly indicates that the board is readonly.
53func (b Board) Readonly() bool { return b.readonly }
54
55// ThreadCount returns the number of threads within the board.
56func (b Board) ThreadCount() int { return b.threadCount }
57
58// MemberCount returns the number of members of the board.
59func (b Board) MemberCount() int { return b.memberCount }
60
61// Creator returns the account address that created the board.
62func (b Board) Creator() address { return b.creator }
63
64// CreatedAt returns the board's creation time as Unix time.
65func (b Board) CreatedAt() int64 { return b.createdAt }
66
67// UpdatedAt returns the board's update time as Unix time.
68func (b Board) UpdatedAt() int64 { return b.updatedAt }
69
70// NewSafeBoard creates a safe board.
71func NewSafeBoard(ref *boards.Board) Board {
72 var usersCount int
73 if ref.Permissions != nil {
74 usersCount = ref.Permissions.UsersCount()
75 }
76
77 var threadCount int
78 if ref.Threads != nil {
79 threadCount = ref.Threads.Size()
80 }
81
82 return Board{
83 id: uint64(ref.ID),
84 name: ref.Name,
85 aliases: append([]string(nil), ref.Aliases...),
86 readonly: ref.Readonly,
87 threadCount: threadCount,
88 memberCount: usersCount,
89 creator: ref.Creator,
90 createdAt: timeToUnix(ref.CreatedAt),
91 updatedAt: timeToUnix(ref.UpdatedAt),
92 }
93}