mirror of
https://github.com/rystaf/mlmym.git
synced 2024-12-29 03:53:46 +00:00
hide instance names, default comment sort options. fixes #32
This commit is contained in:
parent
37e62d2e5f
commit
8d31cbada5
|
@ -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;
|
||||
|
||||
}
|
||||
|
|
15
routes.go
15
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 {
|
||||
|
|
75
state.go
75
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)),
|
||||
|
|
|
@ -13,7 +13,12 @@
|
|||
<a href="">{{$state.User.PersonView.Person.Name }}</a>
|
||||
{{ end }}
|
||||
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>
|
||||
</div>
|
||||
{{ template "comment.html" $activity.Comment }}
|
||||
|
@ -25,10 +30,22 @@
|
|||
<b>message</b>
|
||||
{{ if eq $activity.Message.Creator.ID $state.Session.UserID }}
|
||||
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 }}
|
||||
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}}
|
||||
sent {{ humanize $activity.Message.PrivateMessage.Published.Time }}
|
||||
</span>
|
||||
|
|
|
@ -21,7 +21,13 @@
|
|||
[-]
|
||||
{{ end }}
|
||||
</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>
|
||||
{{- 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>)
|
||||
|
|
|
@ -2,7 +2,7 @@
|
|||
<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>
|
||||
<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" />
|
||||
</head>
|
||||
<body {{ if .Dark }}class="dark"{{end}}>
|
||||
|
|
|
@ -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>
|
||||
<meta name="viewport" content="width=device-width, initial-scale=1" />
|
||||
<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>
|
||||
<body{{ if .Dark }} class="dark"{{end}}>
|
||||
<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}}
|
||||
<div>
|
||||
sorted by:
|
||||
<a {{ if eq .Sort "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 .Sort "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 "Hot"}}class="selected"{{end}} href="{{ .SortBy "Hot"}}">hot</a>
|
||||
<a {{ if eq .CommentSort "Top"}}class="selected"{{end}} href="{{ .SortBy "Top"}}">top</a>
|
||||
<a {{ if eq .CommentSort "New"}}class="selected"{{end}} href="{{ .SortBy "New"}}">new</a>
|
||||
<a {{ if eq .CommentSort "Old"}}class="selected"{{end}} href="{{ .SortBy "Old"}}">old</a>
|
||||
</div>
|
||||
</div>
|
||||
{{ if and .Session (ne .Op "edit_post") }}
|
||||
|
|
|
@ -9,12 +9,18 @@
|
|||
{{ end }}
|
||||
{{ if contains .Sort "Top" }}
|
||||
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>
|
||||
<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>
|
||||
<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>
|
||||
<span>-</span>
|
||||
<a {{ if eq .Sort "TopAll"}}class="selected"{{end}} href="{{ .SortBy "TopAll"}}">all time</a>
|
||||
|
|
|
@ -41,9 +41,21 @@
|
|||
* (last edited <span title="{{.Post.Updated.Time}}">{{ humanize .Post.Updated.Time }}</span>)
|
||||
{{ end }}
|
||||
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
|
||||
<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 class="buttons">
|
||||
{{ if .Post.NSFW }}<span class="nsfw">NSFW</span>{{end}}
|
||||
|
|
|
@ -74,7 +74,7 @@
|
|||
</div>
|
||||
<div>
|
||||
<label>
|
||||
default sort
|
||||
default post sort
|
||||
</label>
|
||||
<select name="DefaultSortType">
|
||||
<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>
|
||||
</select>
|
||||
</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>
|
||||
<label>
|
||||
dark mode
|
||||
|
@ -111,6 +122,12 @@
|
|||
</label>
|
||||
<input type="checkbox" name="autoLoad">
|
||||
</div>
|
||||
<div>
|
||||
<label>
|
||||
hide instance names
|
||||
</label>
|
||||
<input type="checkbox" name="hideInstanceNames" {{ if .HideInstanceNames }}checked{{end}}>
|
||||
</div>
|
||||
<div>
|
||||
<label></label>
|
||||
<input type="submit" value="save">
|
||||
|
|
Loading…
Reference in a new issue