aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorr <r@freesoftwareextremist.com>2020-10-19 06:51:23 +0000
committerr <r@freesoftwareextremist.com>2020-10-19 06:51:23 +0000
commitfdd9b8fd2bf1688187dda2cb801232c744fe26e0 (patch)
treef729fa705e254644fc188639e6dbf55d769df4f6
parentef41ff32e2cb16a3757b952a33d29528482685b8 (diff)
downloadbloat-fdd9b8fd2bf1688187dda2cb801232c744fe26e0.tar.gz
bloat-fdd9b8fd2bf1688187dda2cb801232c744fe26e0.zip
Add setting for default format
-rw-r--r--model/post.go1
-rw-r--r--model/settings.go2
-rw-r--r--renderer/model.go3
-rw-r--r--service/service.go9
-rw-r--r--service/transport.go2
-rw-r--r--templates/postform.tmpl5
-rw-r--r--templates/settings.tmpl9
7 files changed, 26 insertions, 5 deletions
diff --git a/model/post.go b/model/post.go
index 7cfead7..831f74f 100644
--- a/model/post.go
+++ b/model/post.go
@@ -7,6 +7,7 @@ type PostFormat struct {
type PostContext struct {
DefaultVisibility string
+ DefaultFormat string
ReplyContext *ReplyContext
Formats []PostFormat
DarkMode bool
diff --git a/model/settings.go b/model/settings.go
index 03e9581..337a6a3 100644
--- a/model/settings.go
+++ b/model/settings.go
@@ -2,6 +2,7 @@ package model
type Settings struct {
DefaultVisibility string `json:"default_visibility"`
+ DefaultFormat string `json:"default_format"`
CopyScope bool `json:"copy_scope"`
ThreadInNewTab bool `json:"thread_in_new_tab"`
HideAttachments bool `json:"hide_attachments"`
@@ -15,6 +16,7 @@ type Settings struct {
func NewSettings() *Settings {
return &Settings{
DefaultVisibility: "public",
+ DefaultFormat: "",
CopyScope: true,
ThreadInNewTab: false,
HideAttachments: false,
diff --git a/renderer/model.go b/renderer/model.go
index 4b177db..0e5204a 100644
--- a/renderer/model.go
+++ b/renderer/model.go
@@ -121,5 +121,6 @@ type SearchData struct {
type SettingsData struct {
*CommonData
- Settings *model.Settings
+ Settings *model.Settings
+ PostFormats []model.PostFormat
}
diff --git a/service/service.go b/service/service.go
index 447f186..23685c4 100644
--- a/service/service.go
+++ b/service/service.go
@@ -4,8 +4,8 @@ import (
"context"
"errors"
"fmt"
- "mime/multipart"
"html/template"
+ "mime/multipart"
"net/url"
"strings"
@@ -198,6 +198,7 @@ func (svc *service) ServeNavPage(c *model.Client) (err error) {
postContext := model.PostContext{
DefaultVisibility: c.Session.Settings.DefaultVisibility,
+ DefaultFormat: c.Session.Settings.DefaultFormat,
Formats: svc.postFormats,
}
@@ -326,6 +327,7 @@ func (svc *service) ServeThreadPage(c *model.Client, id string, reply bool) (err
postContext = model.PostContext{
DefaultVisibility: visibility,
+ DefaultFormat: c.Session.Settings.DefaultFormat,
Formats: svc.postFormats,
ReplyContext: &model.ReplyContext{
InReplyToID: id,
@@ -686,8 +688,9 @@ func (svc *service) ServeSearchPage(c *model.Client,
func (svc *service) ServeSettingsPage(c *model.Client) (err error) {
commonData := svc.getCommonData(c, "settings")
data := &renderer.SettingsData{
- CommonData: commonData,
- Settings: &c.Session.Settings,
+ CommonData: commonData,
+ Settings: &c.Session.Settings,
+ PostFormats: svc.postFormats,
}
rCtx := getRendererContext(c)
diff --git a/service/transport.go b/service/transport.go
index 4f73c5e..6c0975d 100644
--- a/service/transport.go
+++ b/service/transport.go
@@ -584,6 +584,7 @@ func NewHandler(s Service, staticDir string) http.Handler {
settings := func(w http.ResponseWriter, req *http.Request) {
c := newClient(w, req, req.FormValue("csrf_token"))
visibility := req.FormValue("visibility")
+ format := req.FormValue("format")
copyScope := req.FormValue("copy_scope") == "true"
threadInNewTab := req.FormValue("thread_in_new_tab") == "true"
hideAttachments := req.FormValue("hide_attachments") == "true"
@@ -595,6 +596,7 @@ func NewHandler(s Service, staticDir string) http.Handler {
settings := &model.Settings{
DefaultVisibility: visibility,
+ DefaultFormat: format,
CopyScope: copyScope,
ThreadInNewTab: threadInNewTab,
HideAttachments: hideAttachments,
diff --git a/templates/postform.tmpl b/templates/postform.tmpl
index ac77486..b38cb9d 100644
--- a/templates/postform.tmpl
+++ b/templates/postform.tmpl
@@ -16,8 +16,11 @@
<div>
{{if gt (len .Formats) 0}}
<span class="post-form-field">
+ {{$defFormat := .DefaultFormat}}
<select id="post-format" name="format" accesskey="F" title="Format (F)">
- {{range .Formats}} <option value="{{.Type}}">{{.Name}}</option> {{end}}
+ {{range .Formats}}
+ <option value="{{.Type}}" {{if eq $defFormat .Type}}selected{{end}}>{{.Name}}</option>
+ {{end}}
</select>
</span>
{{end}}
diff --git a/templates/settings.tmpl b/templates/settings.tmpl
index 67386a4..972e1a2 100644
--- a/templates/settings.tmpl
+++ b/templates/settings.tmpl
@@ -5,6 +5,15 @@
<form id="settings-form" action="/settings" method="POST">
<input type="hidden" name="csrf_token" value="{{$.Ctx.CSRFToken}}">
<div class="settings-form-field">
+ <label for="visibility"> Default format </label>
+ {{$defFormat := .Settings.DefaultFormat}}
+ <select id="post-format" name="format">
+ {{range .PostFormats}}
+ <option value="{{.Type}}" {{if eq $defFormat .Type}}selected{{end}}>{{.Name}}</option>
+ {{end}}
+ </select>
+ </div>
+ <div class="settings-form-field">
<label for="visibility"> Default scope </label>
<select id="visibility" name="visibility">
<option value="public" {{if eq .Settings.DefaultVisibility "public"}}selected{{end}}>Public</option>