Skip to content Search Apps Documentation Source Content Run Reset Eval Playground File Folder Download Copy Actions State String Boolean Number Struct Map Slice Pointer Function Closure Reference Nil Package Type Interface Unknown

uris_post.gno

1.67 Kb · 72 lines
 1package boards2
 2
 3import (
 4	"gno.land/p/gnoland/boards/v0"
 5)
 6
 7func makeThreadURI(p *boards.Post) string {
 8	if boards.IsThread(p) {
 9		return makeBoardURI(p.Board) + "/" + p.ID.String()
10	}
11
12	// When post is a reply use the parent thread ID
13	return makeBoardURI(p.Board) + "/" + p.ThreadID.String()
14}
15
16// makeThreadFlatURI links to the thread's flat "all comments" view. Works for
17// a thread or any reply within it (makeThreadURI resolves to the thread).
18func makeThreadFlatURI(p *boards.Post) string {
19	return makeThreadURI(p) + "?flat=1"
20}
21
22func makeReplyURI(p *boards.Post) string {
23	return makeBoardURI(p.Board) + "/" + p.ThreadID.String() + "/" + p.ID.String()
24}
25
26func makeCreateReplyURI(p *boards.Post) string {
27	if boards.IsThread(p) {
28		return makeThreadURI(p) + "/reply"
29	}
30	return makeReplyURI(p) + "/reply"
31}
32
33func makeCreateRepostURI(p *boards.Post) string {
34	return makeThreadURI(p) + "/repost"
35}
36
37func makeDeletePostURI(p *boards.Post) string {
38	if boards.IsThread(p) {
39		return RealmLink.Call(
40			"DeleteThread",
41			"boardID", p.Board.ID.String(),
42			"threadID", p.ThreadID.String(),
43		)
44	}
45	return RealmLink.Call(
46		"DeleteReply",
47		"boardID", p.Board.ID.String(),
48		"threadID", p.ThreadID.String(),
49		"replyID", p.ID.String(),
50	)
51}
52
53func makeEditPostURI(p *boards.Post) string {
54	if boards.IsThread(p) {
55		return makeThreadURI(p) + "/edit"
56	}
57	return makeReplyURI(p) + "/edit"
58}
59
60func makeFlagURI(p *boards.Post) string {
61	if boards.IsThread(p) {
62		return makeThreadURI(p) + "/flag"
63	}
64	return makeReplyURI(p) + "/flag"
65}
66
67func makeFlaggingReasonsURI(p *boards.Post) string {
68	if boards.IsThread(p) {
69		return makeThreadURI(p) + "/flagging-reasons"
70	}
71	return makeReplyURI(p) + "/flagging-reasons"
72}