From 9a60ee5ffb452fca424d95daa48725ca992e5061 Mon Sep 17 00:00:00 2001 From: jeronimoalbi Date: Mon, 4 Nov 2024 17:48:19 +0100 Subject: [PATCH] chore: address review comments MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Co-authored-by: İlker G. Öztürk --- .../gno.land/p/demo/boardsv2/draft3/app.gno | 18 ++++++++++-------- .../p/demo/boardsv2/draft3/options.gno | 9 +-------- .../p/demo/boardsv2/draft3/post/store.gno | 13 +++++++++++++ 3 files changed, 24 insertions(+), 16 deletions(-) diff --git a/examples/gno.land/p/demo/boardsv2/draft3/app.gno b/examples/gno.land/p/demo/boardsv2/draft3/app.gno index 991678ac608..3893e0866f7 100644 --- a/examples/gno.land/p/demo/boardsv2/draft3/app.gno +++ b/examples/gno.land/p/demo/boardsv2/draft3/app.gno @@ -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) } @@ -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 diff --git a/examples/gno.land/p/demo/boardsv2/draft3/options.gno b/examples/gno.land/p/demo/boardsv2/draft3/options.gno index cbc395e94e0..906b1130663 100644 --- a/examples/gno.land/p/demo/boardsv2/draft3/options.gno +++ b/examples/gno.land/p/demo/boardsv2/draft3/options.gno @@ -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 - } -} diff --git a/examples/gno.land/p/demo/boardsv2/draft3/post/store.gno b/examples/gno.land/p/demo/boardsv2/draft3/post/store.gno index 43762d87867..49513f250db 100644 --- a/examples/gno.land/p/demo/boardsv2/draft3/post/store.gno +++ b/examples/gno.land/p/demo/boardsv2/draft3/post/store.gno @@ -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 +}