Skip to content

Commit

Permalink
chore: address review comments
Browse files Browse the repository at this point in the history
Co-authored-by: İlker G. Öztürk <[email protected]>
  • Loading branch information
jeronimoalbi and ilgooz committed Nov 4, 2024
1 parent 0f48ffb commit 9a60ee5
Show file tree
Hide file tree
Showing 3 changed files with 24 additions and 16 deletions.
18 changes: 10 additions & 8 deletions examples/gno.land/p/demo/boardsv2/draft3/app.gno
Original file line number Diff line number Diff line change
Expand Up @@ -20,13 +20,15 @@ type App struct {
posts post.Store
plugins *plugin.Registry
maxCommentsDepth int
disableComments bool
reputationPolicy pluginreputation.Policy
}

// New creates a new boards application.
func New(st post.Store, options ...Option) App {
app := App{posts: st}
app := App{
posts: st,
maxCommentsDepth: -1, // Infinite number of comments
}
for _, apply := range options {
apply(&app)
}
Expand All @@ -48,24 +50,24 @@ func New(st post.Store, options ...Option) App {
}

func (a App) GetBoard(path string) (_ Board, found bool) {
p, found := a.posts.Get(path)
if !found || p.Level != LevelBoard {
p, found := a.posts.GetByLevel(path, LevelBoard)
if !found {
return Board{}, false
}
return Board{p}, true
}

func (a App) GetThread(path string) (_ Thread, found bool) {
p, found := a.posts.Get(path)
if !found || p.Level != LevelThread {
p, found := a.posts.GetByLevel(path, LevelThread)
if !found {
return Thread{}, false
}
return Thread{p}, true
}

func (a App) GetComment(path string) (_ Comment, found bool) {
p, found := a.posts.Get(path)
if !found || p.Level != LevelComment {
p, found := a.posts.GetByLevel(path, LevelComment)
if !found {
return Comment{}, false
}
return Comment{p}, true
Expand Down
9 changes: 1 addition & 8 deletions examples/gno.land/p/demo/boardsv2/draft3/options.gno
Original file line number Diff line number Diff line change
Expand Up @@ -23,16 +23,9 @@ func TokenBasedReputationPolicy() Option {
}

// MaxCommentsDepth configures the max depth for nested comments.
// Setting it to zero allows infinite comments (default).
// Setting it to -1 allows an infinite number of nested comments (default).
func MaxCommentsDepth(d int) Option {
return func(a *App) {
a.maxCommentsDepth = d
}
}

// DisableComments disables comment support.
func DisableComments() Option {
return func(a *App) {
a.disableComments = true
}
}
13 changes: 13 additions & 0 deletions examples/gno.land/p/demo/boardsv2/draft3/post/store.gno
Original file line number Diff line number Diff line change
Expand Up @@ -16,3 +16,16 @@ func (s Store) Get(path string) (_ *Post, found bool) {
}
return nil, false
}

func (s Store) GetByLevel(path string, level int) (_ *Post, found bool) {
v, found := s.slugs.Get(path)
if !found {
return nil, false
}

p := v.(*Post)
if p.Level != level {
return nil, false
}
return p, true
}

0 comments on commit 9a60ee5

Please sign in to comment.