From 28695fb8e6b299389347fc8c42f7dc3923b42f24 Mon Sep 17 00:00:00 2001 From: Hyphen Date: Wed, 2 Sep 2020 19:50:48 +0200 Subject: Add the Anti Dopamine feature --- model/settings.go | 2 ++ renderer/model.go | 1 + service/service.go | 9 ++++++++- service/transport.go | 2 ++ templates/notification.tmpl | 4 +++- templates/settings.tmpl | 5 +++++ templates/status.tmpl | 12 +++++++++--- 7 files changed, 30 insertions(+), 5 deletions(-) diff --git a/model/settings.go b/model/settings.go index fa69672..b7c77cf 100644 --- a/model/settings.go +++ b/model/settings.go @@ -9,6 +9,7 @@ type Settings struct { AutoRefreshNotifications bool `json:"auto_refresh_notifications"` FluorideMode bool `json:"fluoride_mode"` DarkMode bool `json:"dark_mode"` + AntiDopamineMode bool `json:"anti_dopamine_mode"` } func NewSettings() *Settings { @@ -21,5 +22,6 @@ func NewSettings() *Settings { AutoRefreshNotifications: false, FluorideMode: false, DarkMode: false, + AntiDopamineMode: false, } } diff --git a/renderer/model.go b/renderer/model.go index 85c73b8..7ea8c22 100644 --- a/renderer/model.go +++ b/renderer/model.go @@ -13,6 +13,7 @@ type Context struct { DarkMode bool CSRFToken string UserID string + AntiDopamineMode bool } type NavData struct { diff --git a/service/service.go b/service/service.go index 35ce3bd..cc59cb6 100644 --- a/service/service.go +++ b/service/service.go @@ -116,6 +116,7 @@ func getRendererContext(c *model.Client) *renderer.Context { DarkMode: settings.DarkMode, CSRFToken: session.CSRFToken, UserID: session.UserID, + AntiDopamineMode: settings.AntiDopamineMode, } } @@ -402,13 +403,19 @@ func (svc *service) ServeNotificationPage(c *model.Client, maxID string, var nextLink string var unreadCount int var readID string + var excludes []string var pg = mastodon.Pagination{ MaxID: maxID, MinID: minID, Limit: 20, } - notifications, err := c.GetNotifications(ctx, &pg) + dope := c.Session.Settings.AntiDopamineMode + if dope { + excludes = append(excludes, "follow", "favourite", "reblog") + } + + notifications, err := c.GetNotifications(ctx, &pg, excludes...) if err != nil { return } diff --git a/service/transport.go b/service/transport.go index 131c580..7d27a84 100644 --- a/service/transport.go +++ b/service/transport.go @@ -591,6 +591,7 @@ func NewHandler(s Service, staticDir string) http.Handler { arn := req.FormValue("auto_refresh_notifications") == "true" fluorideMode := req.FormValue("fluoride_mode") == "true" darkMode := req.FormValue("dark_mode") == "true" + antiDopamineMode := req.FormValue("anti_dopamine_mode") == "true" settings := &model.Settings{ DefaultVisibility: visibility, @@ -601,6 +602,7 @@ func NewHandler(s Service, staticDir string) http.Handler { AutoRefreshNotifications: arn, FluorideMode: fluorideMode, DarkMode: darkMode, + AntiDopamineMode: antiDopamineMode, } err := s.SaveSettings(c, settings) diff --git a/templates/notification.tmpl b/templates/notification.tmpl index b1855a6..227bc57 100644 --- a/templates/notification.tmpl +++ b/templates/notification.tmpl @@ -3,7 +3,9 @@
Notifications - {{if gt .UnreadCount 0}}({{.UnreadCount }}){{end}} + {{if and (not $.Ctx.AntiDopamineMode) (gt .UnreadCount 0)}} + ({{.UnreadCount }}) + {{end}}
refresh {{if .ReadID}} diff --git a/templates/settings.tmpl b/templates/settings.tmpl index d0710c3..ab5f03c 100644 --- a/templates/settings.tmpl +++ b/templates/settings.tmpl @@ -41,6 +41,11 @@
+
+ + +
diff --git a/templates/status.tmpl b/templates/status.tmpl index 3c0533b..de0909b 100644 --- a/templates/status.tmpl +++ b/templates/status.tmpl @@ -160,7 +160,9 @@ reply - {{if .RepliesCount}} ({{DisplayInteractionCount .RepliesCount}}) {{end}} + {{if and (not $.Ctx.AntiDopamineMode) .RepliesCount}} + ({{DisplayInteractionCount .RepliesCount}}) + {{end}}
@@ -184,7 +186,9 @@ {{end}} {{end}} - {{if .ReblogsCount}} ({{DisplayInteractionCount .ReblogsCount}}) {{end}} + {{if and (not $.Ctx.AntiDopamineMode) .ReblogsCount}} + ({{DisplayInteractionCount .ReblogsCount}}) + {{end}}
@@ -202,7 +206,9 @@ {{end}} - {{if .FavouritesCount}} ({{DisplayInteractionCount .FavouritesCount}}) {{end}} + {{if and (not $.Ctx.AntiDopamineMode) .FavouritesCount}} + ({{DisplayInteractionCount .FavouritesCount}}) + {{end}}
-- cgit v1.2.3