-
Notifications
You must be signed in to change notification settings - Fork 379
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix(r/demo/boards): correctly render reposts (#1530)
r/demo/boards already implements the data structures for reposts and the API function [CreateRepost](https://github.com/gnolang/gno/blob/a1c9a8c142038a9624a035262b899a24e16ff3cd/examples/gno.land/r/demo/boards/public.gno#L87). But the Render display doesn't handle reposts correctly. I did a repost on test3 with: ``` gnokey maketx call -pkgpath "gno.land/r/demo/boards" -func "CreateRepost" -gas-fee 1000000ugnot -gas-wanted 5000000 -send "" -broadcast -chainid "test3" -args "1" -args "2" -args "" -args "check out this NFT post" -args "3" -remote "test3.gno.land:36657" jefft0 ``` This should display on board number 3 "boardtest". https://test3.gno.land/r/demo/boards:boardtest . Indeed, it shows ``` check out this NFT post - @jefft0, 2024-01-12 4:24pm UTC [x] (0 replies) ``` But when I click on the date to see the post, [the page](https://test3.gno.land/r/demo/boards:boardtest/2/2) shows "reply does not exist with id: 2" because Render incorrectly treats a repost as a reply. This pull request is one approach to displaying reposts. It has three commits. The first commit adds `GetRepostFormURL` (similar to `GetReplyFormURL`) and updates `RenderPost` with a helper for [repost] (similar to [reply]). It also updates `RenderSummary` to check if the post is a repost and displays the reposted post along with the comment for the repost, and an indicator like "(2 reposts)". With this change, it shows something like the following where "mytitle" is the title of the original post with its body. ![Screenshot 2024-01-12 at 17 50 19](https://github.com/gnolang/gno/assets/1999543/48c0ec39-3716-45e4-b20d-bc01b900ea8f) The second commit updates existing tests to have the correct expected output. The third commit adds a tests for `CreateRepost` with an expected output and errors. (Why did we bother with fixing reposts? Because we implemented reposts in GnoSocial which is a modification of r/demo/boards. Since we fixed this in GnoSocial it's easy to contribute the same fix here, and maybe get some good feedback on the approach.) <details><summary>Contributors' checklist...</summary> - [x] Added new tests, or not needed, or not feasible - [x] No breaking changes were made, or a `BREAKING CHANGE: xxx` message was included in the description --------- Signed-off-by: Jeff Thompson <jeff@thefirst.org>
- Loading branch information
Showing
18 changed files
with
185 additions
and
17 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
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
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
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,32 @@ | ||
// PKGPATH: gno.land/r/boards_test | ||
package boards_test | ||
|
||
// SEND: 200000000ugnot | ||
|
||
import ( | ||
"std" | ||
|
||
"gno.land/p/demo/testutils" | ||
"gno.land/r/demo/boards" | ||
"gno.land/r/demo/users" | ||
) | ||
|
||
func main() { | ||
users.Register("", "gnouser", "my profile") | ||
// create a post via registered user | ||
bid1 := boards.CreateBoard("test_board1") | ||
pid := boards.CreateThread(bid1, "First Post (title)", "Body of the first post. (body)") | ||
bid2 := boards.CreateBoard("test_board2") | ||
|
||
// create a repost via anon user | ||
test2 := testutils.TestAddress("test2") | ||
std.TestSetOrigCaller(test2) | ||
std.TestSetOrigSend(std.Coins{{"ugnot", 9000000}}, nil) | ||
|
||
rid := boards.CreateRepost(bid1, pid, "", "Check this out", bid2) | ||
println(rid) | ||
println(boards.Render("test_board1")) | ||
} | ||
|
||
// Error: | ||
// please register, otherwise minimum fee 100000000 is required if anonymous |
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,24 @@ | ||
// PKGPATH: gno.land/r/boards_test | ||
package boards_test | ||
|
||
// SEND: 200000000ugnot | ||
|
||
import ( | ||
"gno.land/r/demo/boards" | ||
"gno.land/r/demo/users" | ||
) | ||
|
||
func main() { | ||
users.Register("", "gnouser", "my profile") | ||
bid1 := boards.CreateBoard("test_board1") | ||
pid := boards.CreateThread(bid1, "First Post (title)", "Body of the first post. (body)") | ||
bid2 := boards.CreateBoard("test_board2") | ||
|
||
// create a repost to a non-existing board | ||
rid := boards.CreateRepost(5, pid, "", "Check this out", bid2) | ||
println(rid) | ||
println(boards.Render("test_board1")) | ||
} | ||
|
||
// Error: | ||
// src board not exist |
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,24 @@ | ||
// PKGPATH: gno.land/r/boards_test | ||
package boards_test | ||
|
||
// SEND: 200000000ugnot | ||
|
||
import ( | ||
"gno.land/r/demo/boards" | ||
"gno.land/r/demo/users" | ||
) | ||
|
||
func main() { | ||
users.Register("", "gnouser", "my profile") | ||
bid1 := boards.CreateBoard("test_board1") | ||
boards.CreateThread(bid1, "First Post (title)", "Body of the first post. (body)") | ||
bid2 := boards.CreateBoard("test_board2") | ||
|
||
// create a repost to a non-existing thread | ||
rid := boards.CreateRepost(bid1, 5, "", "Check this out", bid2) | ||
println(rid) | ||
println(boards.Render("test_board1")) | ||
} | ||
|
||
// Error: | ||
// thread not exist |
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,24 @@ | ||
// PKGPATH: gno.land/r/boards_test | ||
package boards_test | ||
|
||
// SEND: 200000000ugnot | ||
|
||
import ( | ||
"gno.land/r/demo/boards" | ||
"gno.land/r/demo/users" | ||
) | ||
|
||
func main() { | ||
users.Register("", "gnouser", "my profile") | ||
bid1 := boards.CreateBoard("test_board1") | ||
pid := boards.CreateThread(bid1, "First Post (title)", "Body of the first post. (body)") | ||
boards.CreateBoard("test_board2") | ||
|
||
// create a repost to a non-existing destination board | ||
rid := boards.CreateRepost(bid1, pid, "", "Check this out", 5) | ||
println(rid) | ||
println(boards.Render("test_board1")) | ||
} | ||
|
||
// Error: | ||
// dst board not exist |
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,40 @@ | ||
// PKGPATH: gno.land/r/boards_test | ||
package boards_test | ||
|
||
// SEND: 200000000ugnot | ||
|
||
import ( | ||
"gno.land/r/demo/boards" | ||
"gno.land/r/demo/users" | ||
) | ||
|
||
var ( | ||
bid1 boards.BoardID | ||
bid2 boards.BoardID | ||
pid boards.PostID | ||
) | ||
|
||
func init() { | ||
users.Register("", "gnouser", "my profile") | ||
|
||
bid1 = boards.CreateBoard("test_board1") | ||
pid = boards.CreateThread(bid1, "First Post (title)", "Body of the first post. (body)") | ||
bid2 = boards.CreateBoard("test_board2") | ||
} | ||
|
||
func main() { | ||
rid := boards.CreateRepost(bid1, pid, "", "Check this out", bid2) | ||
println(rid) | ||
println(boards.Render("test_board2")) | ||
} | ||
|
||
// Output: | ||
// 1 | ||
// \[[post](/r/demo/boards?help&__func=CreateThread&bid=2&body.type=textarea)] | ||
// | ||
// ---------------------------------------- | ||
// Repost: Check this out | ||
// ## [First Post (title)](/r/demo/boards:test_board1/1) | ||
// | ||
// Body of the first post. (body) | ||
// \- [@gnouser](/r/demo/users:gnouser), [2009-02-13 11:31pm UTC](/r/demo/boards:test_board1/1) \[[x](/r/demo/boards?help&__func=DeletePost&bid=1&threadid=1&postid=1)] (0 replies) (1 reposts) |
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
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
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
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