From 8d31cbada52b649e43b499f0c8649e574752f186 Mon Sep 17 00:00:00 2001 From: Ryan Stafford Date: Fri, 14 Jul 2023 09:55:42 -0400 Subject: [PATCH] hide instance names, default comment sort options. fixes #32 --- public/style.css | 3 +- routes.go | 15 +++++++- state.go | 75 ++++++++++++++++++++------------------- templates/activities.html | 23 ++++++++++-- templates/comment.html | 8 ++++- templates/frontpage.html | 2 +- templates/main.html | 10 +++--- templates/menu.html | 10 ++++-- templates/post.html | 16 +++++++-- templates/settings.html | 19 +++++++++- 10 files changed, 128 insertions(+), 53 deletions(-) diff --git a/public/style.css b/public/style.css index 36214aa..7cb8d12 100644 --- a/public/style.css +++ b/public/style.css @@ -1027,7 +1027,8 @@ form.create input[type=file], form.create select { } .preferences label{ display: inline-block; - width: 100px; + width: 130px; + margin-right: 5px; text-align: right; } diff --git a/routes.go b/routes.go index 1507480..f914ab8 100644 --- a/routes.go +++ b/routes.go @@ -209,12 +209,17 @@ func Initialize(Host string, r *http.Request) (State, error) { } state.Listing = getCookie(r, "DefaultListingType") state.Sort = getCookie(r, "DefaultSortType") + state.CommentSort = getCookie(r, "DefaultCommentSortType") state.Dark = getCookie(r, "Dark") != "" state.ShowNSFW = getCookie(r, "ShowNSFW") != "" + state.HideInstanceNames = getCookie(r, "HideInstanceNames") != "" state.ParseQuery(r.URL.RawQuery) if state.Sort == "" { state.Sort = "Hot" } + if state.CommentSort == "" { + state.CommentSort = "Hot" + } if state.Listing == "" || state.Session == nil && state.Listing == "Subscribed" { state.Listing = "All" } @@ -542,7 +547,7 @@ func Settings(w http.ResponseWriter, r *http.Request, ps httprouter.Params) { } switch r.Method { case "POST": - for _, name := range []string{"DefaultSortType", "DefaultListingType"} { + for _, name := range []string{"DefaultSortType", "DefaultListingType", "DefaultCommentSortType"} { deleteCookie(w, state.Host, name) setCookie(w, "", name, r.FormValue(name)) } @@ -562,8 +567,16 @@ func Settings(w http.ResponseWriter, r *http.Request, ps httprouter.Params) { deleteCookie(w, "", "ShowNSFW") state.ShowNSFW = false } + if r.FormValue("hideInstanceNames") != "" { + setCookie(w, "", "HideInstanceNames", "1") + state.HideInstanceNames = true + } else { + deleteCookie(w, "", "HideInstanceNames") + state.HideInstanceNames = false + } state.Listing = r.FormValue("DefaultListingType") state.Sort = r.FormValue("DefaultSortType") + state.CommentSort = r.FormValue("DefaultCommentSortType") // TODO save user settings case "GET": if state.Session != nil { diff --git a/state.go b/state.go index 266eddc..b271855 100644 --- a/state.go +++ b/state.go @@ -62,40 +62,42 @@ type Session struct { } type State struct { - Client *lemmy.Client - HTTPClient *http.Client - Session *Session - Status int - Error error - Alert string - Host string - CommunityName string - Community *types.GetCommunityResponse - TopCommunities []types.CommunityView - Communities []types.CommunityView - UnreadCount int64 - Sort string - Listing string - Page int - Parts []string - Posts []Post - Comments []Comment - Activities []Activity - CommentCount int - PostID int - CommentID int - Context int - UserName string - User *types.GetPersonDetailsResponse - Now int64 - XHR bool - Op string - Site *types.GetSiteResponse - Query string - SearchType string - Captcha *types.CaptchaResponse - Dark bool - ShowNSFW bool + Client *lemmy.Client + HTTPClient *http.Client + Session *Session + Status int + Error error + Alert string + Host string + CommunityName string + Community *types.GetCommunityResponse + TopCommunities []types.CommunityView + Communities []types.CommunityView + UnreadCount int64 + Sort string + CommentSort string + Listing string + Page int + Parts []string + Posts []Post + Comments []Comment + Activities []Activity + CommentCount int + PostID int + CommentID int + Context int + UserName string + User *types.GetPersonDetailsResponse + Now int64 + XHR bool + Op string + Site *types.GetSiteResponse + Query string + SearchType string + Captcha *types.CaptchaResponse + Dark bool + ShowNSFW bool + HideInstanceNames bool } func (p State) SortBy(v string) string { @@ -163,6 +165,7 @@ func (state *State) ParseQuery(RawQuery string) { } if len(m["sort"]) > 0 { state.Sort = m["sort"][0] + state.CommentSort = m["sort"][0] } if len(m["communityname"]) > 0 { state.CommunityName = m["communityname"][0] @@ -241,7 +244,7 @@ func (state *State) GetComment(commentid int) { state.CommentID = commentid cresp, err := state.Client.Comments(context.Background(), types.GetComments{ ParentID: types.NewOptional(state.CommentID), - Sort: types.NewOptional(types.CommentSortType(state.Sort)), + Sort: types.NewOptional(types.CommentSortType(state.CommentSort)), Type: types.NewOptional(types.ListingType("All")), Limit: types.NewOptional(int64(50)), }) @@ -296,7 +299,7 @@ func (state *State) GetComments() { } cresp, err := state.Client.Comments(context.Background(), types.GetComments{ PostID: types.NewOptional(state.PostID), - Sort: types.NewOptional(types.CommentSortType(state.Sort)), + Sort: types.NewOptional(types.CommentSortType(state.CommentSort)), Type: types.NewOptional(types.ListingType("All")), Limit: types.NewOptional(int64(50)), Page: types.NewOptional(int64(state.Page)), diff --git a/templates/activities.html b/templates/activities.html index 12b3284..110419b 100644 --- a/templates/activities.html +++ b/templates/activities.html @@ -13,7 +13,12 @@ {{$state.User.PersonView.Person.Name }} {{ end }} in - c/{{ $activity.Comment.P.Community.Name }} + + c/{{ if $state.HideInstanceNames -}} + {{ $activity.Comment.P.Community.Name }} + {{ else -}} + {{ fullcname $activity.Comment.P.Community }} + {{ end }} {{ template "comment.html" $activity.Comment }} @@ -25,10 +30,22 @@ message {{ if eq $activity.Message.Creator.ID $state.Session.UserID }} to - {{ $activity.Message.Recipient.Name }} + + {{- if $state.HideInstanceNames -}} + {{ $activity.Message.Recipient.Name }} + {{- else -}} + {{ fullname $activity.Message.Recipient }} + {{- end -}} + {{ else }} from - {{ $activity.Message.Creator.Name }} + + {{- if $state.HideInstanceNames -}} + {{ $activity.Message.Creator.Name }} + {{- else -}} + {{ fullname $activity.Message.Creator }} + {{- end -}} + {{end}} sent {{ humanize $activity.Message.PrivateMessage.Published.Time }} diff --git a/templates/comment.html b/templates/comment.html index 2a740ea..fb686b8 100644 --- a/templates/comment.html +++ b/templates/comment.html @@ -21,7 +21,13 @@ [-] {{ end }} - {{fullname .P.Creator}} + + {{- if .State.HideInstanceNames -}} + {{ .P.Creator.Name }} + {{- else -}} + {{ fullname .P.Creator }} + {{- end -}} + {{.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 ea74320..42434fa 100644 --- a/templates/frontpage.html +++ b/templates/frontpage.html @@ -2,7 +2,7 @@ {{ 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 5b03aa5..c4f5a9d 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}} - +