diff --git a/mastodon/status.go b/mastodon/status.go index 816d092..298c666 100644 --- a/mastodon/status.go +++ b/mastodon/status.go @@ -54,6 +54,7 @@ type Status struct { ShowReplies bool `json:"show_replies"` ReplyMap map[string][]ReplyInfo `json:"reply_map"` ReplyNumber int `json:"reply_number"` + ThreadInNewTab bool `json:"thread_in_new_tab"` } // Context hold information for mastodon context. diff --git a/model/notification.go b/model/notification.go new file mode 100644 index 0000000..8b53790 --- /dev/null +++ b/model/notification.go @@ -0,0 +1 @@ +package model diff --git a/model/settings.go b/model/settings.go index bc8f09f..55db08a 100644 --- a/model/settings.go +++ b/model/settings.go @@ -3,4 +3,13 @@ package model type Settings struct { DefaultVisibility string `json:"default_visibility"` CopyScope bool `json:"copy_scope"` + ThreadInNewTab bool `json:"thread_in_new_tab"` +} + +func NewSettings() *Settings { + return &Settings{ + DefaultVisibility: "public", + CopyScope: true, + ThreadInNewTab: false, + } } diff --git a/service/service.go b/service/service.go index d9482c8..c9c48eb 100644 --- a/service/service.go +++ b/service/service.go @@ -90,10 +90,12 @@ func (svc *service) GetAuthUrl(ctx context.Context, instance string) ( } sessionID = util.NewSessionId() - err = svc.sessionRepo.Add(model.Session{ + session := model.Session{ ID: sessionID, InstanceDomain: instance, - }) + Settings: *model.NewSettings(), + } + err = svc.sessionRepo.Add(session) if err != nil { return } @@ -276,6 +278,10 @@ func (svc *service) ServeTimelinePage(ctx context.Context, client io.Writer, return err } + for i := range statuses { + statuses[i].ThreadInNewTab = c.Session.Settings.ThreadInNewTab + } + if len(maxID) > 0 && len(statuses) > 0 { hasPrev = true prevLink = fmt.Sprintf("/timeline/$s?min_id=%s", timelineType, statuses[0].ID) diff --git a/service/transport.go b/service/transport.go index bbf1f06..83eeedf 100644 --- a/service/transport.go +++ b/service/transport.go @@ -52,9 +52,9 @@ func NewHandler(s Service, staticDir string) http.Handler { } http.SetCookie(w, &http.Cookie{ - Name: "session_id", - Value: sessionID, - Expires: time.Now().Add(365 * 24 * time.Hour), + Name: "session_id", + Value: sessionID, + Expires: time.Now().Add(365 * 24 * time.Hour), }) w.Header().Add("Location", url) @@ -354,9 +354,11 @@ func NewHandler(s Service, staticDir string) http.Handler { visibility := req.FormValue("visibility") copyScope := req.FormValue("copy_scope") == "true" + threadInNewTab := req.FormValue("thread_in_new_tab") == "true" settings := &model.Settings{ DefaultVisibility: visibility, CopyScope: copyScope, + ThreadInNewTab: threadInNewTab, } 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) { // TODO remove session from database http.SetCookie(w, &http.Cookie{ - Name: "session_id", - Value: "", - Expires: time.Now(), + Name: "session_id", + Value: "", + Expires: time.Now(), }) w.Header().Add("Location", "/") w.WriteHeader(http.StatusFound) diff --git a/templates/settings.tmpl b/templates/settings.tmpl index e2fd778..df04cb1 100644 --- a/templates/settings.tmpl +++ b/templates/settings.tmpl @@ -16,6 +16,10 @@ +