Skip to content

Commit

Permalink
wip: defining a simple package API for creating posts
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 Oct 4, 2024
1 parent baf9821 commit be049e7
Show file tree
Hide file tree
Showing 11 changed files with 277 additions and 4 deletions.
35 changes: 35 additions & 0 deletions examples/gno.land/p/demo/boardsv2/app.gno
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) {

}
20 changes: 20 additions & 0 deletions examples/gno.land/p/demo/boardsv2/board.gno
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 {

}
8 changes: 7 additions & 1 deletion examples/gno.land/p/demo/boardsv2/boardsv2.gno
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


11 changes: 11 additions & 0 deletions examples/gno.land/p/demo/boardsv2/option.gno
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 {}
30 changes: 30 additions & 0 deletions examples/gno.land/p/demo/boardsv2/post.gno
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 {

}
5 changes: 5 additions & 0 deletions examples/gno.land/p/demo/boardsv2/post/content.gno
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 examples/gno.land/p/demo/boardsv2/post/plugins/content/content.gno
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
}
}
91 changes: 90 additions & 1 deletion examples/gno.land/p/demo/boardsv2/post/post.gno
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 {
//
// }
4 changes: 4 additions & 0 deletions examples/gno.land/p/demo/boardsv2/post/storage.gno
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
package post

type Storage interface {
}
2 changes: 1 addition & 1 deletion examples/gno.land/p/demo/boardsv2/post/view.gno
Original file line number Diff line number Diff line change
@@ -1 +1 @@
package post
package post
45 changes: 44 additions & 1 deletion examples/gno.land/r/demo/boardsv2/boardsv2.gno
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

0 comments on commit be049e7

Please sign in to comment.