Add notification interval setting
authorr <r@freesoftwareextremist.com>
Sat, 14 Nov 2020 14:08:16 +0000 (14:08 +0000)
committerr <r@freesoftwareextremist.com>
Sat, 14 Nov 2020 14:22:34 +0000 (14:22 +0000)
It replaces the "Auto refresh notifications" checkbox

model/settings.go
renderer/model.go
service/service.go
service/transport.go
templates/header.tmpl
templates/settings.tmpl

index 337a6a345a66ff0830b0925d4220145adb8151ff..6d179018baf6c1c970b9c3189461a6cb8fb53f84 100644 (file)
@@ -1,29 +1,29 @@
 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"`
-       MaskNSFW                 bool   `json:"mask_nfsw"`
-       AutoRefreshNotifications bool   `json:"auto_refresh_notifications"`
-       FluorideMode             bool   `json:"fluoride_mode"`
-       DarkMode                 bool   `json:"dark_mode"`
-       AntiDopamineMode         bool   `json:"anti_dopamine_mode"`
+       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"`
+       MaskNSFW             bool   `json:"mask_nfsw"`
+       NotificationInterval int    `json:"notifications_interval"`
+       FluorideMode         bool   `json:"fluoride_mode"`
+       DarkMode             bool   `json:"dark_mode"`
+       AntiDopamineMode     bool   `json:"anti_dopamine_mode"`
 }
 
 func NewSettings() *Settings {
        return &Settings{
-               DefaultVisibility:        "public",
-               DefaultFormat:            "",
-               CopyScope:                true,
-               ThreadInNewTab:           false,
-               HideAttachments:          false,
-               MaskNSFW:                 true,
-               AutoRefreshNotifications: false,
-               FluorideMode:             false,
-               DarkMode:                 false,
-               AntiDopamineMode:         false,
+               DefaultVisibility:    "public",
+               DefaultFormat:        "",
+               CopyScope:            true,
+               ThreadInNewTab:       false,
+               HideAttachments:      false,
+               MaskNSFW:             true,
+               NotificationInterval: 0,
+               FluorideMode:         false,
+               DarkMode:             false,
+               AntiDopamineMode:     false,
        }
 }
