-
Notifications
You must be signed in to change notification settings - Fork 373
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
These changes were done before the change of direction for the boards implementation. Commiting them to avoid loosing the ideas and improvements present here.
- Loading branch information
1 parent
cecf7a8
commit 0f48ffb
Showing
10 changed files
with
252 additions
and
52 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
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
47 changes: 47 additions & 0 deletions
47
examples/gno.land/p/demo/boardsv2/draft3/post/plugin/fork/fork.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,47 @@ | ||
package pluginfork | ||
|
||
import ( | ||
"gno.land/p/demo/boards/post" | ||
) | ||
|
||
const Name = "fork" | ||
|
||
// TODO: Implement fork plugin to support thread forking | ||
type Plugin struct { | ||
AllowedPostLevels []int | ||
} | ||
|
||
func New(o ...Option) Plugin { | ||
var p Plugin | ||
for _, apply := range o { | ||
apply(&p) | ||
} | ||
return p | ||
} | ||
|
||
func (p Plugin) Name() string { | ||
return Name | ||
} | ||
|
||
func (p Plugin) Render() string { | ||
// TODO: Implement render support for text | ||
return "" | ||
} | ||
|
||
func (p Plugin) HasForkSupport(pst *post.Post) bool { | ||
if len(p.AllowedPostLevels) == 0 { | ||
return true | ||
} | ||
|
||
for _, lvl := range p.AllowedPostLevels { | ||
if pst.Level == lvl { | ||
return true | ||
} | ||
} | ||
return false | ||
} | ||
|
||
func (p Plugin) Fork(pst *post.Post, newPath string) error { | ||
// TODO: Implement fork support | ||
return nil | ||
} |
9 changes: 9 additions & 0 deletions
9
examples/gno.land/p/demo/boardsv2/draft3/post/plugin/fork/options.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,9 @@ | ||
package pluginfork | ||
|
||
type Option func(*Plugin) | ||
|
||
func AllowedPostLevels(levels []int) Option { | ||
return func(p *Plugin) { | ||
p.AllowedPostLevels = levels | ||
} | ||
} |
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
58 changes: 58 additions & 0 deletions
58
examples/gno.land/p/demo/boardsv2/draft3/post/plugin/reputation/store.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,58 @@ | ||
package pluginreputation | ||
|
||
import ( | ||
"gno.land/p/demo/seqid" | ||
) | ||
|
||
type ( | ||
VotesIterFn = func(votes uint64, path string) bool | ||
|
||
Store struct { | ||
votes avl.Tree // string(count) -> string(path) | ||
} | ||
) | ||
|
||
func (s Store) Iterate(fn VotesIterFn) bool { | ||
// TODO: Support pagination of votes? | ||
return s.votes.Iterate("", "", func(key string, v interface{}) bool { | ||
count, _ := seqid.FromBinary(key) | ||
return fn(uint64(count), v.(string)) | ||
}) | ||
} | ||
|
||
func (s *Store) inc(path string) uint64 { | ||
var ( | ||
current seqid.ID | ||
v, found = s.votes.Get(path) | ||
) | ||
if found { | ||
current = v.(seqid.ID) | ||
// TODO: Implement the right solution because this is not right, just showcase | ||
s.votes.Remove(current.Binary()) | ||
} | ||
|
||
current.Next() | ||
s.votes.Set(current.Binary(), path) | ||
return uint64(current) | ||
} | ||
|
||
func (s *Store) dec(path string) uint64 { | ||
var ( | ||
current seqid.ID | ||
v, found = s.votes.Get(path) | ||
) | ||
if found { | ||
current = v.(seqid.ID) | ||
} | ||
|
||
if current == 0 { | ||
return current | ||
} | ||
|
||
s.votes.Remove(current.Binary()) | ||
current-- | ||
if current != 0 { | ||
s.votes.Set(current.Binary(), current) | ||
} | ||
return uint64(current) | ||
} |
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
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
Oops, something went wrong.