mark post read. fixes #20

This commit is contained in:
Ryan Stafford 2023-07-20 19:36:12 -04:00
parent 1eec1a7274
commit 5d778161ec
5 changed files with 34 additions and 3 deletions

View file

@ -223,6 +223,10 @@ function formSubmit(e) {
e.submitter.disabled = "disabled" e.submitter.disabled = "disabled"
request(targ.target, params, request(targ.target, params,
function(res){ function(res){
if (data.get("op") == "read_post") {
document.getElementById("p"+data.get("postid")).remove()
return
}
targ.outerHTML = res targ.outerHTML = res
setup() setup()
}, },

View file

@ -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.Path = "/" + state.Host + "/c/" + resp.PostView.Community.Name
r.URL.RawQuery = "" 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": case "vote_post":
var score int16 var score int16
score = 1 score = 1

View file

@ -59,6 +59,6 @@
{{ template "sidebar.html" . }} {{ template "sidebar.html" . }}
</main> </main>
{{ end }} {{ end }}
<script src="/_/static/utils.js?v=19"></script> <script src="/_/static/utils.js?v=20"></script>
</body> </body>
</html> </html>

View file

@ -139,7 +139,7 @@
{{ end }} {{ end }}
{{ end }} {{ end }}
<script src="/_/static/utils.js?v=19"></script> <script src="/_/static/utils.js?v=20"></script>
{{ template "sidebar.html" . }} {{ template "sidebar.html" . }}
</main> </main>
{{ end }} {{ end }}

View file

@ -1,5 +1,5 @@
{{ if and (ne .State.Op "vote_post") (ne .State.Op "save_post") }} {{ if and (ne .State.Op "vote_post") (ne .State.Op "save_post") }}
<div class="post{{if .Post.Deleted}} deleted{{end}}{{ if .Post.FeaturedCommunity }} distinguished{{end}}{{if .Post.FeaturedLocal }} announcement{{end}}"> <div class="post{{if .Post.Deleted}} deleted{{end}}{{ if .Post.FeaturedCommunity }} distinguished{{end}}{{if .Post.FeaturedLocal }} announcement{{end}}" id="p{{.Post.ID}}">
{{ if gt .Rank 0 }} {{ if gt .Rank 0 }}
<div class="rank"> {{ .Rank }} </div> <div class="rank"> {{ .Rank }} </div>
{{ end }} {{ end }}
@ -91,6 +91,17 @@
{{ if .State.PostID }} {{ if .State.PostID }}
<a id="hidechildren" class="scripting" href="">hide all child comments</a> <a id="hidechildren" class="scripting" href="">hide all child comments</a>
{{ end }} {{ end }}
{{ if and .State.Site .State.Site.MyUser.IsValid (not .State.Site.MyUser.MustValue.LocalUserView.LocalUser.ShowReadPosts) }}
<form class="link-btn" method="POST">
<input type="hidden" name="postid" value="{{.Post.ID }}">
<input type="hidden" name="op" value="read_post">
{{ if .Post.Deleted }}
<input type="submit" name="submit" value="mark unread">
{{ else }}
<input type="submit" name="submit" value="mark read">
{{ end }}
</form>
{{ end }}
</div> </div>
</div> </div>
<div></div> <div></div>