From 295fedef80ffe6b3f6afb6e9aeffad469c0e8da0 Mon Sep 17 00:00:00 2001 From: alex wennerberg Date: Wed, 31 Jul 2024 09:56:54 -0400 Subject: [PATCH] begin with replies --- TODO | 2 -- markdown.go | 4 ++-- views/new-post.html | 2 +- views/thread.html | 4 ++-- web.go | 12 ++++++++++-- 5 files changed, 15 insertions(+), 9 deletions(-) diff --git a/TODO b/TODO index dc7d3e1..c6b0167 100644 --- a/TODO +++ b/TODO @@ -5,8 +5,6 @@ RESEARCH: FEATURES: consider htmx -user profile should be /u/{profile} not id -4chan style replies minor/bugs: rate limit registration diff --git a/markdown.go b/markdown.go index 80894d4..17448f7 100644 --- a/markdown.go +++ b/markdown.go @@ -19,7 +19,7 @@ func (p Post) Render() template.HTML { // #post -> post func (p Post) BuildReply() string { - // naive solution: prefix everything? - // User [@username](/u/username) wrote ... + // naive solution: prefix everything with '> ' + // User [@username](/u/username) wrote in [#n](/post/n)... return p.Content } diff --git a/views/new-post.html b/views/new-post.html index c32e6df..65ebd9f 100644 --- a/views/new-post.html +++ b/views/new-post.html @@ -7,7 +7,7 @@

-
+
gemtext guide
diff --git a/views/thread.html b/views/thread.html index 2f4ae9f..6023d80 100644 --- a/views/thread.html +++ b/views/thread.html @@ -1,7 +1,7 @@ {{ template "header.html" . }}
{{ if or (not .Thread.Locked) (.User.Role.ModLevel) }} - + {{ end }} {{ template "pagelist.html" . }}
@@ -35,7 +35,7 @@ {{ .Render }}
+ {{ end }} {{ $pages := pageArr .ItemCount }} diff --git a/web.go b/web.go index f37366c..9b8b5ee 100644 --- a/web.go +++ b/web.go @@ -149,12 +149,20 @@ func newThreadPage(w http.ResponseWriter, r *http.Request) { func newPostPage(w http.ResponseWriter, r *http.Request) { tmpl := make(map[string]any) - tid, _ := strconv.Atoi(r.URL.Query().Get("threadid")) + tid, _ := strconv.Atoi(r.URL.Query().Get("thread")) + inReplyTo, _ := strconv.Atoi(r.URL.Query().Get("reply")) + thread, err := getThread(tid) if err != nil { serverError(w, r, err) return } + if inReplyTo != 0 { + post, err := getPost(inReplyTo) + if err == nil { + tmpl["Content"] = post.BuildReply() + } + } tmpl["Thread"] = thread tmpl["Forum"], err = getForum(thread.ForumID) if err != nil { @@ -170,7 +178,7 @@ func createNewPost(w http.ResponseWriter, r *http.Request) { if !postValid(content) { return // TODO 4xx } - tid, _ := strconv.Atoi(r.URL.Query().Get("threadid")) + tid, _ := strconv.Atoi(r.URL.Query().Get("thread")) thread, _ := getThread(tid) if thread.Locked && !u.Role.ModLevel() { // can't post in locked thread -- 2.45.2