From b46ec659fc84017412e01ca4cffdffb8c2e30205 Mon Sep 17 00:00:00 2001 From: Ryan Stafford Date: Mon, 3 Jul 2023 21:53:18 -0400 Subject: [PATCH 01/78] totp support --- go.mod | 2 +- go.sum | 2 ++ routes.go | 52 ++++++++++++++++++++++++++---------------- templates/login.html | 10 +++++++- templates/sidebar.html | 4 ++-- 5 files changed, 46 insertions(+), 24 deletions(-) diff --git a/go.mod b/go.mod index 88f3104..1f3e062 100644 --- a/go.mod +++ b/go.mod @@ -10,7 +10,7 @@ require ( github.com/gorilla/sessions v1.2.1 // indirect github.com/gorilla/websocket v1.4.2 // indirect github.com/julienschmidt/httprouter v1.3.0 // indirect - github.com/rystaf/go-lemmy v0.0.0-20230623191350-f39e3c8bdcb5 // indirect + github.com/rystaf/go-lemmy v0.0.0-20230704005320-c4b010dd339b // indirect github.com/yuin/goldmark v1.5.4 // indirect go.elara.ws/go-lemmy v0.17.3 // indirect golang.org/x/text v0.10.0 // indirect diff --git a/go.sum b/go.sum index 66acff2..fdda18e 100644 --- a/go.sum +++ b/go.sum @@ -29,6 +29,8 @@ github.com/rystaf/go-lemmy v0.0.0-20230623191111-7ff8c74b1935 h1:zmzUz6PGRB8yQTT github.com/rystaf/go-lemmy v0.0.0-20230623191111-7ff8c74b1935/go.mod h1:nRSkTD+ARAHXtqlSPdf5q3hjHLP1ALsS1m5D3o86o+4= github.com/rystaf/go-lemmy v0.0.0-20230623191350-f39e3c8bdcb5 h1:MoI87uid2KqpLdUMZGK2HBOuxJMnPOJaar/4Og2PshM= github.com/rystaf/go-lemmy v0.0.0-20230623191350-f39e3c8bdcb5/go.mod h1:nRSkTD+ARAHXtqlSPdf5q3hjHLP1ALsS1m5D3o86o+4= +github.com/rystaf/go-lemmy v0.0.0-20230704005320-c4b010dd339b h1:6z+gOUUvKwKQfgqEbxXS229gjr5V3HYg9bYbL9VHFdQ= +github.com/rystaf/go-lemmy v0.0.0-20230704005320-c4b010dd339b/go.mod h1:nRSkTD+ARAHXtqlSPdf5q3hjHLP1ALsS1m5D3o86o+4= github.com/yuin/goldmark v1.5.4 h1:2uY/xC0roWy8IBEGLgB1ywIoEJFGmRrX21YQcvGZzjU= github.com/yuin/goldmark v1.5.4/go.mod h1:6yULJ656Px+3vBD8DxQVa3kxgyrAnzto9xy5taEt/CY= go.elara.ws/go-lemmy v0.17.3 h1:644k23BS2xqKJHJ9cHd8eyt1INpb5myqsBQQL2chBiA= diff --git a/routes.go b/routes.go index 94253a8..dca64b9 100644 --- a/routes.go +++ b/routes.go @@ -510,6 +510,7 @@ func Settings(w http.ResponseWriter, r *http.Request, ps httprouter.Params) { func SignUpOrLogin(w http.ResponseWriter, r *http.Request, ps httprouter.Params) { state, err := Initialize(ps.ByName("host"), r) if err != nil { + fmt.Println(err) Render(w, "index.html", state) return } @@ -517,11 +518,19 @@ func SignUpOrLogin(w http.ResponseWriter, r *http.Request, ps httprouter.Params) var username string switch r.FormValue("submit") { case "log in": - resp, err := state.Client.Login(context.Background(), types.Login{ + login := types.Login{ UsernameOrEmail: r.FormValue("username"), Password: r.FormValue("password"), - }) + } + if r.FormValue("totp") != "" { + login.Totp2faToken = types.NewOptional(r.FormValue("totp")) + } + resp, err := state.Client.Login(context.Background(), login) if err != nil { + if strings.Contains(fmt.Sprintf("%v", err), "missing_totp_token") { + state.Op = "2fa" + } + fmt.Println(err) state.Error = err state.GetSite() state.GetCaptcha() @@ -577,13 +586,6 @@ func SignUpOrLogin(w http.ResponseWriter, r *http.Request, ps httprouter.Params) } } if token != "" { - if err != nil { - state.Error = err - state.GetSite() - state.GetCaptcha() - Render(w, "login.html", state) - return - } state.GetUser(username) setCookie(w, state.Host, "jwt", token) userid := strconv.Itoa(state.User.PersonView.Person.ID) @@ -671,18 +673,28 @@ func UserOp(w http.ResponseWriter, r *http.Request, ps httprouter.Params) { deleteCookie(w, state.Host, "jwt") deleteCookie(w, state.Host, "user") case "login": - resp, err := state.Client.Login(context.Background(), types.Login{ - UsernameOrEmail: r.FormValue("user"), - Password: r.FormValue("pass"), - }) - if err != nil { - state.Status = http.StatusUnauthorized + login := types.Login{ + UsernameOrEmail: r.FormValue("username"), + Password: r.FormValue("password"), } - if resp.JWT.IsValid() { - state.GetUser(r.FormValue("user")) - setCookie(w, state.Host, "jwt", resp.JWT.String()) - userid := strconv.Itoa(state.User.PersonView.Person.ID) - setCookie(w, state.Host, "user", state.User.PersonView.Person.Name+":"+userid) + if r.FormValue("totp") != "" { + login.Totp2faToken = types.NewOptional(r.FormValue("totp")) + } + resp, err := state.Client.Login(context.Background(), login) + if err != nil { + if strings.Contains(fmt.Sprintf("%v", err), "missing_totp_token") { + state.Op = "2fa" + Render(w, "login.html", state) + return + } + state.Status = http.StatusUnauthorized + } else if resp.JWT.IsValid() { + state.GetUser(r.FormValue("username")) + if state.User != nil { + setCookie(w, state.Host, "jwt", resp.JWT.String()) + userid := strconv.Itoa(state.User.PersonView.Person.ID) + setCookie(w, state.Host, "user", state.User.PersonView.Person.Name+":"+userid) + } } case "create_community": state.GetSite() diff --git a/templates/login.html b/templates/login.html index 78cc14a..700d16e 100644 --- a/templates/login.html +++ b/templates/login.html @@ -35,6 +35,7 @@
{{.Error}}
{{ end }}
+{{ if ne .Op "2fa" }}

create a new account

@@ -81,9 +82,10 @@
+{{ end }}

login

-
+ + {{ if eq .Op "2fa" }} + + {{ end }}
diff --git a/templates/sidebar.html b/templates/sidebar.html index ff2050a..8137b77 100644 --- a/templates/sidebar.html +++ b/templates/sidebar.html @@ -32,8 +32,8 @@ {{ if not .Session -}}
{{ end }} - + {{ template "sidebar.html" . }} From 6184bddd02f85454f84cd97178e2032baff48a07 Mon Sep 17 00:00:00 2001 From: Ryan Stafford Date: Wed, 5 Jul 2023 09:49:41 -0400 Subject: [PATCH 06/78] distinguished posts/comemnts, nsfw blue/warnings --- public/style.css | 57 +++++++++++++++++++++++++++++-- routes.go | 18 +++++++++- state.go | 1 + templates/comment.html | 2 +- templates/frontpage.html | 38 +++++++++++---------- templates/main.html | 72 +++++++++++++++++++++------------------- templates/post.html | 8 ++--- templates/settings.html | 1 + 8 files changed, 138 insertions(+), 59 deletions(-) diff --git a/public/style.css b/public/style.css index d9e612c..bce8885 100644 --- a/public/style.css +++ b/public/style.css @@ -24,6 +24,14 @@ code { .clearleft { clear: left; } +.img-blur { + filter: blur(10px); + -webkit-filter: blur(10px); + -moz-filter: blur(10px); + -o-filter: blur(10px); + -ms-filter: blur(10px); + transform: scale(1.03); +} .post { margin: 6px; } @@ -31,10 +39,16 @@ code { height: 52px; width: 70px; margin: 0px 4px; + position: relative; + overflow: hidden; + --background-color: #e7e7e7; +} +.post .thumb div { + height: 52px; + width: 70px; background-repeat: no-repeat; background-size: cover; background-position: center; - --background-color: #e7e7e7; } .rank { color: #c6c6c6; @@ -94,6 +108,10 @@ code { font-size: medium; text-decoration: none; } +.post.distinguished .title a { + color: #228822; + font-weight: bold; +} .dark .title a { color: #dedede; } @@ -207,6 +225,13 @@ code { border-radius: 3px; padding: 0px 2px; } +.comment .meta a.distinguished { + background-color: #228822; + color: white; + font-weight: bold; + border-radius: 3px; + padding: 0px 2px; +} .commentmenu { font-size: 16px; margin: 0px 0px 10px 10px; @@ -281,6 +306,31 @@ code { .left { float: left; } +span.nsfw { + color: #d10023; + font-size: 10px; + line-height: 14px; + border-radius:3px; + border: 1px solid #d10023; + padding: 0 4px; + display: inline-block; + font-weight: 400; +} +form.nsfw { + text-align: center; + margin: 50px auto; + width: 650px; + font-size: 18px; +} +form.nsfw div { + font-size: 40px; + background-color: #ff575b; + display: inline-block; + padding: 20px 10px; + border-radius: 50%; + font-weight: bold; + color: white; +} .gray { color: #808080; } @@ -843,13 +893,16 @@ form.create input[type=file], form.create select { content: "*"; color: red; } +.preferences { + margin: 20px; +} .preferences div { font-size: 13px; margin: 10px; } .preferences label{ display: inline-block; - width: 100px; + width: 120px; text-align: right; } diff --git a/routes.go b/routes.go index 166216e..6bfa4b5 100644 --- a/routes.go +++ b/routes.go @@ -170,6 +170,7 @@ func Initialize(Host string, r *http.Request) (State, error) { state.Listing = getCookie(r, "DefaultListingType") state.Sort = getCookie(r, "DefaultSortType") state.Dark = getCookie(r, "Dark") != "" + state.ShowNSFW = getCookie(r, "ShowNSFW") != "" state.ParseQuery(r.URL.RawQuery) if state.Sort == "" { state.Sort = "Hot" @@ -497,11 +498,19 @@ func Settings(w http.ResponseWriter, r *http.Request, ps httprouter.Params) { deleteCookie(w, state.Host, "Dark") state.Dark = false } + if r.FormValue("shownsfw") != "" { + setCookie(w, state.Host, "ShowNSFW", "1") + state.ShowNSFW = true + } else { + deleteCookie(w, state.Host, "ShowNSFW") + state.ShowNSFW = false + } state.Listing = r.FormValue("DefaultListingType") state.Sort = r.FormValue("DefaultSortType") + // TODO save user settings case "GET": if state.Session != nil { - // TODO fetch server settings + // TODO fetch user settings } } Render(w, "settings.html", state) @@ -540,6 +549,7 @@ func SignUpOrLogin(w http.ResponseWriter, r *http.Request, ps httprouter.Params) if resp.JWT.IsValid() { token = resp.JWT.String() username = r.FormValue("username") + deleteCookie(w, state.Host, "ShowNSFW") } case "sign up": register := types.Register{ @@ -959,6 +969,12 @@ func UserOp(w http.ResponseWriter, r *http.Request, ps httprouter.Params) { r.URL.Fragment = "c" + commentid r.URL.RawQuery = "" } + case "shownsfw": + if r.FormValue("submit") == "continue" { + setCookie(w, state.Host, "ShowNSFW", "1") + } else { + r.URL.Path = "/" + state.Host + } } http.Redirect(w, r, r.URL.String(), 301) } diff --git a/state.go b/state.go index c13966c..055ed6a 100644 --- a/state.go +++ b/state.go @@ -88,6 +88,7 @@ type State struct { SearchType string Captcha *types.CaptchaResponse Dark bool + ShowNSFW bool } func (p State) SortBy(v string) string { diff --git a/templates/comment.html b/templates/comment.html index a720562..0ad3b4a 100644 --- a/templates/comment.html +++ b/templates/comment.html @@ -21,7 +21,7 @@ [-] {{ end }} - {{fullname .P.Creator}} + {{fullname .P.Creator}} {{.P.Counts.Score}} points {{ humanize .P.Comment.Published.Time }} {{- if gt .P.Comment.Updated.Time.Unix .P.Comment.Published.Time.Unix -}} * (last edited {{ humanize .P.Comment.Updated.Time }}) diff --git a/templates/frontpage.html b/templates/frontpage.html index f067241..394c037 100644 --- a/templates/frontpage.html +++ b/templates/frontpage.html @@ -18,32 +18,36 @@ {{ template "nav.html" . -}} +{{ if and (not .ShowNSFW) .Community .Community.CommunityView.Community.NSFW }} + {{ template "nsfw.html" }} +{{ else }}
-{{ if or (contains .Sort "Top") (and (not .PostID) (not .User) (not .Community) (not .Activities) (eq .Op ""))}} - {{ template "menu.html" . }} -{{ end}} + {{ if or (contains .Sort "Top") (and (not .PostID) (not .User) (not .Community) (not .Activities) (eq .Op ""))}} + {{ template "menu.html" . }} + {{ end}} -{{ if .Error }} + {{ if .Error }}
{{.Error}}
-{{ end }} + {{ end }} -{{ range .Posts }} - {{ template "post.html" . }} -{{ end }} + {{ range .Posts }} + {{ template "post.html" . }} + {{ end }} -{{ if or (and (not .Op) (not .Activities) (not .Comments) (not .Posts) (not .Communities)) (and (not .Comments) .PostID) (and (not .Activities) (not .Query) .User) }} -
there doesn't seem to be anything here
-{{ end }} + {{ if or (and (not .Op) (not .Activities) (not .Comments) (not .Posts) (not .Communities)) (and (not .Comments) .PostID) (and (not .Activities) (not .Query) .User) }} +
there doesn't seem to be anything here
+ {{ end }} -{{ if or .Query (eq .SearchType "Communities") (eq (len .Posts) 25) (and .Comments (and (eq .CommentCount 200) (gt (index .Posts 0).Counts.Comments .CommentCount))) (and .User (or (gt .User.PersonView.Counts.CommentCount 10) (gt .User.PersonView.Counts.PostCount 10))) }} -
- view more: {{if gt .Page 1 }}‹ prev{{ end }} next › -
-{{ end }} + {{ if or .Query (eq .SearchType "Communities") (eq (len .Posts) 25) (and .Comments (and (eq .CommentCount 200) (gt (index .Posts 0).Counts.Comments .CommentCount))) (and .User (or (gt .User.PersonView.Counts.CommentCount 10) (gt .User.PersonView.Counts.PostCount 10))) }} +
+ view more: {{if gt .Page 1 }}‹ prev{{ end }} next › +
+ {{ end }} - {{ template "sidebar.html" . }} + {{ template "sidebar.html" . }}
+{{ end }} diff --git a/templates/main.html b/templates/main.html index 2abad3e..f7ad858 100644 --- a/templates/main.html +++ b/templates/main.html @@ -18,12 +18,15 @@ {{ template "nav.html" . -}} +{{ if and (not .ShowNSFW) .Community .Community.CommunityView.Community.NSFW }} + {{ template "nsfw.html" }} +{{ else }}
-{{ if or (contains .Sort "Top") (and (not .PostID) (not .User) (not .Community) (not .Activities) (eq .Op ""))}} + {{ if or (contains .Sort "Top") (and (not .PostID) (not .User) (not .Community) (not .Activities) (eq .Op ""))}} {{ template "menu.html" . }} -{{ end}} + {{ end}} -{{ if or (ne .Query "") .Communities }} + {{ if or (ne .Query "") .Communities }}
search
@@ -45,34 +48,34 @@ {{ end }} -{{ end}} + {{ end}} -{{ if .Error }} + {{ if .Error }}
{{.Error}}
-{{ end }} + {{ end }} -{{ range .Communities }} + {{ range .Communities }} {{ template "community.html" . }} -{{ end }} + {{ end }} -{{ if eq .Op "create_community" "edit_community" }} - {{ template "create_community.html" . }} -{{ end }} + {{ if eq .Op "create_community" "edit_community" }} + {{ template "create_community.html" . }} + {{ end }} -{{ range .Posts }} + {{ range .Posts }} {{ template "post.html" . }} -{{ end }} + {{ end }} -{{ if eq .Op "create_post" "edit_post" }} - {{ template "create_post.html" . }} -{{ end }} + {{ if eq .Op "create_post" "edit_post" }} + {{ template "create_post.html" . }} + {{ end }} -{{ if and .PostID .Posts}} - {{ if .CommentID}} + {{ if and .PostID .Posts}} + {{ if .CommentID}}
you are viewing a single comment's thread
view the rest of the comments
- {{ else }} + {{ else }}
{{if .Comments}}{{if gt .Page 1}}next{{else if or (lt .CommentCount 200) (lt (index .Posts 0).Counts.Comments .CommentCount) }}all{{else}}top{{end}} {{.CommentCount}} comments{{else}} no comments (yet){{end}}
@@ -83,7 +86,7 @@ old
- {{ if and .Session (ne .Op "edit_post") }} + {{ if and .Session (ne .Op "edit_post") }}
@@ -91,34 +94,35 @@ + {{ end }} {{ end }} - {{ end }} -{{ end}} + {{ end}} -{{ range $i, $comment := .Comments }} + {{ range $i, $comment := .Comments }} {{ template "comment.html" $comment }} -{{ end }} + {{ end }} -{{ if eq .Op "send_message" }} -{{ template "send_message.html" . }} -{{ else }} -{{ template "activities.html" . }} -{{ end }} + {{ if eq .Op "send_message" }} + {{ template "send_message.html" . }} + {{ else }} + {{ template "activities.html" . }} + {{ end }} -{{ if or (and (not .Op) (not .Activities) (not .Comments) (not .Posts) (not .Communities)) (and (not .Comments) .PostID) (and (not .Activities) (not .Query) .User) }} -
there doesn't seem to be anything here
-{{ end }} + {{ if or (and (not .Op) (not .Activities) (not .Comments) (not .Posts) (not .Communities)) (and (not .Comments) .PostID) (and (not .Activities) (not .Query) .User) }} +
there doesn't seem to be anything here
+ {{ end }} -{{ if or .Query (eq .SearchType "Communities") (eq (len .Posts) 25) (and .Comments (and (eq .CommentCount 200) (gt (index .Posts 0).Counts.Comments .CommentCount))) (and .User (or (gt .User.PersonView.Counts.CommentCount 10) (gt .User.PersonView.Counts.PostCount 10))) }} + {{ if or .Query (eq .SearchType "Communities") (eq (len .Posts) 25) (and .Comments (and (eq .CommentCount 200) (gt (index .Posts 0).Counts.Comments .CommentCount))) (and .User (or (gt .User.PersonView.Counts.CommentCount 10) (gt .User.PersonView.Counts.PostCount 10))) }}
view more: {{if gt .Page 1 }}‹ prev{{ end }} next ›
-{{ end }} + {{ end }} {{ template "sidebar.html" . }}
+{{ end }} diff --git a/templates/post.html b/templates/post.html index aeb7125..e52f5f6 100644 --- a/templates/post.html +++ b/templates/post.html @@ -1,5 +1,5 @@ {{ if not .State.XHR }} -
+
{{ if gt .Rank 0 }}
{{ .Rank }}
{{ end }} @@ -21,13 +21,12 @@ {{ end }} {{ if not .State.XHR}}
-
+
{{ .Post.Name }} ({{ domain . }})
-
submitted @@ -41,8 +40,9 @@ c/{{ fullcname .Community}}
+ {{ if .Post.NSFW }}NSFW{{end}} {{ .Counts.Comments }} comments - {{ if and .State.Session (eq .State.Session.UserID .Post.CreatorID) }} + {{ if and .State.Session (eq .State.Session.UserID .Post.CreatorID) }} {{ if not .Post.Deleted }}edit{{end}}
From 5a24937781c66849210da1443005492fcb3fe5e8 Mon Sep 17 00:00:00 2001 From: Ryan Stafford Date: Wed, 5 Jul 2023 10:20:07 -0400 Subject: [PATCH 07/78] comment/post saving. fixes #6 --- public/style.css | 4 ++-- public/utils.js | 2 +- routes.go | 26 +++++++++++++++++++++++++- state.go | 12 +++++++++--- templates/comment.html | 27 +++++++++++++++++++++------ templates/nav.html | 5 ++++- templates/post.html | 13 ++++++++++++- 7 files changed, 74 insertions(+), 15 deletions(-) diff --git a/public/style.css b/public/style.css index bce8885..bbf16b9 100644 --- a/public/style.css +++ b/public/style.css @@ -89,7 +89,7 @@ code { .dark .score form.link-btn input { color: #646464; } -.comment form.link-btn input { +.comment .score form.link-btn input { line-height: 17px; } .score form.like.link-btn input:first-child, .score .like div { @@ -386,7 +386,7 @@ form.nsfw div { border-left: 2px solid #c5c1ad; padding: 0 8px; } -.buttons a, .buttons form input { +.buttons a, .buttons form input, .comment .buttons form input { text-decoration: none; color: #888; padding-right: 4px; diff --git a/public/utils.js b/public/utils.js index a3e042b..f3b0be9 100644 --- a/public/utils.js +++ b/public/utils.js @@ -35,7 +35,7 @@ function commentClick(e) { e = e || window.event; var targ = e.currentTarget || e.srcElement || e; if (targ.nodeType == 3) targ = targ.parentNode; - if (e.target.name=="vote") { + if (e.target.name=="submit") { e.preventDefault() var form = e.target.parentNode if (form) { diff --git a/routes.go b/routes.go index 6bfa4b5..2f7c507 100644 --- a/routes.go +++ b/routes.go @@ -860,6 +860,30 @@ func UserOp(w http.ResponseWriter, r *http.Request, ps httprouter.Params) { state.Error = err fmt.Println(err) } + case "save_post": + postid, _ := strconv.Atoi(r.FormValue("postid")) + _, err := state.Client.SavePost(context.Background(), types.SavePost{ + PostID: postid, + Save: r.FormValue("submit") == "save", + }) + if err != nil { + fmt.Println(err) + } + case "save_comment": + commentid, _ := strconv.Atoi(r.FormValue("commentid")) + _, err := state.Client.SaveComment(context.Background(), types.SaveComment{ + CommentID: commentid, + Save: r.FormValue("submit") == "save", + }) + if err != nil { + fmt.Println(err) + } + if r.FormValue("xhr") != "" { + state.XHR = true + state.GetComment(commentid) + Render(w, "index.html", state) + return + } case "delete_post": postid, _ := strconv.Atoi(r.FormValue("postid")) post := types.DeletePost{ @@ -900,7 +924,7 @@ func UserOp(w http.ResponseWriter, r *http.Request, ps httprouter.Params) { case "vote_comment": var score int16 score = 1 - if r.FormValue("vote") != "▲" { + if r.FormValue("submit") != "▲" { score = -1 } if r.FormValue("undo") == strconv.Itoa(int(score)) { diff --git a/state.go b/state.go index 055ed6a..c7306b0 100644 --- a/state.go +++ b/state.go @@ -169,6 +169,11 @@ func (state *State) ParseQuery(RawQuery string) { if len(m["xhr"]) > 0 { state.XHR = true } + if len(m["view"]) > 0 { + if m["view"][0] == "Saved" { + state.Op = "Saved" + } + } //if len(m["op"]) > 0 { // state.Op = m["op"][0] //} @@ -363,9 +368,10 @@ func (state *State) GetUser(username string) { limit = 1 } resp, err := state.Client.PersonDetails(context.Background(), types.GetPersonDetails{ - Username: types.NewOptional(state.UserName), - Page: types.NewOptional(int64(state.Page)), - Limit: types.NewOptional(int64(limit)), + Username: types.NewOptional(state.UserName), + Page: types.NewOptional(int64(state.Page)), + Limit: types.NewOptional(int64(limit)), + SavedOnly: types.NewOptional(state.Op == "Saved"), }) if err != nil { fmt.Println(err) diff --git a/templates/comment.html b/templates/comment.html index 0ad3b4a..6a3f4ce 100644 --- a/templates/comment.html +++ b/templates/comment.html @@ -3,14 +3,14 @@ {{ if .State.Session }}
- +
{{ if .P.MyVote.IsValid}} {{ end}} - +
{{ end }} @@ -49,9 +49,8 @@ {{ else }}
  • hide source
  • {{ end }} - {{ if .State.Session }} - {{ if and (eq .P.Comment.CreatorID .State.Session.UserID) (ne .Op "edit")}} + {{ if and (eq .P.Comment.CreatorID .State.Session.UserID) (ne .Op "edit") }}
  • edit
  • @@ -61,8 +60,24 @@
  • {{ end }} - {{ if ne .Op "reply"}} -
  • reply
  • +
  • + +
  • + {{ if ne .Op "reply" }} +
  • + + reply + +
  • {{ end }} {{ end }} diff --git a/templates/nav.html b/templates/nav.html index e856413..ec1102e 100644 --- a/templates/nav.html +++ b/templates/nav.html @@ -48,7 +48,10 @@ {{ end }}
      {{ if .User }} -
    • overview
    • +
    • overview
    • + {{ if eq .User.PersonView.Person.ID .Session.UserID}} +
    • saved
    • + {{ end }} {{ else if .Comments -}}
    • comments
    • {{ else if .Activities }} diff --git a/templates/post.html b/templates/post.html index e52f5f6..aca7fc2 100644 --- a/templates/post.html +++ b/templates/post.html @@ -54,7 +54,18 @@ {{ end }} - {{ end}} + {{ end}} + {{ if .State.Session }} + + {{end}}
    {{ if (and .Post.Body.IsValid (ne .Post.Body.String "")) }} From f1f2305e8293f61b21382444fa70e3a961da1cb0 Mon Sep 17 00:00:00 2001 From: Ryan Stafford Date: Wed, 5 Jul 2023 11:00:14 -0400 Subject: [PATCH 08/78] fix youtube link false positive --- public/utils.js | 1 + templates/frontpage.html | 2 +- templates/main.html | 2 +- 3 files changed, 3 insertions(+), 2 deletions(-) diff --git a/public/utils.js b/public/utils.js index f3b0be9..ee63829 100644 --- a/public/utils.js +++ b/public/utils.js @@ -92,6 +92,7 @@ function formSubmit(e) { } function parse_youtube(url){ + if (url.indexOf("youtu") == -1) return false var regExp = /^.*(?:(?:youtu\.be\/|v\/|vi\/|u\/\w\/|embed\/|shorts\/)|(?:(?:watch)?\?v(?:i)?=|\&v(?:i)?=))([^#\&\?]*).*/; var match = url.match(regExp); if (match && match.length > 1) { diff --git a/templates/frontpage.html b/templates/frontpage.html index 394c037..f6b75d6 100644 --- a/templates/frontpage.html +++ b/templates/frontpage.html @@ -48,6 +48,6 @@ {{ template "sidebar.html" . }} {{ end }} - + diff --git a/templates/main.html b/templates/main.html index f7ad858..3672a19 100644 --- a/templates/main.html +++ b/templates/main.html @@ -120,7 +120,7 @@
    {{ end }} - + {{ template "sidebar.html" . }} {{ end }} From 3643600cab591286ec553575c85583b371c140e0 Mon Sep 17 00:00:00 2001 From: Ryan Stafford Date: Wed, 5 Jul 2023 11:01:10 -0400 Subject: [PATCH 09/78] rewrite relative links, linkify community bangs. fixes #9 --- routes.go | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/routes.go b/routes.go index 2f7c507..692a534 100644 --- a/routes.go +++ b/routes.go @@ -119,9 +119,13 @@ var funcMap = template.FuncMap{ converted := buf.String() converted = strings.Replace(converted, `!$1@$2 `) return template.HTML(converted) }, "contains": strings.Contains, @@ -830,6 +834,7 @@ func UserOp(w http.ResponseWriter, r *http.Request, ps httprouter.Params) { post := types.EditPost{ PostID: postid, Body: types.NewOptional(r.FormValue("body")), + Name: types.NewOptional(r.FormValue("name")), URL: types.NewOptional(r.FormValue("url")), } if r.FormValue("url") == "" { From 6e121dd63c2c5105de92357ae60fcb77cb6a5c7e Mon Sep 17 00:00:00 2001 From: Ryan Stafford Date: Wed, 5 Jul 2023 11:22:46 -0400 Subject: [PATCH 10/78] remove markdown from post titles --- go.mod | 1 + go.sum | 11 +++++++++++ routes.go | 14 +++++++++++++- templates/post.html | 2 +- 4 files changed, 26 insertions(+), 2 deletions(-) diff --git a/go.mod b/go.mod index 1f3e062..1eb85a5 100644 --- a/go.mod +++ b/go.mod @@ -10,6 +10,7 @@ require ( github.com/gorilla/sessions v1.2.1 // indirect github.com/gorilla/websocket v1.4.2 // indirect github.com/julienschmidt/httprouter v1.3.0 // indirect + github.com/k3a/html2text v1.2.1 // indirect github.com/rystaf/go-lemmy v0.0.0-20230704005320-c4b010dd339b // indirect github.com/yuin/goldmark v1.5.4 // indirect go.elara.ws/go-lemmy v0.17.3 // indirect diff --git a/go.sum b/go.sum index fdda18e..7dfa6d5 100644 --- a/go.sum +++ b/go.sum @@ -5,14 +5,18 @@ github.com/dustin/go-humanize v1.0.1/go.mod h1:Mu1zIs6XwVuF/gI1OepvI0qD18qycQx+m github.com/google/go-cmp v0.5.2/go.mod h1:v8dTdLbMG2kIc/vJvl+f65V22dbkXbowE6jgT/gNBxE= github.com/google/go-querystring v1.1.0 h1:AnCroh3fv4ZBgVIf1Iwtovgjaw/GiKJo8M8yD/fhyJ8= github.com/google/go-querystring v1.1.0/go.mod h1:Kcdr2DB4koayq7X8pmAG4sNG59So17icRSOU623lUBU= +github.com/gopherjs/gopherjs v0.0.0-20181017120253-0766667cb4d1/go.mod h1:wJfORRmW1u3UXTncJ5qlYoELFm8eSnnEO6hX4iZ3EWY= github.com/gorilla/securecookie v1.1.1 h1:miw7JPhV+b/lAHSXz4qd/nN9jRiAFV5FwjeKyCS8BvQ= github.com/gorilla/securecookie v1.1.1/go.mod h1:ra0sb63/xPlUeL+yeDciTfxMRAA+MP+HVt/4epWDjd4= github.com/gorilla/sessions v1.2.1 h1:DHd3rPN5lE3Ts3D8rKkQ8x/0kqfeNmBAaiSi+o7FsgI= github.com/gorilla/sessions v1.2.1/go.mod h1:dk2InVEVJ0sfLlnXv9EAgkf6ecYs/i80K/zI+bUmuGM= github.com/gorilla/websocket v1.4.2 h1:+/TMaTYc4QFitKJxsQ7Yye35DkWvkdLcvGKqM+x0Ufc= github.com/gorilla/websocket v1.4.2/go.mod h1:YR8l580nyteQvAITg2hZ9XVh4b55+EU/adAjf1fMHhE= +github.com/jtolds/gls v4.20.0+incompatible/go.mod h1:QJZ7F/aHp+rZTRtaJ1ow/lLfFfVYBRgL+9YlvaHOwJU= github.com/julienschmidt/httprouter v1.3.0 h1:U0609e9tgbseu3rBINet9P48AI/D3oJs4dN7jwJOQ1U= github.com/julienschmidt/httprouter v1.3.0/go.mod h1:JR6WtHb+2LUe8TCKY3cZOxFyyO8IZAc4RVcycCCAKdM= +github.com/k3a/html2text v1.2.1 h1:nvnKgBvBR/myqrwfLuiqecUtaK1lB9hGziIJKatNFVY= +github.com/k3a/html2text v1.2.1/go.mod h1:ieEXykM67iT8lTvEWBh6fhpH4B23kB9OMKPdIBmgUqA= github.com/rystaf/go-lemmy v0.0.0-20230622213726-c394de37235c h1:VxOcsDMWaqoBKbhoiSBxPl1zZ62YZ/VAW2nxlBRJiow= github.com/rystaf/go-lemmy v0.0.0-20230622213726-c394de37235c/go.mod h1:nRSkTD+ARAHXtqlSPdf5q3hjHLP1ALsS1m5D3o86o+4= github.com/rystaf/go-lemmy v0.0.0-20230622214853-5f2ab0756865 h1:xitFpcTOSP8RlZWR569yY75B2/7WX08rQQVG+0Mi4SA= @@ -31,10 +35,17 @@ github.com/rystaf/go-lemmy v0.0.0-20230623191350-f39e3c8bdcb5 h1:MoI87uid2KqpLdU github.com/rystaf/go-lemmy v0.0.0-20230623191350-f39e3c8bdcb5/go.mod h1:nRSkTD+ARAHXtqlSPdf5q3hjHLP1ALsS1m5D3o86o+4= github.com/rystaf/go-lemmy v0.0.0-20230704005320-c4b010dd339b h1:6z+gOUUvKwKQfgqEbxXS229gjr5V3HYg9bYbL9VHFdQ= github.com/rystaf/go-lemmy v0.0.0-20230704005320-c4b010dd339b/go.mod h1:nRSkTD+ARAHXtqlSPdf5q3hjHLP1ALsS1m5D3o86o+4= +github.com/smartystreets/assertions v0.0.0-20180927180507-b2de0cb4f26d/go.mod h1:OnSkiWE9lh6wB0YB77sQom3nweQdgAjqCqsofrRNTgc= +github.com/smartystreets/goconvey v1.6.4/go.mod h1:syvi0/a8iFYH4r/RixwvyeAJjdLS9QV7WQ/tjFTllLA= github.com/yuin/goldmark v1.5.4 h1:2uY/xC0roWy8IBEGLgB1ywIoEJFGmRrX21YQcvGZzjU= github.com/yuin/goldmark v1.5.4/go.mod h1:6yULJ656Px+3vBD8DxQVa3kxgyrAnzto9xy5taEt/CY= go.elara.ws/go-lemmy v0.17.3 h1:644k23BS2xqKJHJ9cHd8eyt1INpb5myqsBQQL2chBiA= go.elara.ws/go-lemmy v0.17.3/go.mod h1:rurQND/HT3yWfX/T4w+hb6vEwRAeAlV+9bSGFkkx5rA= +golang.org/x/crypto v0.0.0-20190308221718-c2843e01d9a2/go.mod h1:djNgcEr1/C05ACkg1iLfiJU5Ep61QUkGW8qpdssI0+w= +golang.org/x/net v0.0.0-20190311183353-d8887717615a/go.mod h1:t9HGtf8HONx5eT2rtn7q6eTqICYqUVnKs3thJo3Qplg= +golang.org/x/sys v0.0.0-20190215142949-d0b11bdaac8a/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY= +golang.org/x/text v0.3.0/go.mod h1:NqM8EUOU14njkJ3fqMW+pc6Ldnwhi/IjpwHt7yyuwOQ= golang.org/x/text v0.10.0 h1:UpjohKhiEgNc0CSauXmwYftY1+LlaC75SJwh0SgCX58= golang.org/x/text v0.10.0/go.mod h1:TvPlkZtksWOMsz7fbANvkp4WM8x/WCo/om8BMLbz+aE= +golang.org/x/tools v0.0.0-20190328211700-ab21143f2384/go.mod h1:LCzVGOaR6xXOjkQ3onu1FJEFr0SW1gC7cKk1uF8kGRs= golang.org/x/xerrors v0.0.0-20191204190536-9bdfabe68543/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0= diff --git a/routes.go b/routes.go index 692a534..7664c15 100644 --- a/routes.go +++ b/routes.go @@ -18,6 +18,7 @@ import ( "github.com/dustin/go-humanize" "github.com/julienschmidt/httprouter" + "github.com/k3a/html2text" "github.com/rystaf/go-lemmy" "github.com/rystaf/go-lemmy/types" "golang.org/x/text/language" @@ -114,7 +115,8 @@ var funcMap = template.FuncMap{ "markdown": func(host string, body string) template.HTML { var buf bytes.Buffer if err := md.Convert([]byte(body), &buf); err != nil { - panic(err) + fmt.Println(err) + return template.HTML(body) } converted := buf.String() converted = strings.Replace(converted, `!$1@$2 `) return template.HTML(converted) }, + "rmmarkdown": func(body string) string { + var buf bytes.Buffer + if err := md.Convert([]byte(body), &buf); err != nil { + fmt.Println(err) + return body + } + text := html2text.HTML2TextWithOptions(buf.String(), html2text.WithLinksInnerText()) + re := regexp.MustCompile(`\`) + return re.ReplaceAllString(text, "") + }, "contains": strings.Contains, "sub": func(a int32, b int) int { return int(a) - b diff --git a/templates/post.html b/templates/post.html index aca7fc2..3801a6c 100644 --- a/templates/post.html +++ b/templates/post.html @@ -24,7 +24,7 @@
    From 95195d00d772ad825a586a85f5de261efc26e67e Mon Sep 17 00:00:00 2001 From: Ryan Stafford Date: Wed, 5 Jul 2023 14:05:32 -0400 Subject: [PATCH 11/78] add missing template --- templates/nsfw.html | 9 +++++++++ 1 file changed, 9 insertions(+) create mode 100644 templates/nsfw.html diff --git a/templates/nsfw.html b/templates/nsfw.html new file mode 100644 index 0000000..4df5ebb --- /dev/null +++ b/templates/nsfw.html @@ -0,0 +1,9 @@ +
    +
    18+
    +

    You must be 18+ to view this community

    + +

    You must be at least eighteen years old to view this content. Are you over eighteen and willing to see adult content?

    + + + +
    From c105dfc90017d3c29b60adfcf48959dff3d47a68 Mon Sep 17 00:00:00 2001 From: Ryan Stafford Date: Wed, 5 Jul 2023 14:27:49 -0400 Subject: [PATCH 12/78] fix saved tab not loading --- templates/nav.html | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/templates/nav.html b/templates/nav.html index ec1102e..081c2bb 100644 --- a/templates/nav.html +++ b/templates/nav.html @@ -49,7 +49,7 @@
      {{ if .User }}
    • overview
    • - {{ if eq .User.PersonView.Person.ID .Session.UserID}} + {{ if and .Session (eq .User.PersonView.Person.ID .Session.UserID) }}
    • saved
    • {{ end }} {{ else if .Comments -}} From 2b5349466aa214eca55937ea0e83419d8ddbe5ae Mon Sep 17 00:00:00 2001 From: Ryan Stafford Date: Wed, 5 Jul 2023 14:50:52 -0400 Subject: [PATCH 13/78] use full community name in top header links. fixes #10 --- templates/nav.html | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/templates/nav.html b/templates/nav.html index 081c2bb..287e6c2 100644 --- a/templates/nav.html +++ b/templates/nav.html @@ -6,7 +6,7 @@ | {{ $host := .Host }} {{ range $i, $c := .TopCommunities}} - {{$c.Community.Name}} + {{$c.Community.Name}} - {{ end }} more » From 88457d0818c056add0f803afef59c594a17925bf Mon Sep 17 00:00:00 2001 From: Ryan Stafford Date: Wed, 5 Jul 2023 15:26:26 -0400 Subject: [PATCH 14/78] hide child comments button --- public/style.css | 16 +++++++++++++--- public/utils.js | 34 ++++++++++++++++++++++++++++++++++ templates/comment.html | 3 +++ templates/main.html | 7 +++---- templates/post.html | 3 +++ templates/sidebar.html | 2 +- 6 files changed, 57 insertions(+), 8 deletions(-) diff --git a/public/style.css b/public/style.css index bbf16b9..9437d9e 100644 --- a/public/style.css +++ b/public/style.css @@ -389,9 +389,10 @@ form.nsfw div { .buttons a, .buttons form input, .comment .buttons form input { text-decoration: none; color: #888; - padding-right: 4px; + display: inline-block; + margin-right: 8px !important; } -.buttons a:hover, .title a:hover, .buttons input:hover { +.buttons a:hover, .title a:hover, .buttons form input:hover, .comment .buttons form input:hover { text-decoration: underline; } .entry { @@ -431,7 +432,16 @@ form.nsfw div { .expando-button:hover{ background-color: #466599; } -.expando-button.hidden { +.expando-button.hidden, .children.hidden { + display: none; +} +.hidechildren .show { + display: none; +} +.hidechildren.hidden .show { + display: inline; +} +.hidechildren.hidden .hide { display: none; } .expando { diff --git a/public/utils.js b/public/utils.js index ee63829..1edca59 100644 --- a/public/utils.js +++ b/public/utils.js @@ -64,6 +64,20 @@ function commentClick(e) { } return false } + if (e.target.className.indexOf("hidechildren") != -1) { + if (e.target.getAttribute("for") != targ.id) { return } + e.preventDefault() + var btn = targ.getElementsByClassName("hidechildren")[0] + var children = targ.getElementsByClassName("children")[0] + if (children.className.indexOf("hidden") == -1) { + children.className = "children hidden" + btn.className = "hidechildren hidden" + } else { + children.className = "children" + btn.className = "hidechildren" + } + return false + } if ((e.target.className.indexOf("loadmore") != -1) || (e.target.className.indexOf("edit") != -1) || (e.target.className.indexOf("source") != -1) || @@ -77,6 +91,26 @@ function commentClick(e) { return false } } +function hideAllChildComments(e) { + e.preventDefault() + var comments = document.getElementsByClassName("comment") + for (var i = 0; i < comments.length; i++) { + var comment = comments[i] + var btn = comment.getElementsByClassName("hidechildren") + if (!btn.length) { continue } + btn = btn[0] + if (btn.getAttribute("for") != comment.id) { continue } + var children = comment.getElementsByClassName("children")[0] + if (children.className.indexOf("hidden") == -1) { + children.className = "children hidden" + btn.className = "hidechildren hidden" + } else { + children.className = "children" + btn.className = "hidechildren" + } + } + return false +} function formSubmit(e) { e = e || window.event; var targ = e.currentTarget || e.srcElement || e; diff --git a/templates/comment.html b/templates/comment.html index 6a3f4ce..8bfc809 100644 --- a/templates/comment.html +++ b/templates/comment.html @@ -79,6 +79,9 @@ {{ end }} +{{ end }} +{{ if gt .ChildCount 0 }} +
    • hideshow {{ .ChildCount }} child comments
    • {{ end }}
    diff --git a/templates/main.html b/templates/main.html index 3672a19..5aa6f5c 100644 --- a/templates/main.html +++ b/templates/main.html @@ -8,10 +8,9 @@
    {{ if (and .Post.Body.IsValid (ne .Post.Body.String "")) }} diff --git a/templates/sidebar.html b/templates/sidebar.html index 8137b77..8054605 100644 --- a/templates/sidebar.html +++ b/templates/sidebar.html @@ -66,7 +66,7 @@ {{ printer .Site.SiteView.Counts.Users }} readers
    {{ printer .Site.SiteView.Counts.UsersActiveDay }} users here now -

    {{ markdown .Host .Site.SiteView.Site.Sidebar.String }}

    + {{ markdown .Host .Site.SiteView.Site.Sidebar.String }}
    founded {{ humanize .Site.SiteView.Site.Published.Time }}
    {{ if .Site.Admins }} ADMINS From 834d8170d10f1499857871470793a853e0b0df28 Mon Sep 17 00:00:00 2001 From: Ryan Stafford Date: Wed, 5 Jul 2023 16:20:34 -0400 Subject: [PATCH 15/78] expando image resizing --- public/style.css | 15 +++++++++++++-- templates/frontpage.html | 10 ++++++---- templates/main.html | 5 ++++- templates/post.html | 2 ++ 4 files changed, 25 insertions(+), 7 deletions(-) diff --git a/public/style.css b/public/style.css index 9437d9e..c72b7e0 100644 --- a/public/style.css +++ b/public/style.css @@ -447,13 +447,24 @@ form.nsfw div { .expando { display: none; max-width: 587px; + position: relative; color: #000; } .expando.open{ display: block; } -.expando img { - max-width: 100%; +.expando .image { + display: inline-block; + overflow: hidden; + resize: both; + width: 100%; + background-repeat: no-repeat; + background-size: contain; + background-position: top left; +} +.expando .image img { + visibility: hidden; + width: 100%; } .expando .md { background-color: #fafafa; diff --git a/templates/frontpage.html b/templates/frontpage.html index f6b75d6..b603641 100644 --- a/templates/frontpage.html +++ b/templates/frontpage.html @@ -2,17 +2,19 @@ {{ if and .Community (ne .Community.CommunityView.Community.Title "")}}{{.Community.CommunityView.Community.Title}}{{else if ne .CommunityName ""}}/c/{{.CommunityName}}{{ else if .User}}overview for {{.User.PersonView.Person.Name}}{{else}}{{ host .Host }}{{end}} - + diff --git a/templates/main.html b/templates/main.html index 5aa6f5c..bd8a22c 100644 --- a/templates/main.html +++ b/templates/main.html @@ -3,7 +3,7 @@ {{if and .Posts .PostID }}{{ (index .Posts 0).Post.Name}} : {{.CommunityName}}{{else if and .Community (ne .Community.CommunityView.Community.Title "")}}{{.Community.CommunityView.Community.Title}}{{else if ne .CommunityName ""}}/c/{{.CommunityName}}{{ else if .User}}overview for {{.User.PersonView.Person.Name}}{{else}}{{ host .Host }}{{end}} - + diff --git a/templates/post.html b/templates/post.html index b2f178b..9e30139 100644 --- a/templates/post.html +++ b/templates/post.html @@ -75,7 +75,9 @@
    {{ markdown .State.Host .Post.Body.String }}
    {{ end }} {{ if isImage .Post.URL.String}} +
    +
    {{ end }}
    From ae0c8427d2d5706b0d2dd04207e50ec9f39bee69 Mon Sep 17 00:00:00 2001 From: Ryan Stafford Date: Wed, 5 Jul 2023 16:59:23 -0400 Subject: [PATCH 16/78] hide all toggle, get comments/posts bugfixes --- public/utils.js | 2 ++ state.go | 25 ++++++++++++++++++------- 2 files changed, 20 insertions(+), 7 deletions(-) diff --git a/public/utils.js b/public/utils.js index 1edca59..3e469e0 100644 --- a/public/utils.js +++ b/public/utils.js @@ -104,9 +104,11 @@ function hideAllChildComments(e) { if (children.className.indexOf("hidden") == -1) { children.className = "children hidden" btn.className = "hidechildren hidden" + e.target.innerHTML = "show all child comments" } else { children.className = "children" btn.className = "hidechildren" + e.target.innerHTML = "hide all child comments" } } return false diff --git a/state.go b/state.go index c7306b0..e33caef 100644 --- a/state.go +++ b/state.go @@ -269,6 +269,14 @@ func (state *State) GetComments() { Limit: types.NewOptional(int64(200)), Page: types.NewOptional(int64(state.Page)), }) + if err != nil && strings.Contains(fmt.Sprintf("%v", err), "couldnt_get_comments") { + cresp, err = state.Client.Comments(context.Background(), types.GetComments{ + PostID: types.NewOptional(state.PostID), + Sort: types.NewOptional(types.CommentSortType(state.Sort)), + Type: types.NewOptional(types.ListingType("All")), + Page: types.NewOptional(int64(state.Page)), + }) + } if err != nil { state.Status = http.StatusInternalServerError fmt.Println(err) @@ -432,13 +440,16 @@ func (state *State) MarkAllAsRead() { } func (state *State) GetPosts() { - resp, err := state.Client.Posts(context.Background(), types.GetPosts{ - Sort: types.NewOptional(types.SortType(state.Sort)), - Type: types.NewOptional(types.ListingType(state.Listing)), - CommunityName: types.NewOptional(state.CommunityName), - Limit: types.NewOptional(int64(25)), - Page: types.NewOptional(int64(state.Page)), - }) + posts := types.GetPosts{ + Sort: types.NewOptional(types.SortType(state.Sort)), + Type: types.NewOptional(types.ListingType(state.Listing)), + Limit: types.NewOptional(int64(25)), + Page: types.NewOptional(int64(state.Page)), + } + if state.CommunityName != "" { + posts.CommunityName = types.NewOptional(state.CommunityName) + } + resp, err := state.Client.Posts(context.Background(), posts) if err != nil { fmt.Println(err) state.Status = http.StatusInternalServerError From 3d23c96166fc3b6c2b14b16e99b42ede9a594bee Mon Sep 17 00:00:00 2001 From: Ryan Stafford Date: Wed, 5 Jul 2023 18:34:46 -0400 Subject: [PATCH 17/78] load more button --- main.go | 2 +- public/style.css | 14 ++++++++++++-- public/utils.js | 18 ++++++++++++++++++ routes.go | 11 +++++++++-- state.go | 12 ++---------- templates/frontpage.html | 7 ++++++- templates/main.html | 9 +++++++-- templates/post.html | 4 ++-- templates/xhr.html | 2 +- 9 files changed, 58 insertions(+), 21 deletions(-) diff --git a/main.go b/main.go index cdd4cdc..75fce11 100644 --- a/main.go +++ b/main.go @@ -51,7 +51,7 @@ func init() { md = goldmark.New(goldmark.WithExtensions(extension.Linkify)) templates = make(map[string]*template.Template) if !*watch { - for _, name := range []string{"index.html", "login.html", "frontpage.html", "root.html", "settings.html"} { + for _, name := range []string{"index.html", "login.html", "frontpage.html", "root.html", "settings.html", "xhr.html"} { t := template.New(name).Funcs(funcMap) glob, err := t.ParseGlob("templates/*") if err != nil { diff --git a/public/style.css b/public/style.css index c72b7e0..4aaddd3 100644 --- a/public/style.css +++ b/public/style.css @@ -121,6 +121,9 @@ code { [disabled] { cursor: not-allowed; } +#loadmore [disabled] { + cursor: wait; +} .post .title { color: #888; font-size: 10px; @@ -357,6 +360,7 @@ form.nsfw div { } .pager { margin: 10px; + display: none; } .pager a { padding: 1px 4px; @@ -367,6 +371,9 @@ form.nsfw div { text-decoration: none; color: #369; } +#loadmore { + margin: 10px 0px; +} .buttons li { display: inline; } @@ -457,14 +464,14 @@ form.nsfw div { display: inline-block; overflow: hidden; resize: both; - width: 100%; + max-width: 100%; background-repeat: no-repeat; background-size: contain; background-position: top left; } .expando .image img { visibility: hidden; - width: 100%; + max-width: 100%; } .expando .md { background-color: #fafafa; @@ -712,6 +719,9 @@ nav .communities a.more { position: absolute; right: 0; } +.dark nav .communities a.more { + background-color: #cccccc; +} .orangered, .orangered b { color: orangered !important; } diff --git a/public/utils.js b/public/utils.js index 3e469e0..b8d57d3 100644 --- a/public/utils.js +++ b/public/utils.js @@ -91,6 +91,24 @@ function commentClick(e) { return false } } +function loadMore(e) { + e.preventDefault() + page = e.target.getAttribute("data-page") + e.target.disabled="disabled" + e.target.value="loading" + var urlParams = new URLSearchParams(window.location.search); + urlParams.set("xhr", "1") + urlParams.set("page", page) + request(window.location.origin+window.location.pathname+"?"+urlParams.toString(), "", function(res){ + if (res.trim()) { + e.target.outerHTML = res + '
    ' + } + else { + e.target.outerHTML = "" + } + }) + return false; +} function hideAllChildComments(e) { e.preventDefault() var comments = document.getElementsByClassName("comment") diff --git a/routes.go b/routes.go index 7664c15..1c465d2 100644 --- a/routes.go +++ b/routes.go @@ -351,7 +351,11 @@ func GetFrontpage(w http.ResponseWriter, r *http.Request, ps httprouter.Params) if state.Op == "" { state.GetPosts() } - Render(w, "frontpage.html", state) + if state.XHR { + Render(w, "xhr.html", state) + } else { + Render(w, "frontpage.html", state) + } } func GetPost(w http.ResponseWriter, r *http.Request, ps httprouter.Params) { @@ -508,10 +512,11 @@ func Settings(w http.ResponseWriter, r *http.Request, ps httprouter.Params) { setCookie(w, state.Host, name, r.FormValue(name)) } if r.FormValue("darkmode") != "" { - setCookie(w, state.Host, "Dark", "1") + setCookie(w, "", "Dark", "1") state.Dark = true } else { deleteCookie(w, state.Host, "Dark") + deleteCookie(w, "", "Dark") state.Dark = false } if r.FormValue("shownsfw") != "" { @@ -934,6 +939,8 @@ func UserOp(w http.ResponseWriter, r *http.Request, ps httprouter.Params) { state.Client.CreatePostLike(context.Background(), post) if r.FormValue("xhr") != "" { state.GetPost(postid) + state.PostID = 0 + state.Op = "vote_post" state.XHR = true Render(w, "index.html", state) return diff --git a/state.go b/state.go index e33caef..1692c56 100644 --- a/state.go +++ b/state.go @@ -235,7 +235,7 @@ func (state *State) GetComment(commentid int) { ParentID: types.NewOptional(state.CommentID), Sort: types.NewOptional(types.CommentSortType(state.Sort)), Type: types.NewOptional(types.ListingType("All")), - Limit: types.NewOptional(int64(200)), + Limit: types.NewOptional(int64(50)), }) if err != nil { fmt.Println(err) @@ -266,17 +266,9 @@ func (state *State) GetComments() { PostID: types.NewOptional(state.PostID), Sort: types.NewOptional(types.CommentSortType(state.Sort)), Type: types.NewOptional(types.ListingType("All")), - Limit: types.NewOptional(int64(200)), + Limit: types.NewOptional(int64(50)), Page: types.NewOptional(int64(state.Page)), }) - if err != nil && strings.Contains(fmt.Sprintf("%v", err), "couldnt_get_comments") { - cresp, err = state.Client.Comments(context.Background(), types.GetComments{ - PostID: types.NewOptional(state.PostID), - Sort: types.NewOptional(types.CommentSortType(state.Sort)), - Type: types.NewOptional(types.ListingType("All")), - Page: types.NewOptional(int64(state.Page)), - }) - } if err != nil { state.Status = http.StatusInternalServerError fmt.Println(err) diff --git a/templates/frontpage.html b/templates/frontpage.html index b603641..93b37c6 100644 --- a/templates/frontpage.html +++ b/templates/frontpage.html @@ -10,9 +10,13 @@ +