From be049e79736f483a27b3b2a08639aaf39bbc0a78 Mon Sep 17 00:00:00 2001 From: jeronimoalbi Date: Fri, 4 Oct 2024 14:53:58 +0200 Subject: [PATCH] wip: defining a simple package API for creating posts MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Co-authored-by: İlker G. Öztürk --- examples/gno.land/p/demo/boardsv2/app.gno | 35 +++++++ examples/gno.land/p/demo/boardsv2/board.gno | 20 ++++ .../gno.land/p/demo/boardsv2/boardsv2.gno | 8 +- examples/gno.land/p/demo/boardsv2/option.gno | 11 +++ examples/gno.land/p/demo/boardsv2/post.gno | 30 ++++++ .../gno.land/p/demo/boardsv2/post/content.gno | 5 + .../boardsv2/post/plugins/content/content.gno | 30 ++++++ .../gno.land/p/demo/boardsv2/post/post.gno | 91 ++++++++++++++++++- .../gno.land/p/demo/boardsv2/post/storage.gno | 4 + .../gno.land/p/demo/boardsv2/post/view.gno | 2 +- .../gno.land/r/demo/boardsv2/boardsv2.gno | 45 ++++++++- 11 files changed, 277 insertions(+), 4 deletions(-) create mode 100644 examples/gno.land/p/demo/boardsv2/app.gno create mode 100644 examples/gno.land/p/demo/boardsv2/board.gno create mode 100644 examples/gno.land/p/demo/boardsv2/option.gno create mode 100644 examples/gno.land/p/demo/boardsv2/post.gno create mode 100644 examples/gno.land/p/demo/boardsv2/post/content.gno create mode 100644 examples/gno.land/p/demo/boardsv2/post/plugins/content/content.gno create mode 100644 examples/gno.land/p/demo/boardsv2/post/storage.gno diff --git a/examples/gno.land/p/demo/boardsv2/app.gno b/examples/gno.land/p/demo/boardsv2/app.gno new file mode 100644 index 000000000000..ab2f184e5e8d --- /dev/null +++ b/examples/gno.land/p/demo/boardsv2/app.gno @@ -0,0 +1,35 @@ +package boardsv2 + +import ( + "gno.land/demo/p/boardsv2/post" + commentplugin "gno.land/demo/p/boardsv2/post/plugins/content" +) + +type App struct { + s Storage + boards []Board +} + +func New(s Storage, o ...Option) App { + a := App{ + s: Storage, + } + return a +} + +func (a *App) AddBoard(name, title, description string) (*Board, error) { + p := post.New(commentplugin.TitleBasedContent{ + Title: title, + Description: description, + }) + post.Add(a.s, name, p) + return a.GetBoard(name) +} + +func (a *App) GetBoard(name string) (board *Board, found bool) { + +} + +func (a *App) ListBoards() ([]*Board, error) { + +} diff --git a/examples/gno.land/p/demo/boardsv2/board.gno b/examples/gno.land/p/demo/boardsv2/board.gno new file mode 100644 index 000000000000..cf5d89ce828f --- /dev/null +++ b/examples/gno.land/p/demo/boardsv2/board.gno @@ -0,0 +1,20 @@ +package boardsv2 + +type Board struct { +} + +func (b *Board) AddPost() error { + +} + +func (b *Board) GetPost(id string) (post *Post, found bool) { + +} + +func (b *Board) Fork() error { + +} + +func (b *Board) Lock() error { + +} diff --git a/examples/gno.land/p/demo/boardsv2/boardsv2.gno b/examples/gno.land/p/demo/boardsv2/boardsv2.gno index 4ad3d4662723..91c308f95763 100644 --- a/examples/gno.land/p/demo/boardsv2/boardsv2.gno +++ b/examples/gno.land/p/demo/boardsv2/boardsv2.gno @@ -1 +1,7 @@ -package boardsv2 \ No newline at end of file +// boardsv2 is a reddit like abstraction around post/*. +// You might implement other abstractions around post/* to create +// different type of dApps. +// refer to the app.gno file to get started. +package boardsv2 + + diff --git a/examples/gno.land/p/demo/boardsv2/option.gno b/examples/gno.land/p/demo/boardsv2/option.gno new file mode 100644 index 000000000000..6d45c967dde6 --- /dev/null +++ b/examples/gno.land/p/demo/boardsv2/option.gno @@ -0,0 +1,11 @@ +package boardsv2 + +type Option struct{} + +// LinearReputationPolicy allows upvoting or downvoting a post by one +// for each account. +func LineerReputationPolicy() Option {} + +// TokenBasedReputationPolicy allows upvoting or downvoting a post propotional +// to the specified tokens that an account holds. +func TokenBasedReputationPolicy() Option {} diff --git a/examples/gno.land/p/demo/boardsv2/post.gno b/examples/gno.land/p/demo/boardsv2/post.gno new file mode 100644 index 000000000000..a15e1df53994 --- /dev/null +++ b/examples/gno.land/p/demo/boardsv2/post.gno @@ -0,0 +1,30 @@ +package boardsv2 + +import ( + "gno.land/demo/p/boardsv2/post" + replyplugin "gno.land/demo/p/boardsv2/post/plugins/content/reply" +) + +type Post struct { + post post.Post + st Store +} + +func (p *Post) Comment(creator std.Address, message string) (id string, err error) { + pp := p.New(replyplugin.MessageContent{ + Message: message, + }) + id := p.post.NextIncrementalKey(creator.String()) // Post.ID/address/1 = "comment ID" + if err := post.Add(p.st, id); err != nil { + return "", err + } + return id, nil +} + +func (p *Post) Upvote() error { + +} + +func (p *Post) Downvote() error { + +} diff --git a/examples/gno.land/p/demo/boardsv2/post/content.gno b/examples/gno.land/p/demo/boardsv2/post/content.gno new file mode 100644 index 000000000000..cbfd45c36feb --- /dev/null +++ b/examples/gno.land/p/demo/boardsv2/post/content.gno @@ -0,0 +1,5 @@ +package post + +type Content interface { + Render() string +} diff --git a/examples/gno.land/p/demo/boardsv2/post/plugins/content/content.gno b/examples/gno.land/p/demo/boardsv2/post/plugins/content/content.gno new file mode 100644 index 000000000000..05043e7e1724 --- /dev/null +++ b/examples/gno.land/p/demo/boardsv2/post/plugins/content/content.gno @@ -0,0 +1,30 @@ +package commentplugin + +type CommentContent struct { + Body string +} + +func (c CommentContent) Render() string { + +} + +type TitleBasedContent struct{} + +type TextContent struct { + Title string + Body string + Tags []string +} + +func (c TextContent) Render() string { + +} + +type PollContent struct { + Question string + Options []string + Votes []struct { + Address std.Adress + Option string + } +} diff --git a/examples/gno.land/p/demo/boardsv2/post/post.gno b/examples/gno.land/p/demo/boardsv2/post/post.gno index 54be1f50a862..d103579d437b 100644 --- a/examples/gno.land/p/demo/boardsv2/post/post.gno +++ b/examples/gno.land/p/demo/boardsv2/post/post.gno @@ -1 +1,90 @@ -package post \ No newline at end of file +package post + +import "time" + +/* +alicePost = &Post { content: "foo" } (0x001) +bobFork := &Post { Origial: alicePost (0x001) } + +//1. Check gc behavior in realm for forks + +--- +alicePost := &(*alicePost) (0x002) +alicePost.content = "new content" + +bobFork := &Post { Origial: uintptr(0x001) } +--- +type Post struct { + ID int + Level int +} + +package reddit + +// explore with plugins +// - boardsv2 +// - pkg/general +// - pkg/reddit +var ( + rating avl.Tree +) + +genericPost := Post{} +reddit.UpvotePost(genericPost.ID) +*/ + +// Blog example +// Home +// - post 1 (content: title, body, author, label, timestamp) +// - post 1.1 (body, author) (thread) +// - post 1.1.1 (comment to a thread but also a new thread) +// - post 1.1.1.1 +// - post 1.2 (thread) +// +// - post 2 +// - post 3 +// +// Reddit example +// Home +// - post 1 (title, body) (board) +// - post 1.1 (title, body) (sub-board) +// - post 1.1.1 (title, body, label) +// - post 1.1.1.1 (comment, thread) +type Post struct { + ID string + Content Content // title, body, label, author, other metadata... + Level int + Base *Post + Children []*Post + Forks []*Post + UpdatedAt time.Time + CreatedAt time.Time // the time when created by user or forked. + Creator std.Address +} + +// create plugins for Post type < +// upvoting < implement first plugin +// define public API for plugin, post packages and boardsv2 +// moderation +// +// plugin ideas: +// - visibility +// - upcoting +// - acess control > you shouldn't be able to answer to the boards yo're not invited +// - moedaration (ban certain posts -this could be through a dao in the future) + +func New(s Storage) Post { + +} + +func Create(c Content) *Post { + +} + +func (p *Post) NextIncrementalKey(base string) string { + +} + +// func (p *Post) Append() error { +// +// } diff --git a/examples/gno.land/p/demo/boardsv2/post/storage.gno b/examples/gno.land/p/demo/boardsv2/post/storage.gno new file mode 100644 index 000000000000..49a5f7eef325 --- /dev/null +++ b/examples/gno.land/p/demo/boardsv2/post/storage.gno @@ -0,0 +1,4 @@ +package post + +type Storage interface { +} diff --git a/examples/gno.land/p/demo/boardsv2/post/view.gno b/examples/gno.land/p/demo/boardsv2/post/view.gno index 54be1f50a862..235520f8734b 100644 --- a/examples/gno.land/p/demo/boardsv2/post/view.gno +++ b/examples/gno.land/p/demo/boardsv2/post/view.gno @@ -1 +1 @@ -package post \ No newline at end of file +package post diff --git a/examples/gno.land/r/demo/boardsv2/boardsv2.gno b/examples/gno.land/r/demo/boardsv2/boardsv2.gno index 4ad3d4662723..4205c210da54 100644 --- a/examples/gno.land/r/demo/boardsv2/boardsv2.gno +++ b/examples/gno.land/r/demo/boardsv2/boardsv2.gno @@ -1 +1,44 @@ -package boardsv2 \ No newline at end of file +package boardsv2 + +import "gno.land/p/demo/avl" + +// TODO: This goes in the realm +// type Boards struct { +// // TODO: Define how do we want to display and sort boards and posts (upvotes, pinned, ...) +// boards avl.Tree +// Title string +// Description string +// } + +func Render(path string) string { + // TODO: Implement render + return "" +} + +// TODO: Define public API + +func CreateBoard() {} // Maybe +func EditBoard() {} // Maybe +func ForkBoard() {} // Maybe + +func CreatePost() {} +func EditPost() {} +func ForkPost() {} +func DeletePost() {} +func Repost() {} +func Pin() {} +func Invite() {} // Maybe: Could also rely on an allow list +func UpVote() {} +func DownVote() {} + +func Comment() {} // Maybe +func EditComment() {} // Maybe +func DeleteComment() {} // Maybe + +func ToggleCommentsSupport() {} // Maybe +func ToggleThreadsSupport() {} // Maybe +func GetTags() {} // Maybe: List of allowed tags (moderated) + +func AddModerator() {} // Maybe +func RemoveModerator() {} // Maybe +func GetModerators() {} // Maybe