index 0e5204a9753e4798241eeed3611e0565ea6458f7..1dcb40452586ff51eda927cf46728e7c4d278cdf 100644 (file)
@@ -23,12 +23,12 @@ type NavData struct {
 }
 
 type CommonData struct {
-       Title       string
-       CustomCSS   string
-       CSRFToken   string
-       Count       int
-       AutoRefresh bool
-       Target      string
+       Title           string
+       CustomCSS       string
+       CSRFToken       string
+       Count           int
+       RefreshInterval int
+       Target          string
 }
 
 type ErrorData struct {
index 48aafdaafd922ff080f342c99d60bc235fdf2c60..1ba99da872063df437f2afed68f37c39d01570c4 100644 (file)
@@ -434,7 +434,7 @@ func (svc *service) ServeNotificationPage(c *model.Client, maxID string,
        }
 
        commonData := svc.getCommonData(c, "notifications")
-       commonData.AutoRefresh = c.Session.Settings.AutoRefreshNotifications
+       commonData.RefreshInterval = c.Session.Settings.NotificationInterval
        commonData.Target = "main"
        commonData.Count = unreadCount
        data := &renderer.NotificationData{
@@ -932,6 +932,11 @@ func (svc *service) UnSubscribe(c *model.Client, id string) (err error) {
 }
 
 func (svc *service) SaveSettings(c *model.Client, s *model.Settings) (err error) {
+       switch s.NotificationInterval {
+       case 0, 30, 60, 120, 300, 600:
+       default:
+               return errInvalidArgument
+       }
        session, err := svc.sessionRepo.Get(c.Session.ID)
        if err != nil {
                return
index 6c0975dba865a67b665b0acefacb9c8b0ea71593..3c9392a4a71c625ca6fbe7fdc684bec29bcb4535 100644 (file)
@@ -589,22 +589,22 @@ func NewHandler(s Service, staticDir string) http.Handler {
                threadInNewTab := req.FormValue("thread_in_new_tab") == "true"
                hideAttachments := req.FormValue("hide_attachments") == "true"
                maskNSFW := req.FormValue("mask_nsfw") == "true"
-               arn := req.FormValue("auto_refresh_notifications") == "true"
+               ni, _ := strconv.Atoi(req.FormValue("notification_interval"))
                fluorideMode := req.FormValue("fluoride_mode") == "true"
                darkMode := req.FormValue("dark_mode") == "true"
                antiDopamineMode := req.FormValue("anti_dopamine_mode") == "true"
 
                settings := &model.Settings{
-                       DefaultVisibility:        visibility,
-                       DefaultFormat:            format,
-                       CopyScope:                copyScope,
-                       ThreadInNewTab:           threadInNewTab,
-                       HideAttachments:          hideAttachments,
-                       MaskNSFW:                 maskNSFW,
-                       AutoRefreshNotifications: arn,
-                       FluorideMode:             fluorideMode,
-                       DarkMode:                 darkMode,
-                       AntiDopamineMode:         antiDopamineMode,
+                       DefaultVisibility:    visibility,
+                       DefaultFormat:        format,
+                       CopyScope:            copyScope,
+                       ThreadInNewTab:       threadInNewTab,
+                       HideAttachments:      hideAttachments,
+                       MaskNSFW:             maskNSFW,
+                       NotificationInterval: ni,
+                       FluorideMode:         fluorideMode,
+                       DarkMode:             darkMode,
+                       AntiDopamineMode:     antiDopamineMode,
                }
 
                err := s.SaveSettings(c, settings)
index 0c81b7229c997ca0a59cb6200e76d63960bdcc32..df2b6afbb626552ce1c670e9c5d828c75eb1572e 100644 (file)
@@ -14,8 +14,8 @@
        {{if $.Ctx.AntiDopamineMode}}
        <meta name="antidopamine_mode" content="{{$.Ctx.AntiDopamineMode}}">
        {{end}}
-       {{if .AutoRefresh}}
-       <meta http-equiv="refresh" content="30">
+       {{if .RefreshInterval}}
+       <meta http-equiv="refresh" content="{{.RefreshInterval}}">
        {{end}}
        <title> {{if gt .Count 0}}({{.Count}}){{end}} {{.Title}} </title>
        <link rel="stylesheet" href="/static/style.css">
index 972e1a2eff9b6e38bc0aa6f721eaf0c14adacbeb..baeb64dcc1dd6975155499b19a3b7b1f16161201 100644 (file)
                        <option value="direct" {{if eq .Settings.DefaultVisibility "direct"}}selected{{end}}>Direct</option>
                </select>
        </div>
+       <div class="settings-form-field">
+               <label for="notification-interval"> Refresh Notifications </label>
+               <select id="notification-interval" name="notification_interval">
+                       <option value="0" {{if eq .Settings.NotificationInterval 0}}selected{{end}}>Disabled</option>
+                       <option value="30" {{if eq .Settings.NotificationInterval 30}}selected{{end}}>After 30s</option>
+                       <option value="60" {{if eq .Settings.NotificationInterval 60}}selected{{end}}>After 1m</option>
+                       <option value="120" {{if eq .Settings.NotificationInterval 120}}selected{{end}}>After 2m</option>
+                       <option value="300" {{if eq .Settings.NotificationInterval 300}}selected{{end}}>After 5m</option>
+                       <option value="600" {{if eq .Settings.NotificationInterval 600}}selected{{end}}>After 10m</option>
+               </select>
+       </div>
        <div class="settings-form-field">
                <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>
                <input id="mask-nsfw" name="mask_nsfw" type="checkbox" value="true" {{if .Settings.MaskNSFW}}checked{{end}}>
                <label for="mask-nsfw"> Mask NSFW attachments </label>
        </div>
-       <div class="settings-form-field">
-               <input id="auto-refresh-notifications" name="auto_refresh_notifications" type="checkbox" value="true" {{if .Settings.AutoRefreshNotifications}}checked{{end}}>
-               <label for="auto-refresh-notifications"> Auto refresh notifications </label>
-       </div>
        <div class="settings-form-field">
                <input id="fluoride-mode" name="fluoride_mode" type="checkbox" value="true" {{if .Settings.FluorideMode}}checked{{end}}>
                <label for="fluoride-mode"> Enable <abbr title="Enable JavaScript based functionality, e.g., like/retweet without page reload and reply preview on thread page">fluoride mode</abbr> </label>