Add default settings
authorr <r@freesoftwareextremist.com>
Sun, 29 Dec 2019 11:32:24 +0000 (11:32 +0000)
committerr <r@freesoftwareextremist.com>
Sun, 29 Dec 2019 11:32:24 +0000 (11:32 +0000)
mastodon/status.go
model/notification.go [new file with mode: 0644]
model/settings.go
service/service.go
service/transport.go
templates/settings.tmpl
templates/status.tmpl

index 816d09269a43fa9700a5c4cd429aaf3fdf6d888f..298c6663b3171908b778ef000f4ca1f232015600 100644 (file)
@@ -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 (file)
index 0000000..8b53790
--- /dev/null
@@ -0,0 +1 @@
+package model
index bc8f09fbdea017cb9bcbc8e32bf5d692778291a3..55db08af6bacac99187f7de818d04566d4a52670 100644 (file)
@@ -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,
+       }
 }
index d9482c87e05195d5843c80d3821802ad9c9aad45..c9c48ebd60d22b667737a4a00a558d58f412edad 100644 (file)
@@ -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)
index bbf1f063c78f7892e43f59ccf3501b45de6b4ced..83eeedfab3ef6c6510d86e40e0968a9c92ad1776 100644 (file)
@@ -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)
index e2fd778e461decab37fb526b72615fad903cf542..df04cb1e23bc0d455093b2d2bb7b35f6a17e49b9 100644 (file)
                <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>
        </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>
 </form>
 
index 4e975ad3492f67725c589a8ac6cac838ec809db3..4c9406207caa4825378574f36dd4cdfbe4b9d7fa 100644 (file)
@@ -90,7 +90,7 @@
                                        <a class="status-you" href="/thread/{{.ID}}?reply=true#status-{{.ID}}" title="reply"> 
                                                <i class="fa fa-reply"></i>
                                        </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>
                                        </a>
                                </div>
                                        </a>
                                </div>
                                <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> 
                                        </a>
                                </div>