Add an option to hide unsupported notifications
This commit is contained in:
parent
1c8c661abb
commit
db29c3d874
|
@ -23,9 +23,12 @@ type Notification struct {
|
||||||
}
|
}
|
||||||
|
|
||||||
// GetNotifications return notifications.
|
// 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
|
var notifications []*Notification
|
||||||
params := url.Values{}
|
params := url.Values{}
|
||||||
|
for _, include := range includes {
|
||||||
|
params.Add("include_types[]", include)
|
||||||
|
}
|
||||||
for _, exclude := range excludes {
|
for _, exclude := range excludes {
|
||||||
params.Add("exclude_types[]", exclude)
|
params.Add("exclude_types[]", exclude)
|
||||||
}
|
}
|
||||||
|
|
|
@ -11,6 +11,7 @@ type Settings struct {
|
||||||
FluorideMode bool `json:"fluoride_mode"`
|
FluorideMode bool `json:"fluoride_mode"`
|
||||||
DarkMode bool `json:"dark_mode"`
|
DarkMode bool `json:"dark_mode"`
|
||||||
AntiDopamineMode bool `json:"anti_dopamine_mode"`
|
AntiDopamineMode bool `json:"anti_dopamine_mode"`
|
||||||
|
HideUnsupportedNotifs bool `json:"hide_unsupported_notifs"`
|
||||||
CSS string `json:"css"`
|
CSS string `json:"css"`
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -26,6 +27,7 @@ func NewSettings() *Settings {
|
||||||
FluorideMode: false,
|
FluorideMode: false,
|
||||||
DarkMode: false,
|
DarkMode: false,
|
||||||
AntiDopamineMode: false,
|
AntiDopamineMode: false,
|
||||||
|
HideUnsupportedNotifs: false,
|
||||||
CSS: "",
|
CSS: "",
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -410,18 +410,29 @@ func (s *service) NotificationPage(c *client, maxID string,
|
||||||
var nextLink string
|
var nextLink string
|
||||||
var unreadCount int
|
var unreadCount int
|
||||||
var readID string
|
var readID string
|
||||||
var excludes []string
|
var includes, excludes []string
|
||||||
var pg = mastodon.Pagination{
|
var pg = mastodon.Pagination{
|
||||||
MaxID: maxID,
|
MaxID: maxID,
|
||||||
MinID: minID,
|
MinID: minID,
|
||||||
Limit: 20,
|
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 {
|
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 {
|
if err != nil {
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
|
@ -481,6 +481,7 @@ func NewHandler(s *service, logger *log.Logger, staticDir string) http.Handler {
|
||||||
fluorideMode := c.r.FormValue("fluoride_mode") == "true"
|
fluorideMode := c.r.FormValue("fluoride_mode") == "true"
|
||||||
darkMode := c.r.FormValue("dark_mode") == "true"
|
darkMode := c.r.FormValue("dark_mode") == "true"
|
||||||
antiDopamineMode := c.r.FormValue("anti_dopamine_mode") == "true"
|
antiDopamineMode := c.r.FormValue("anti_dopamine_mode") == "true"
|
||||||
|
hideUnsupportedNotifs := c.r.FormValue("hide_unsupported_notifs") == "true"
|
||||||
css := c.r.FormValue("css")
|
css := c.r.FormValue("css")
|
||||||
|
|
||||||
settings := &model.Settings{
|
settings := &model.Settings{
|
||||||
|
@ -494,6 +495,7 @@ func NewHandler(s *service, logger *log.Logger, staticDir string) http.Handler {
|
||||||
FluorideMode: fluorideMode,
|
FluorideMode: fluorideMode,
|
||||||
DarkMode: darkMode,
|
DarkMode: darkMode,
|
||||||
AntiDopamineMode: antiDopamineMode,
|
AntiDopamineMode: antiDopamineMode,
|
||||||
|
HideUnsupportedNotifs: hideUnsupportedNotifs,
|
||||||
CSS: css,
|
CSS: css,
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -61,6 +61,11 @@
|
||||||
value="true" {{if .Settings.AntiDopamineMode}}checked{{end}}>
|
value="true" {{if .Settings.AntiDopamineMode}}checked{{end}}>
|
||||||
<label for="anti-dopamine-mode"> Enable <abbr title="Remove like/retweet/unread notification count and disable like/retweet/follow notifications">anti-dopamine mode</abbr> </label>
|
<label for="anti-dopamine-mode"> Enable <abbr title="Remove like/retweet/unread notification count and disable like/retweet/follow notifications">anti-dopamine mode</abbr> </label>
|
||||||
</div>
|
</div>
|
||||||
|
<div class="settings-form-field">
|
||||||
|
<input id="hide-unsupported-notifs" name="hide_unsupported_notifs" type="checkbox"
|
||||||
|
value="true" {{if .Settings.HideUnsupportedNotifs}}checked{{end}}>
|
||||||
|
<label for="hide-unsupported-notifs"> Hide unsupported notifications </label>
|
||||||
|
</div>
|
||||||
<div class="settings-form-field">
|
<div class="settings-form-field">
|
||||||
<input id="dark-mode" name="dark_mode" type="checkbox" value="true" {{if .Settings.DarkMode}}checked{{end}}>
|
<input id="dark-mode" name="dark_mode" type="checkbox" value="true" {{if .Settings.DarkMode}}checked{{end}}>
|
||||||
<label for="dark-mode"> Use dark theme </label>
|
<label for="dark-mode"> Use dark theme </label>
|
||||||
|
|
Loading…
Reference in New Issue