inbox/profile: dont fetch comment replies when voting, show my votes, retain context link on vote. fixes #90

This commit is contained in:
Ryan Stafford 2024-04-16 19:40:37 -04:00
parent 73c0e2aa83
commit ed67986a0f
2 changed files with 24 additions and 1 deletions

View file

@ -1329,7 +1329,12 @@ func UserOp(w http.ResponseWriter, r *http.Request, ps httprouter.Params) {
state.Client.LikeComment(context.Background(), post) state.Client.LikeComment(context.Background(), post)
if r.FormValue("xhr") != "" { if r.FormValue("xhr") != "" {
state.XHR = true state.XHR = true
state.GetComment(commentid) if r.URL.Path == "/inbox" || r.URL.Path[:3] == "/u/" {
state.Query = "show context link"
state.GetSingleComment(commentid)
} else {
state.GetComment(commentid)
}
Render(w, "index.html", state) Render(w, "index.html", state)
return return
} }

View file

@ -298,6 +298,23 @@ func (state *State) GetSite() {
}) })
} }
func (state *State) GetSingleComment(commentid int64) {
state.CommentID = commentid
cresp, err := state.Client.Comment(context.Background(), lemmy.GetComment{
ID: commentid,
})
if err != nil {
fmt.Println(err)
state.Status = http.StatusInternalServerError
return
}
state.Comments = []Comment{Comment{
P: cresp.CommentView,
State: state,
Op: state.Op,
}}
}
func (state *State) GetComment(commentid int64) { func (state *State) GetComment(commentid int64) {
if state.Sort != "Hot" && state.Sort != "Top" && state.Sort != "Old" && state.Sort != "New" { if state.Sort != "Hot" && state.Sort != "Top" && state.Sort != "Old" && state.Sort != "New" {
state.Sort = "Hot" state.Sort = "Hot"
@ -449,6 +466,7 @@ func (state *State) GetMessages() {
Creator: m.Creator, Creator: m.Creator,
Community: m.Community, Community: m.Community,
Counts: m.Counts, Counts: m.Counts,
MyVote: m.MyVote,
}, },
Op: unread, Op: unread,
State: state, State: state,