func IsRepost
IsRepost checks if a thread is a repost.
IsRepost checks if a thread is a repost.
IsThread checks if a post is a thread. When a post is not a thread it's considered a thread's reply/comment.
SummaryOf returns a summary of a text.
New creates a new basic non permissioned board.
NewFlagStorage creates a new storage for post flags. The new storage uses an AVL tree to store flagging info.
NewIdentifierGenerator creates a new sequential unique identifier generator.
NewPermissionSet creates a new PermissionSet containing the given permissions.
MustNewReply creates a new reply or panics on error.
MustNewRepost creates a new thread that is a repost of a thread from another board or panics on error.
MustNewThread creates a new thread or panics on error.
NewReply creates a new reply to a thread or another reply.
NewRepost creates a new thread that is a repost of a thread from another board.
NewThread creates a new board thread.
NewPostStorage creates a new storage for posts. The new storage uses an AVL tree to store posts.
NewRepostStorage creates a new storage for reposts. The new storage uses an AVL tree to store reposts.
NewStorage creates a new boards storage.
Args is a list of generic arguments.
1type Board struct {
2 // ID is the unique identifier of the board.
3 ID ID
4
5 // Name is the current name of the board.
6 Name string
7
8 // Aliases contains a list of alternative names for the board.
9 Aliases []string
10
11 // Readonly indicates that the board is readonly.
12 Readonly bool
13
14 // Threads contains board threads.
15 Threads PostStorage
16
17 // ThreadsSequence generates sequential ID for new threads.
18 ThreadsSequence IdentifierGenerator
19
20 // Permissions enables support for permissioned boards.
21 // This type of boards allows managing members with roles and permissions.
22 // It also enables the implementation of permissioned execution of board related features.
23 Permissions Permissions
24
25 // Creator is the account address that created the board.
26 Creator address
27
28 // Meta allows storing board metadata.
29 Meta any
30
31 // CreatedAt is the board's creation time.
32 CreatedAt time.Time
33
34 // UpdatedAt is the board's update time.
35 UpdatedAt time.Time
36}Board defines a type for boards.
SetAliases sets board name aliases.
SetCreatedAt sets the time when board was created.
SetCreator sets the address of the account that created the board.
SetID sets board ID value.
SetMeta sets board metadata.
SetName sets name value.
SetPermissions sets permissions value.
SetReadonly sets readonly value.
SetThreadStorage sets the storage where board threads are stored.
SetThreadsSequence sets the sequential thread ID generator.
SetUpdatedAt sets the time when a board value was updated.
BoardIterFn defines a function type to iterate boards.
Flag defines a type for post flags
FlagIterFn defines a function type to iterate post flags.
1type FlagStorage interface {
2 // Exists checks if a flag from a user exists
3 Exists(address) bool
4
5 // Add adds a new flag from a user.
6 Add(Flag) error
7
8 // Remove removes a user flag.
9 Remove(address) (removed bool)
10
11 // Size returns the number of flags in the storage.
12 Size() int
13
14 // Iterate iterates post flags.
15 // To reverse iterate flags use a negative count.
16 // If the callback returns true, the iteration is stopped.
17 Iterate(start, count int, fn FlagIterFn) bool
18}FlagStorage defines an interface for storing posts flagging information.
ID defines a type for unique identifiers.
Key returns the ID as a string which can be used to index by ID.
PaddedString returns the ID as a 10 character string padded with zeroes. This value can be used for indexing by ID.
String returns the ID as a string.
IdentifierGenerator defines an interface for sequential unique identifier generators.
Permission defines the type for permissions.
PermissionSet defines a type to store any number of permissions.
1type Permissions interface {
2 // HasRole checks if a user has a specific role assigned.
3 HasRole(address, Role) bool
4
5 // HasPermission checks if a user has a specific permission.
6 HasPermission(address, Permission) bool
7
8 // WithPermission calls a callback when a user has a specific permission.
9 // It panics on error.
10 //
11 // An inline crossing function call can be used by the implementation if
12 // crossing is required to update its internal state, for example to create
13 // proposals that when approved execute the callback:
14 //
15 // func(realm) {
16 // // Update internal realm state
17 // // ...
18 // }(cross)
19 WithPermission(address, Permission, Args, func())
20
21 // SetUserRoles adds a new user when it doesn't exist and sets its roles.
22 // Method can also be called to change the roles of an existing user.
23 // It panics on error.
24 SetUserRoles(address, ...Role)
25
26 // RemoveUser removes a user from the permissioner.
27 // It panics on error.
28 RemoveUser(address) (removed bool)
29
30 // HasUser checks if a user exists.
31 HasUser(address) bool
32
33 // UsersCount returns the total number of users the permissioner contains.
34 UsersCount() int
35
36 // IterateUsers iterates permissions' users.
37 IterateUsers(start, count int, fn UsersIterFn) bool
38}Permissions define an interface to for permissioned execution.
1type Post struct {
2 // ID is the unique identifier of the post.
3 ID ID
4
5 // ParentID is the ID of the parent post.
6 ParentID ID
7
8 // ThreadID contains the post ID of the thread where current post is created.
9 // If current post is a thread it contains post's ID.
10 // It should be used when current post is a thread or reply.
11 ThreadID ID
12
13 // OriginalBoardID contains the board ID of the original post when current post is a repost.
14 OriginalBoardID ID
15
16 // Board contains the board where post is created.
17 Board *Board
18
19 // Title contains the post's title.
20 Title string
21
22 // Body contains content of the post.
23 Body string
24
25 // Hidden indicates that the post is hidden.
26 Hidden bool
27
28 // Readonly indicates that the post is readonly.
29 Readonly bool
30
31 // Replies stores post replies.
32 Replies PostStorage
33
34 // Reposts stores reposts of the current post.
35 // It should be used when post is a thread.
36 Reposts RepostStorage
37
38 // Flags stores users flags for the current post.
39 Flags FlagStorage
40
41 // Creator is the account address that created the post.
42 Creator address
43
44 // Meta allows storing post metadata.
45 Meta any
46
47 // CreatedAt is the post's creation time.
48 CreatedAt time.Time
49
50 // UpdatedAt is the post's update time.
51 UpdatedAt time.Time
52}Post defines a generic type for posts. A post can be either a thread or a reply.
SetBoard sets the board where post was created.
SetBody sets post's content.
SetCreatedAt sets the time when post was created.
SetCreator sets the address of the account that created the post.
SetFlagStorage sets the storage where post flags are stored.
SetHidden sets hidden value.
SetID sets post ID value.
SetOriginalBoardID sets the board ID of the original post when current post is a repost.
SetParentID sets post's parent ID value.
SetReadonly sets readonly value.
SetReplyStorage sets the storage where post replies are stored.
SetRepostStorage sets the storage where thread reposts are stored.
SetThreadID sets thread ID value.
SetTitle sets title value.
SetUpdatedAt sets the time when a post value was updated.
Summary return a summary of the post's body. It returns the body making sure that the length is limited to 80 characters.
PostIterFn defines a function type to iterate posts.
1type PostStorage interface {
2 // Get retruns a post that matches an ID.
3 Get(ID) (_ *Post, found bool)
4
5 // Remove removes a post from the storage.
6 Remove(ID) (_ *Post, removed bool)
7
8 // Add adds a post in the storage.
9 Add(*Post) error
10
11 // Size returns the number of posts in the storage.
12 Size() int
13
14 // Iterate iterates posts.
15 // To reverse iterate posts use a negative count.
16 // If the callback returns true, the iteration is stopped.
17 Iterate(start, count int, fn PostIterFn) bool
18}PostStorage defines an interface for posts storage.
RepostIterFn defines a function type to iterate reposts.
1type RepostStorage interface {
2 // Get returns the repost ID for a board.
3 Get(board ID) (repost ID, found bool)
4
5 // Add adds a new repost to the storage.
6 Add(repost *Post) error
7
8 // Remove removes repost for a board.
9 Remove(board ID) (removed bool)
10
11 // Size returns the number of reposts in the storage.
12 Size() int
13
14 // Iterate iterates reposts.
15 // To reverse iterate reposts use a negative count.
16 // If the callback returns true, the iteration is stopped.
17 Iterate(start, count int, fn RepostIterFn) bool
18}RepostStorage defines an interface for storing reposts.
Role defines the type for user roles.
1type Storage interface {
2 // Get retruns a boards that matches an ID.
3 Get(ID) (_ *Board, found bool)
4
5 // GetByName retruns a boards that matches a name.
6 GetByName(name string) (_ *Board, found bool)
7
8 // Remove removes a board from the storage.
9 Remove(ID) (_ *Board, removed bool)
10
11 // Add adds a board to the storage.
12 Add(*Board) error
13
14 // Size returns the number of boards in the storage.
15 Size() int
16
17 // Iterate iterates boards.
18 // To reverse iterate boards use a negative count.
19 // If the callback returns true, the iteration is stopped.
20 Iterate(start, count int, fn BoardIterFn) bool
21}Storage defines an interface for boards storage.
User contains user info.
UsersIterFn defines a function type to iterate users.