-
Notifications
You must be signed in to change notification settings - Fork 378
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
wip: defining a simple package API for creating posts
Co-authored-by: İlker G. Öztürk <[email protected]>
- Loading branch information
1 parent
baf9821
commit be049e7
Showing
11 changed files
with
277 additions
and
4 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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) { | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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 { | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1 +1,7 @@ | ||
package boardsv2 | ||
// 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 | ||
|
||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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 {} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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 { | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
package post | ||
|
||
type Content interface { | ||
Render() string | ||
} |
30 changes: 30 additions & 0 deletions
30
examples/gno.land/p/demo/boardsv2/post/plugins/content/content.gno
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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 | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1 +1,90 @@ | ||
package post | ||
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 { | ||
// | ||
// } |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
package post | ||
|
||
type Storage interface { | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1 +1 @@ | ||
package post | ||
package post |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1 +1,44 @@ | ||
package boardsv2 | ||
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 |