From c3d90539e9a7addd3c41f44b864b14bde60958dc Mon Sep 17 00:00:00 2001 From: r Date: Sat, 14 Nov 2020 14:08:16 +0000 Subject: Add notification interval setting It replaces the "Auto refresh notifications" checkbox --- model/settings.go | 40 ++++++++++++++++++++-------------------- renderer/model.go | 12 ++++++------ service/service.go | 7 ++++++- service/transport.go | 22 +++++++++++----------- templates/header.tmpl | 4 ++-- templates/settings.tmpl | 15 +++++++++++---- 6 files changed, 56 insertions(+), 44 deletions(-) diff --git a/model/settings.go b/model/settings.go index 337a6a3..6d17901 100644 --- a/model/settings.go +++ b/model/settings.go @@ -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, } } diff --git a/renderer/model.go b/renderer/model.go index 0e5204a..1dcb404 100644 --- a/renderer/model.go +++ b/renderer/model.go @@ -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 { diff --git a/service/service.go b/service/service.go index 48aafda..1ba99da 100644 --- a/service/service.go +++ b/service/service.go @@ -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 diff --git a/service/transport.go b/service/transport.go index 6c0975d..3c9392a 100644 --- a/service/transport.go +++ b/service/transport.go @@ -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) diff --git a/templates/header.tmpl b/templates/header.tmpl index 0c81b72..df2b6af 100644 --- a/templates/header.tmpl +++ b/templates/header.tmpl @@ -14,8 +14,8 @@ {{if $.Ctx.AntiDopamineMode}} {{end}} - {{if .AutoRefresh}} - + {{if .RefreshInterval}} + {{end}} {{if gt .Count 0}}({{.Count}}){{end}} {{.Title}} diff --git a/templates/settings.tmpl b/templates/settings.tmpl index 972e1a2..baeb64d 100644 --- a/templates/settings.tmpl +++ b/templates/settings.tmpl @@ -22,6 +22,17 @@ +
+ + +
@@ -38,10 +49,6 @@
-
- - -
-- cgit v1.2.3