From db29c3d87404677c9c02f62097d8a0307cd8d5da Mon Sep 17 00:00:00 2001 From: r Date: Mon, 13 Dec 2021 13:58:15 +0000 Subject: Add an option to hide unsupported notifications --- mastodon/notification.go | 5 ++++- model/settings.go | 46 ++++++++++++++++++++++++---------------------- service/service.go | 17 ++++++++++++++--- service/transport.go | 24 +++++++++++++----------- templates/settings.tmpl | 5 +++++ 5 files changed, 60 insertions(+), 37 deletions(-) diff --git a/mastodon/notification.go b/mastodon/notification.go index 656e6a1..e94f901 100644 --- a/mastodon/notification.go +++ b/mastodon/notification.go @@ -23,9 +23,12 @@ type Notification struct { } // GetNotifications return notifications. -func (c *Client) GetNotifications(ctx context.Context, pg *Pagination, excludes []string) ([]*Notification, error) { +func (c *Client) GetNotifications(ctx context.Context, pg *Pagination, includes, excludes []string) ([]*Notification, error) { var notifications []*Notification params := url.Values{} + for _, include := range includes { + params.Add("include_types[]", include) + } for _, exclude := range excludes { params.Add("exclude_types[]", exclude) } diff --git a/model/settings.go b/model/settings.go index c4e8aec..1f83c75 100644 --- a/model/settings.go +++ b/model/settings.go @@ -1,31 +1,33 @@ 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"` - NotificationInterval int `json:"notifications_interval"` - FluorideMode bool `json:"fluoride_mode"` - DarkMode bool `json:"dark_mode"` - AntiDopamineMode bool `json:"anti_dopamine_mode"` - CSS string `json:"css"` + 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"` + HideUnsupportedNotifs bool `json:"hide_unsupported_notifs"` + CSS string `json:"css"` } func NewSettings() *Settings { return &Settings{ - DefaultVisibility: "public", - DefaultFormat: "", - CopyScope: true, - ThreadInNewTab: false, - HideAttachments: false, - MaskNSFW: true, - NotificationInterval: 0, - FluorideMode: false, - DarkMode: false, - AntiDopamineMode: false, - CSS: "", + DefaultVisibility: "public", + DefaultFormat: "", + CopyScope: true, + ThreadInNewTab: false, + HideAttachments: false, + MaskNSFW: true, + NotificationInterval: 0, + FluorideMode: false, + DarkMode: false, + AntiDopamineMode: false, + HideUnsupportedNotifs: false, + CSS: "", } } diff --git a/service/service.go b/service/service.go index 7122666..9cad731 100644 --- a/service/service.go +++ b/service/service.go @@ -410,18 +410,29 @@ func (s *service) NotificationPage(c *client, maxID string, var nextLink string var unreadCount int var readID string - var excludes []string + var includes, excludes []string var pg = mastodon.Pagination{ MaxID: maxID, MinID: minID, Limit: 20, } + if c.s.Settings.HideUnsupportedNotifs { + // Explicitly include the supported types. + // For now, only Pleroma supports this option, Mastadon + // will simply ignore the unknown params. + includes = []string{"follow", "follow_request", "mention", "reblog", "favourite"} + + // Explicitly exclude the unsupported types. + // Pleroma prioritizes includes over excludes, but we + // still specify excludes to make it work with Mastadon. + excludes = []string{"poll"} + } if c.s.Settings.AntiDopamineMode { - excludes = []string{"follow", "favourite", "reblog"} + excludes = append(excludes, "follow", "favourite", "reblog") } - notifications, err := c.GetNotifications(c.ctx, &pg, excludes) + notifications, err := c.GetNotifications(c.ctx, &pg, includes, excludes) if err != nil { return } diff --git a/service/transport.go b/service/transport.go index a7912e6..615fe2a 100644 --- a/service/transport.go +++ b/service/transport.go @@ -481,20 +481,22 @@ func NewHandler(s *service, logger *log.Logger, staticDir string) http.Handler { fluorideMode := c.r.FormValue("fluoride_mode") == "true" darkMode := c.r.FormValue("dark_mode") == "true" antiDopamineMode := c.r.FormValue("anti_dopamine_mode") == "true" + hideUnsupportedNotifs := c.r.FormValue("hide_unsupported_notifs") == "true" css := c.r.FormValue("css") settings := &model.Settings{ - DefaultVisibility: visibility, - DefaultFormat: format, - CopyScope: copyScope, - ThreadInNewTab: threadInNewTab, - HideAttachments: hideAttachments, - MaskNSFW: maskNSFW, - NotificationInterval: ni, - FluorideMode: fluorideMode, - DarkMode: darkMode, - AntiDopamineMode: antiDopamineMode, - CSS: css, + DefaultVisibility: visibility, + DefaultFormat: format, + CopyScope: copyScope, + ThreadInNewTab: threadInNewTab, + HideAttachments: hideAttachments, + MaskNSFW: maskNSFW, + NotificationInterval: ni, + FluorideMode: fluorideMode, + DarkMode: darkMode, + AntiDopamineMode: antiDopamineMode, + HideUnsupportedNotifs: hideUnsupportedNotifs, + CSS: css, } err := s.SaveSettings(c, settings) diff --git a/templates/settings.tmpl b/templates/settings.tmpl index 6bae9c7..ebb0458 100644 --- a/templates/settings.tmpl +++ b/templates/settings.tmpl @@ -61,6 +61,11 @@ value="true" {{if .Settings.AntiDopamineMode}}checked{{end}}> +
+ + +
-- cgit v1.2.3