From 5d778161ecb5fe77d3cc49d1a0d0981aadbe8cb9 Mon Sep 17 00:00:00 2001 From: Ryan Stafford Date: Thu, 20 Jul 2023 19:36:12 -0400 Subject: [PATCH] mark post read. fixes #20 --- public/utils.js | 4 ++++ routes.go | 16 ++++++++++++++++ templates/frontpage.html | 2 +- templates/main.html | 2 +- templates/post.html | 13 ++++++++++++- 5 files changed, 34 insertions(+), 3 deletions(-) diff --git a/public/utils.js b/public/utils.js index ae67624..48a1e87 100644 --- a/public/utils.js +++ b/public/utils.js @@ -223,6 +223,10 @@ function formSubmit(e) { e.submitter.disabled = "disabled" request(targ.target, params, function(res){ + if (data.get("op") == "read_post") { + document.getElementById("p"+data.get("postid")).remove() + return + } targ.outerHTML = res setup() }, diff --git a/routes.go b/routes.go index b3cec93..88b5371 100644 --- a/routes.go +++ b/routes.go @@ -1102,6 +1102,22 @@ func UserOp(w http.ResponseWriter, r *http.Request, ps httprouter.Params) { r.URL.Path = "/" + state.Host + "/c/" + resp.PostView.Community.Name r.URL.RawQuery = "" } + case "read_post": + postid, _ := strconv.Atoi(r.FormValue("postid")) + post := types.MarkPostAsRead{ + PostID: postid, + Read: true, + } + if r.FormValue("submit") == "mark unread" { + post.Read = false + } + _, err := state.Client.MarkPostAsRead(context.Background(), post) + if err != nil { + fmt.Println(err) + } else if r.FormValue("xhr") != "" { + w.Write([]byte{}) + return + } case "vote_post": var score int16 score = 1 diff --git a/templates/frontpage.html b/templates/frontpage.html index ac291fd..7ca8f0a 100644 --- a/templates/frontpage.html +++ b/templates/frontpage.html @@ -59,6 +59,6 @@ {{ template "sidebar.html" . }} {{ end }} - + diff --git a/templates/main.html b/templates/main.html index 5cf680d..2b58c48 100644 --- a/templates/main.html +++ b/templates/main.html @@ -139,7 +139,7 @@ {{ end }} {{ end }} - + {{ template "sidebar.html" . }} {{ end }} diff --git a/templates/post.html b/templates/post.html index a404d4c..a562c4c 100644 --- a/templates/post.html +++ b/templates/post.html @@ -1,5 +1,5 @@ {{ if and (ne .State.Op "vote_post") (ne .State.Op "save_post") }} -
+
{{ if gt .Rank 0 }}
{{ .Rank }}
{{ end }} @@ -91,6 +91,17 @@ {{ if .State.PostID }} hide all child comments {{ end }} + {{ if and .State.Site .State.Site.MyUser.IsValid (not .State.Site.MyUser.MustValue.LocalUserView.LocalUser.ShowReadPosts) }} + + {{ end }}