hide instance names, default comment sort options. fixes #32

This commit is contained in:
Ryan Stafford 2023-07-14 09:55:42 -04:00
parent 37e62d2e5f
commit 8d31cbada5
10 changed files with 128 additions and 53 deletions

View file

@ -1027,7 +1027,8 @@ form.create input[type=file], form.create select {
} }
.preferences label{ .preferences label{
display: inline-block; display: inline-block;
width: 100px; width: 130px;
margin-right: 5px;
text-align: right; text-align: right;
} }

View file

@ -209,12 +209,17 @@ func Initialize(Host string, r *http.Request) (State, error) {
} }
state.Listing = getCookie(r, "DefaultListingType") state.Listing = getCookie(r, "DefaultListingType")
state.Sort = getCookie(r, "DefaultSortType") state.Sort = getCookie(r, "DefaultSortType")
state.CommentSort = getCookie(r, "DefaultCommentSortType")
state.Dark = getCookie(r, "Dark") != "" state.Dark = getCookie(r, "Dark") != ""
state.ShowNSFW = getCookie(r, "ShowNSFW") != "" state.ShowNSFW = getCookie(r, "ShowNSFW") != ""
state.HideInstanceNames = getCookie(r, "HideInstanceNames") != ""
state.ParseQuery(r.URL.RawQuery) state.ParseQuery(r.URL.RawQuery)
if state.Sort == "" { if state.Sort == "" {
state.Sort = "Hot" state.Sort = "Hot"
} }
if state.CommentSort == "" {
state.CommentSort = "Hot"
}
if state.Listing == "" || state.Session == nil && state.Listing == "Subscribed" { if state.Listing == "" || state.Session == nil && state.Listing == "Subscribed" {
state.Listing = "All" state.Listing = "All"
} }
@ -542,7 +547,7 @@ func Settings(w http.ResponseWriter, r *http.Request, ps httprouter.Params) {
} }
switch r.Method { switch r.Method {
case "POST": case "POST":
for _, name := range []string{"DefaultSortType", "DefaultListingType"} { for _, name := range []string{"DefaultSortType", "DefaultListingType", "DefaultCommentSortType"} {
deleteCookie(w, state.Host, name) deleteCookie(w, state.Host, name)
setCookie(w, "", name, r.FormValue(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") deleteCookie(w, "", "ShowNSFW")
state.ShowNSFW = false 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.Listing = r.FormValue("DefaultListingType")
state.Sort = r.FormValue("DefaultSortType") state.Sort = r.FormValue("DefaultSortType")
state.CommentSort = r.FormValue("DefaultCommentSortType")
// TODO save user settings // TODO save user settings
case "GET": case "GET":
if state.Session != nil { if state.Session != nil {

View file

@ -75,6 +75,7 @@ type State struct {
Communities []types.CommunityView Communities []types.CommunityView
UnreadCount int64 UnreadCount int64
Sort string Sort string
CommentSort string
Listing string Listing string
Page int Page int
Parts []string Parts []string
@ -96,6 +97,7 @@ type State struct {
Captcha *types.CaptchaResponse Captcha *types.CaptchaResponse
Dark bool Dark bool
ShowNSFW bool ShowNSFW bool
HideInstanceNames bool
} }
func (p State) SortBy(v string) string { func (p State) SortBy(v string) string {
@ -163,6 +165,7 @@ func (state *State) ParseQuery(RawQuery string) {
} }
if len(m["sort"]) > 0 { if len(m["sort"]) > 0 {
state.Sort = m["sort"][0] state.Sort = m["sort"][0]
state.CommentSort = m["sort"][0]
} }
if len(m["communityname"]) > 0 { if len(m["communityname"]) > 0 {
state.CommunityName = m["communityname"][0] state.CommunityName = m["communityname"][0]
@ -241,7 +244,7 @@ func (state *State) GetComment(commentid int) {
state.CommentID = commentid state.CommentID = commentid
cresp, err := state.Client.Comments(context.Background(), types.GetComments{ cresp, err := state.Client.Comments(context.Background(), types.GetComments{
ParentID: types.NewOptional(state.CommentID), 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")), Type: types.NewOptional(types.ListingType("All")),
Limit: types.NewOptional(int64(50)), Limit: types.NewOptional(int64(50)),
}) })
@ -296,7 +299,7 @@ func (state *State) GetComments() {
} }
cresp, err := state.Client.Comments(context.Background(), types.GetComments{ cresp, err := state.Client.Comments(context.Background(), types.GetComments{
PostID: types.NewOptional(state.PostID), 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")), Type: types.NewOptional(types.ListingType("All")),
Limit: types.NewOptional(int64(50)), Limit: types.NewOptional(int64(50)),
Page: types.NewOptional(int64(state.Page)), Page: types.NewOptional(int64(state.Page)),

View file

@ -13,7 +13,12 @@
<a href="">{{$state.User.PersonView.Person.Name }}</a> <a href="">{{$state.User.PersonView.Person.Name }}</a>
{{ end }} {{ end }}
in in
<a href="/{{$state.Host}}/c/{{ fullcname $activity.Comment.P.Community }}">c/{{ $activity.Comment.P.Community.Name }}</a> <a href="/{{$state.Host}}/c/{{ fullcname $activity.Comment.P.Community }}">
c/{{ if $state.HideInstanceNames -}}
{{ $activity.Comment.P.Community.Name }}</a>
{{ else -}}
{{ fullcname $activity.Comment.P.Community }}
{{ end }}
</span> </span>
</div> </div>
{{ template "comment.html" $activity.Comment }} {{ template "comment.html" $activity.Comment }}
@ -25,10 +30,22 @@
<b>message</b> <b>message</b>
{{ if eq $activity.Message.Creator.ID $state.Session.UserID }} {{ if eq $activity.Message.Creator.ID $state.Session.UserID }}
to to
<a href="/{{$state.Host}}/u/{{fullname $activity.Message.Recipient}}">{{ $activity.Message.Recipient.Name }}</a> <a href="/{{$state.Host}}/u/{{fullname $activity.Message.Recipient}}">
{{- if $state.HideInstanceNames -}}
{{ $activity.Message.Recipient.Name }}
{{- else -}}
{{ fullname $activity.Message.Recipient }}
{{- end -}}
</a>
{{ else }} {{ else }}
from from
<a href="/{{$state.Host}}/u/{{fullname $activity.Message.Creator}}">{{ $activity.Message.Creator.Name }}</a> <a href="/{{$state.Host}}/u/{{fullname $activity.Message.Creator}}">
{{- if $state.HideInstanceNames -}}
{{ $activity.Message.Creator.Name }}
{{- else -}}
{{ fullname $activity.Message.Creator }}
{{- end -}}
</a>
{{end}} {{end}}
sent {{ humanize $activity.Message.PrivateMessage.Published.Time }} sent {{ humanize $activity.Message.PrivateMessage.Published.Time }}
</span> </span>

View file

@ -21,7 +21,13 @@
[-] [-]
{{ end }} {{ end }}
</a> </a>
<a {{ if .P.Comment.Distinguished}}class="{{if .P.Creator.Admin}}admin {{end}}distinguished"{{ else if .Submitter }}class="submitter"{{end}} href="/{{.State.Host}}/u/{{fullname .P.Creator}}">{{fullname .P.Creator}}</a> <a {{ if .P.Comment.Distinguished}}class="{{if .P.Creator.Admin}}admin {{end}}distinguished"{{ else if .Submitter }}class="submitter"{{end}} href="/{{.State.Host}}/u/{{fullname .P.Creator}}">
{{- if .State.HideInstanceNames -}}
{{ .P.Creator.Name }}
{{- else -}}
{{ fullname .P.Creator }}
{{- end -}}
</a>
<b>{{.P.Counts.Score}} points</b> <span title="{{.P.Comment.Published.Time}}">{{ humanize .P.Comment.Published.Time }}</span> <b>{{.P.Counts.Score}} points</b> <span title="{{.P.Comment.Published.Time}}">{{ humanize .P.Comment.Published.Time }}</span>
{{- if gt .P.Comment.Updated.Time.Unix .P.Comment.Published.Time.Unix -}} {{- if gt .P.Comment.Updated.Time.Unix .P.Comment.Published.Time.Unix -}}
* (last edited <span title="{{.P.Comment.Updated.Time}}">{{ humanize .P.Comment.Updated.Time }}</span>) * (last edited <span title="{{.P.Comment.Updated.Time}}">{{ humanize .P.Comment.Updated.Time }}</span>)

View file

@ -2,7 +2,7 @@
<head> <head>
<title>{{ 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}}</title> <title>{{ 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}}</title>
<link rel="shortcut icon" href="/{{.Host}}/icon.jpg"> <link rel="shortcut icon" href="/{{.Host}}/icon.jpg">
<link rel="stylesheet" href="/_/static/style.css?v=23"> <link rel="stylesheet" href="/_/static/style.css?v=24">
<meta name="viewport" content="width=device-width, initial-scale=1" /> <meta name="viewport" content="width=device-width, initial-scale=1" />
</head> </head>
<body {{ if .Dark }}class="dark"{{end}}> <body {{ if .Dark }}class="dark"{{end}}>

View file

@ -3,7 +3,7 @@
<title>{{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}}</title> <title>{{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}}</title>
<meta name="viewport" content="width=device-width, initial-scale=1" /> <meta name="viewport" content="width=device-width, initial-scale=1" />
<link rel="shortcut icon" href="/{{.Host}}/icon.jpg"> <link rel="shortcut icon" href="/{{.Host}}/icon.jpg">
<link rel="stylesheet" href="/_/static/style.css?v=23"> <link rel="stylesheet" href="/_/static/style.css?v=24">
</head> </head>
<body{{ if .Dark }} class="dark"{{end}}> <body{{ if .Dark }} class="dark"{{end}}>
<noscript> <noscript>
@ -85,10 +85,10 @@
{{if .Comments}}{{if gt .Page 1}}(page {{ .Page }}) {{else if lt (index .Posts 0).Counts.Comments .CommentCount }}all{{else}}top{{end}} {{.CommentCount}} comments{{else}} no comments (yet){{end}} {{if .Comments}}{{if gt .Page 1}}(page {{ .Page }}) {{else if lt (index .Posts 0).Counts.Comments .CommentCount }}all{{else}}top{{end}} {{.CommentCount}} comments{{else}} no comments (yet){{end}}
<div> <div>
sorted by: sorted by:
<a {{ if eq .Sort "Hot"}}class="selected"{{end}} href="{{ .SortBy "Hot"}}">hot</a> <a {{ if eq .CommentSort "Hot"}}class="selected"{{end}} href="{{ .SortBy "Hot"}}">hot</a>
<a {{ if eq .Sort "Top"}}class="selected"{{end}} href="{{ .SortBy "Top"}}">top</a> <a {{ if eq .CommentSort "Top"}}class="selected"{{end}} href="{{ .SortBy "Top"}}">top</a>
<a {{ if eq .Sort "New"}}class="selected"{{end}} href="{{ .SortBy "New"}}">new</a> <a {{ if eq .CommentSort "New"}}class="selected"{{end}} href="{{ .SortBy "New"}}">new</a>
<a {{ if eq .Sort "Old"}}class="selected"{{end}} href="{{ .SortBy "Old"}}">old</a> <a {{ if eq .CommentSort "Old"}}class="selected"{{end}} href="{{ .SortBy "Old"}}">old</a>
</div> </div>
</div> </div>
{{ if and .Session (ne .Op "edit_post") }} {{ if and .Session (ne .Op "edit_post") }}

View file

@ -9,12 +9,18 @@
{{ end }} {{ end }}
{{ if contains .Sort "Top" }} {{ if contains .Sort "Top" }}
links from past: links from past:
<a {{ if eq .Sort "TopHour"}}class="selected"{{end}} href="{{ .SortBy "TopHour"}}">1h</a>
<span>-</span>
<a {{ if eq .Sort "TopSixHour"}}class="selected"{{end}} href="{{ .SortBy "TopSixHour"}}">6h</a>
<span>-</span>
<a {{ if eq .Sort "TopTwelveHour"}}class="selected"{{end}} href="{{ .SortBy "TopTwelveHour"}}">12h</a>
<span>-</span>
<a {{ if eq .Sort "TopDay"}}class="selected"{{end}} href="{{ .SortBy "TopDay"}}">day</a> <a {{ if eq .Sort "TopDay"}}class="selected"{{end}} href="{{ .SortBy "TopDay"}}">day</a>
<span>-</span> <span>-</span>
<a {{ if eq .Sort "TopMonth"}}class="selected"{{end}} href="{{ .SortBy "TopMonth"}}">month</a>
<span>-</span>
<a {{ if eq .Sort "TopWeek"}}class="selected"{{end}} href="{{ .SortBy "TopWeek"}}">week</a> <a {{ if eq .Sort "TopWeek"}}class="selected"{{end}} href="{{ .SortBy "TopWeek"}}">week</a>
<span>-</span> <span>-</span>
<a {{ if eq .Sort "TopMonth"}}class="selected"{{end}} href="{{ .SortBy "TopMonth"}}">month</a>
<span>-</span>
<a {{ if eq .Sort "TopYear"}}class="selected"{{end}} href="{{ .SortBy "TopYear"}}">year</a> <a {{ if eq .Sort "TopYear"}}class="selected"{{end}} href="{{ .SortBy "TopYear"}}">year</a>
<span>-</span> <span>-</span>
<a {{ if eq .Sort "TopAll"}}class="selected"{{end}} href="{{ .SortBy "TopAll"}}">all time</a> <a {{ if eq .Sort "TopAll"}}class="selected"{{end}} href="{{ .SortBy "TopAll"}}">all time</a>

View file

@ -41,9 +41,21 @@
* (last edited <span title="{{.Post.Updated.Time}}">{{ humanize .Post.Updated.Time }}</span>) * (last edited <span title="{{.Post.Updated.Time}}">{{ humanize .Post.Updated.Time }}</span>)
{{ end }} {{ end }}
by by
<a class="submitter{{ if .Creator.Admin}} admin{{end}}" href="/{{ .State.Host }}/u/{{ fullname .Creator }}">{{ fullname .Creator }}</a> <a class="submitter{{ if .Creator.Admin}} admin{{end}}" href="/{{ .State.Host }}/u/{{ fullname .Creator }}">
{{- if .State.HideInstanceNames -}}
{{ .Creator.Name }}
{{- else -}}
{{ fullname .Creator }}
{{- end -}}
</a>
to to
<a href="/{{ .State.Host }}/c/{{ fullcname .Community }}">c/{{ fullcname .Community}}</a> <a href="/{{ .State.Host }}/c/{{ fullcname .Community }}">
c/{{ if .State.HideInstanceNames -}}
{{ .Community.Name }}
{{ else -}}
{{ fullcname .Community }}
{{ end }}
</a>
</div> </div>
<div class="buttons"> <div class="buttons">
{{ if .Post.NSFW }}<span class="nsfw">NSFW</span>{{end}} {{ if .Post.NSFW }}<span class="nsfw">NSFW</span>{{end}}

View file

@ -74,7 +74,7 @@
</div> </div>
<div> <div>
<label> <label>
default sort default post sort
</label> </label>
<select name="DefaultSortType"> <select name="DefaultSortType">
<option value="Hot"{{ if eq .Sort "Hot"}} selected{{end}}>Hot</option> <option value="Hot"{{ if eq .Sort "Hot"}} selected{{end}}>Hot</option>
@ -93,6 +93,17 @@
<option value="TopAll"{{ if eq .Sort "TopAll"}} selected{{end}}>Top All Time</option></select> <option value="TopAll"{{ if eq .Sort "TopAll"}} selected{{end}}>Top All Time</option></select>
</select> </select>
</div> </div>
<div>
<label>
default comment sort
</label>
<select name="DefaultCommentSortType">
<option value="Hot"{{ if eq .CommentSort "Hot"}} selected{{end}}>Hot</option>
<option value="New"{{ if eq .CommentSort "New"}} selected{{end}}>New</option>
<option value="Old"{{ if eq .CommentSort "Old"}} selected{{end}}>Old</option>
<option value="Top"{{ if eq .CommentSort "Top"}} selected{{end}}>Top</option>
</select>
</div>
<div> <div>
<label> <label>
dark mode dark mode
@ -111,6 +122,12 @@
</label> </label>
<input type="checkbox" name="autoLoad"> <input type="checkbox" name="autoLoad">
</div> </div>
<div>
<label>
hide instance names
</label>
<input type="checkbox" name="hideInstanceNames" {{ if .HideInstanceNames }}checked{{end}}>
</div>
<div> <div>
<label></label> <label></label>
<input type="submit" value="save"> <input type="submit" value="save">