Skip to content

Commit

Permalink
chore: address jeronimoalbi complaints
Browse files Browse the repository at this point in the history
  • Loading branch information
x1unix committed Jan 7, 2025
1 parent 5a8ea89 commit 73d1973
Show file tree
Hide file tree
Showing 5 changed files with 18 additions and 11 deletions.
3 changes: 2 additions & 1 deletion examples/gno.land/r/demo/boards2/post.gno
Original file line number Diff line number Diff line change
Expand Up @@ -119,7 +119,7 @@ func (post *Post) SetVisible(isVisible bool) {
post.isHidden = !isVisible
}

func (post *Post) Hidden() bool {
func (post *Post) IsHidden() bool {
return post.isHidden
}

Expand Down Expand Up @@ -300,6 +300,7 @@ func (post *Post) Render(indent string, levels int) string {
post.replies.Iterate("", "", func(_ string, value interface{}) bool {
reply := value.(*Post)
if reply.isHidden {
// TODO: change this in case of pagination
return false
}

Expand Down
6 changes: 3 additions & 3 deletions examples/gno.land/r/demo/boards2/post_test.gno
Original file line number Diff line number Diff line change
Expand Up @@ -35,13 +35,13 @@ func TestPostAddFlag(t *testing.T) {

func TestPostSetVisible(t *testing.T) {
post := createTestThread(t)
uassert.False(t, post.Hidden(), "post should be visible by default")
uassert.False(t, post.IsHidden(), "post should be visible by default")

post.SetVisible(false)
uassert.True(t, post.Hidden(), "post should be hidden")
uassert.True(t, post.IsHidden(), "post should be hidden")

post.SetVisible(true)
uassert.False(t, post.Hidden(), "post should be visible")
uassert.False(t, post.IsHidden(), "post should be visible")
}

func TestPostAddRepostTo(t *testing.T) {
Expand Down
12 changes: 9 additions & 3 deletions examples/gno.land/r/demo/boards2/public.gno
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,7 @@ func CreateReply(bid BoardID, threadID, replyID PostID, body string) PostID {
} else {
// Try to get parent reply and add a new child reply
post := mustGetReply(thread, replyID)
assertThreadVisible(thread)
assertReplyVisible(post)

reply = post.AddReply(caller, body)
}
Expand All @@ -99,7 +99,7 @@ func FlagReply(bid BoardID, threadID, replyID PostID, reason string) {
thread := mustGetThread(board, threadID)
reply := mustGetReply(thread, replyID)

if flagItem(reply, NewFlag(caller, reason)) {
if hide := flagItem(reply, NewFlag(caller, reason)); hide {
reply.SetVisible(false)
}
}
Expand Down Expand Up @@ -250,7 +250,13 @@ func assertReplyExists(thread *Post, replyID PostID) {
}

func assertThreadVisible(thread *Post) {
if thread.Hidden() {
if thread.IsHidden() {
panic("thread with ID: " + thread.GetPostID().String() + " was hidden")
}
}

func assertReplyVisible(thread *Post) {
if thread.IsHidden() {
panic("reply with ID: " + thread.GetPostID().String() + " was hidden")
}
}
6 changes: 3 additions & 3 deletions examples/gno.land/r/demo/boards2/render.gno
Original file line number Diff line number Diff line change
Expand Up @@ -60,8 +60,8 @@ func renderThread(res *mux.ResponseWriter, req *mux.Request) {
thread, found := board.GetThread(PostID(tID))
if !found {
res.Write("Thread does not exist with ID: " + rawID)
} else if thread.Hidden() {
res.Write("Thread with ID: " + rawID + " was hidden")
} else if thread.IsHidden() {
res.Write("Thread with ID: " + rawID + " has been flagged as inappropriate")
} else {
res.Write(thread.Render("", 5))
}
Expand Down Expand Up @@ -99,7 +99,7 @@ func renderReply(res *mux.ResponseWriter, req *mux.Request) {
reply, found := thread.GetReply(PostID(rID))
if !found {
res.Write("Reply does not exist with ID: " + rawID)
} else if reply.Hidden() {
} else if reply.IsHidden() {
res.Write("Reply with ID: " + rawID + " was hidden")
} else {
res.Write(reply.RenderInner())
Expand Down
2 changes: 1 addition & 1 deletion examples/gno.land/r/demo/boards2/z_2_c_filetest.gno
Original file line number Diff line number Diff line change
Expand Up @@ -23,4 +23,4 @@ func main() {
}

// Error:
// thread with ID: 2 was hidden
// reply with ID: 2 was hidden

0 comments on commit 73d1973

Please sign in to comment.