Add the Anti Dopamine feature

This commit is contained in:
Hyphen 2020-09-02 19:50:48 +02:00 committed by r
parent 71c5da7b3b
commit 28695fb8e6
7 changed files with 30 additions and 5 deletions

View File

@ -9,6 +9,7 @@ type Settings struct {
AutoRefreshNotifications bool `json:"auto_refresh_notifications"` AutoRefreshNotifications bool `json:"auto_refresh_notifications"`
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"`
} }
func NewSettings() *Settings { func NewSettings() *Settings {
@ -21,5 +22,6 @@ func NewSettings() *Settings {
AutoRefreshNotifications: false, AutoRefreshNotifications: false,
FluorideMode: false, FluorideMode: false,
DarkMode: false, DarkMode: false,
AntiDopamineMode: false,
} }
} }

View File

@ -13,6 +13,7 @@ type Context struct {
DarkMode bool DarkMode bool
CSRFToken string CSRFToken string
UserID string UserID string
AntiDopamineMode bool
} }
type NavData struct { type NavData struct {

View File

@ -116,6 +116,7 @@ func getRendererContext(c *model.Client) *renderer.Context {
DarkMode: settings.DarkMode, DarkMode: settings.DarkMode,
CSRFToken: session.CSRFToken, CSRFToken: session.CSRFToken,
UserID: session.UserID, UserID: session.UserID,
AntiDopamineMode: settings.AntiDopamineMode,
} }
} }
@ -402,13 +403,19 @@ func (svc *service) ServeNotificationPage(c *model.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 pg = mastodon.Pagination{ var pg = mastodon.Pagination{
MaxID: maxID, MaxID: maxID,
MinID: minID, MinID: minID,
Limit: 20, 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 { if err != nil {
return return
} }

View File

@ -591,6 +591,7 @@ func NewHandler(s Service, staticDir string) http.Handler {
arn := req.FormValue("auto_refresh_notifications") == "true" arn := req.FormValue("auto_refresh_notifications") == "true"
fluorideMode := req.FormValue("fluoride_mode") == "true" fluorideMode := req.FormValue("fluoride_mode") == "true"
darkMode := req.FormValue("dark_mode") == "true" darkMode := req.FormValue("dark_mode") == "true"
antiDopamineMode := req.FormValue("anti_dopamine_mode") == "true"
settings := &model.Settings{ settings := &model.Settings{
DefaultVisibility: visibility, DefaultVisibility: visibility,
@ -601,6 +602,7 @@ func NewHandler(s Service, staticDir string) http.Handler {
AutoRefreshNotifications: arn, AutoRefreshNotifications: arn,
FluorideMode: fluorideMode, FluorideMode: fluorideMode,
DarkMode: darkMode, DarkMode: darkMode,
AntiDopamineMode: antiDopamineMode,
} }
err := s.SaveSettings(c, settings) err := s.SaveSettings(c, settings)

View File

@ -3,7 +3,9 @@
<div class="notification-title-container"> <div class="notification-title-container">
<div class="notification-title"> <div class="notification-title">
Notifications Notifications
{{if gt .UnreadCount 0}}({{.UnreadCount }}){{end}} {{if and (not $.Ctx.AntiDopamineMode) (gt .UnreadCount 0)}}
({{.UnreadCount }})
{{end}}
</div> </div>
<a class="notification-refresh" href="/notifications" target="_self">refresh</a> <a class="notification-refresh" href="/notifications" target="_self">refresh</a>
{{if .ReadID}} {{if .ReadID}}

View File

@ -41,6 +41,11 @@
<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>
</div> </div>
<div class="settings-form-field">
<input id="anti-dopamine-mode" name="anti_dopamine_mode" type="checkbox"
value="true" {{if .Settings.AntiDopamineMode}}checked{{end}}>
<label for="anti-dopamine-mode"> Remove addictive social media features </label>
</div>
<button type="submit"> Save </button> <button type="submit"> Save </button>
</form> </form>

View File

@ -160,7 +160,9 @@
reply reply
</a> </a>
<a class="status-reply-count" href="/thread/{{.ID}}#status-{{.ID}}" {{if $.Ctx.ThreadInNewTab}}target="_blank"{{end}}> <a class="status-reply-count" href="/thread/{{.ID}}#status-{{.ID}}" {{if $.Ctx.ThreadInNewTab}}target="_blank"{{end}}>
{{if .RepliesCount}} ({{DisplayInteractionCount .RepliesCount}}) {{end}} {{if and (not $.Ctx.AntiDopamineMode) .RepliesCount}}
({{DisplayInteractionCount .RepliesCount}})
{{end}}
</a> </a>
</div> </div>
<div class="status-action"> <div class="status-action">
@ -184,7 +186,9 @@
{{end}} {{end}}
{{end}} {{end}}
<a class="status-retweet-count" href="/retweetedby/{{.ID}}" title="click to see the the list"> <a class="status-retweet-count" href="/retweetedby/{{.ID}}" title="click to see the the list">
{{if .ReblogsCount}} ({{DisplayInteractionCount .ReblogsCount}}) {{end}} {{if and (not $.Ctx.AntiDopamineMode) .ReblogsCount}}
({{DisplayInteractionCount .ReblogsCount}})
{{end}}
</a> </a>
</div> </div>
<div class="status-action"> <div class="status-action">
@ -202,7 +206,9 @@
</form> </form>
{{end}} {{end}}
<a class="status-like-count" href="/likedby/{{.ID}}" title="click to see the the list"> <a class="status-like-count" href="/likedby/{{.ID}}" title="click to see the the list">
{{if .FavouritesCount}} ({{DisplayInteractionCount .FavouritesCount}}) {{end}} {{if and (not $.Ctx.AntiDopamineMode) .FavouritesCount}}
({{DisplayInteractionCount .FavouritesCount}})
{{end}}
</a> </a>
</div> </div>
<div class="status-action"> <div class="status-action">