Add default settings

This commit is contained in:
r 2019-12-29 11:32:24 +00:00
parent ede1bb4275
commit 9e556721c5
7 changed files with 33 additions and 10 deletions

View File

@ -54,6 +54,7 @@ type Status struct {
ShowReplies bool `json:"show_replies"` ShowReplies bool `json:"show_replies"`
ReplyMap map[string][]ReplyInfo `json:"reply_map"` ReplyMap map[string][]ReplyInfo `json:"reply_map"`
ReplyNumber int `json:"reply_number"` ReplyNumber int `json:"reply_number"`
ThreadInNewTab bool `json:"thread_in_new_tab"`
} }
// Context hold information for mastodon context. // Context hold information for mastodon context.

1
model/notification.go Normal file
View File

@ -0,0 +1 @@
package model

View File

@ -3,4 +3,13 @@ package model
type Settings struct { type Settings struct {
DefaultVisibility string `json:"default_visibility"` DefaultVisibility string `json:"default_visibility"`
CopyScope bool `json:"copy_scope"` CopyScope bool `json:"copy_scope"`
ThreadInNewTab bool `json:"thread_in_new_tab"`
}
func NewSettings() *Settings {
return &Settings{
DefaultVisibility: "public",
CopyScope: true,
ThreadInNewTab: false,
}
} }

View File

@ -90,10 +90,12 @@ func (svc *service) GetAuthUrl(ctx context.Context, instance string) (
} }
sessionID = util.NewSessionId() sessionID = util.NewSessionId()
err = svc.sessionRepo.Add(model.Session{ session := model.Session{
ID: sessionID, ID: sessionID,
InstanceDomain: instance, InstanceDomain: instance,
}) Settings: *model.NewSettings(),
}
err = svc.sessionRepo.Add(session)
if err != nil { if err != nil {
return return
} }
@ -276,6 +278,10 @@ func (svc *service) ServeTimelinePage(ctx context.Context, client io.Writer,
return err return err
} }
for i := range statuses {
statuses[i].ThreadInNewTab = c.Session.Settings.ThreadInNewTab
}
if len(maxID) > 0 && len(statuses) > 0 { if len(maxID) > 0 && len(statuses) > 0 {
hasPrev = true hasPrev = true
prevLink = fmt.Sprintf("/timeline/$s?min_id=%s", timelineType, statuses[0].ID) prevLink = fmt.Sprintf("/timeline/$s?min_id=%s", timelineType, statuses[0].ID)

View File

@ -52,9 +52,9 @@ func NewHandler(s Service, staticDir string) http.Handler {
} }
http.SetCookie(w, &http.Cookie{ http.SetCookie(w, &http.Cookie{
Name: "session_id", Name: "session_id",
Value: sessionID, Value: sessionID,
Expires: time.Now().Add(365 * 24 * time.Hour), Expires: time.Now().Add(365 * 24 * time.Hour),
}) })
w.Header().Add("Location", url) w.Header().Add("Location", url)
@ -354,9 +354,11 @@ func NewHandler(s Service, staticDir string) http.Handler {
visibility := req.FormValue("visibility") visibility := req.FormValue("visibility")
copyScope := req.FormValue("copy_scope") == "true" copyScope := req.FormValue("copy_scope") == "true"
threadInNewTab := req.FormValue("thread_in_new_tab") == "true"
settings := &model.Settings{ settings := &model.Settings{
DefaultVisibility: visibility, DefaultVisibility: visibility,
CopyScope: copyScope, CopyScope: copyScope,
ThreadInNewTab: threadInNewTab,
} }
err := s.SaveSettings(ctx, w, nil, settings) err := s.SaveSettings(ctx, w, nil, settings)
@ -372,9 +374,9 @@ func NewHandler(s Service, staticDir string) http.Handler {
r.HandleFunc("/signout", func(w http.ResponseWriter, req *http.Request) { r.HandleFunc("/signout", func(w http.ResponseWriter, req *http.Request) {
// TODO remove session from database // TODO remove session from database
http.SetCookie(w, &http.Cookie{ http.SetCookie(w, &http.Cookie{
Name: "session_id", Name: "session_id",
Value: "", Value: "",
Expires: time.Now(), Expires: time.Now(),
}) })
w.Header().Add("Location", "/") w.Header().Add("Location", "/")
w.WriteHeader(http.StatusFound) w.WriteHeader(http.StatusFound)

View File

@ -16,6 +16,10 @@
<input id="copy-scope" name="copy_scope" type="checkbox" value="true" {{if .Settings.CopyScope}}checked{{end}}> <input id="copy-scope" name="copy_scope" type="checkbox" value="true" {{if .Settings.CopyScope}}checked{{end}}>
<label for="copy-scope"> Copy scope when replying </label> <label for="copy-scope"> Copy scope when replying </label>
</div> </div>
<div class="settings-form-field">
<input id="thread-tab" name="thread_in_new_tab" type="checkbox" value="true" {{if .Settings.ThreadInNewTab}}checked{{end}}>
<label for="thread-tab"> Open threads in new tab from timeline </label>
</div>
<button type="submit"> Save </button> <button type="submit"> Save </button>
</form> </form>

View File

@ -90,7 +90,7 @@
<a class="status-you" href="/thread/{{.ID}}?reply=true#status-{{.ID}}" title="reply"> <a class="status-you" href="/thread/{{.ID}}?reply=true#status-{{.ID}}" title="reply">
<i class="fa fa-reply"></i> <i class="fa fa-reply"></i>
</a> </a>
<a class="status-action-count" href="/thread/{{.ID}}#status-{{.ID}}"> <a class="status-action-count" href="/thread/{{.ID}}#status-{{.ID}}" {{if .ThreadInNewTab}}target="_blank"{{end}}>
<span> {{DisplayInteractionCount .RepliesCount}} </span> <span> {{DisplayInteractionCount .RepliesCount}} </span>
</a> </a>
</div> </div>
@ -129,7 +129,7 @@
</a> </a>
</div> </div>
<div class="status-action"> <div class="status-action">
<a class="status-time" href="/thread/{{.ID}}#status-{{.ID}}"> <a class="status-time" href="/thread/{{.ID}}#status-{{.ID}}" {{if .ThreadInNewTab}}target="_blank"{{end}}>
<time datetime="{{FormatTimeRFC3339 .CreatedAt}}" title="{{.CreatedAt}}"> {{TimeSince .CreatedAt}} </time> <time datetime="{{FormatTimeRFC3339 .CreatedAt}}" title="{{.CreatedAt}}"> {{TimeSince .CreatedAt}} </time>
</a> </a>
</div> </div>