From f380371654dd81b258e5f37e50ffcf3764f117c1 Mon Sep 17 00:00:00 2001 From: r Date: Sat, 25 Apr 2020 09:35:18 +0000 Subject: Add option to hide attachments --- model/settings.go | 2 ++ renderer/model.go | 13 +++++++------ service/service.go | 13 +++++++------ service/transport.go | 2 ++ templates/settings.tmpl | 4 ++++ templates/status.tmpl | 23 ++++++++++++++++++++--- 6 files changed, 42 insertions(+), 15 deletions(-) diff --git a/model/settings.go b/model/settings.go index b1463c7..fa69672 100644 --- a/model/settings.go +++ b/model/settings.go @@ -4,6 +4,7 @@ type Settings struct { DefaultVisibility string `json:"default_visibility"` 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"` @@ -15,6 +16,7 @@ func NewSettings() *Settings { DefaultVisibility: "public", CopyScope: true, ThreadInNewTab: false, + HideAttachments: false, MaskNSFW: true, AutoRefreshNotifications: false, FluorideMode: false, diff --git a/renderer/model.go b/renderer/model.go index 96907b3..85c73b8 100644 --- a/renderer/model.go +++ b/renderer/model.go @@ -6,12 +6,13 @@ import ( ) type Context struct { - MaskNSFW bool - FluorideMode bool - ThreadInNewTab bool - DarkMode bool - CSRFToken string - UserID string + HideAttachments bool + MaskNSFW bool + FluorideMode bool + ThreadInNewTab bool + DarkMode bool + CSRFToken string + UserID string } type NavData struct { diff --git a/service/service.go b/service/service.go index 02c55cb..d6ff192 100644 --- a/service/service.go +++ b/service/service.go @@ -107,12 +107,13 @@ func getRendererContext(c *model.Client) *renderer.Context { settings = *model.NewSettings() } return &renderer.Context{ - MaskNSFW: settings.MaskNSFW, - ThreadInNewTab: settings.ThreadInNewTab, - FluorideMode: settings.FluorideMode, - DarkMode: settings.DarkMode, - CSRFToken: session.CSRFToken, - UserID: session.UserID, + HideAttachments: settings.HideAttachments, + MaskNSFW: settings.MaskNSFW, + ThreadInNewTab: settings.ThreadInNewTab, + FluorideMode: settings.FluorideMode, + DarkMode: settings.DarkMode, + CSRFToken: session.CSRFToken, + UserID: session.UserID, } } diff --git a/service/transport.go b/service/transport.go index f52cca0..840f4cc 100644 --- a/service/transport.go +++ b/service/transport.go @@ -615,6 +615,7 @@ func NewHandler(s Service, staticDir string) http.Handler { visibility := req.FormValue("visibility") copyScope := req.FormValue("copy_scope") == "true" 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" fluorideMode := req.FormValue("fluoride_mode") == "true" @@ -624,6 +625,7 @@ func NewHandler(s Service, staticDir string) http.Handler { DefaultVisibility: visibility, CopyScope: copyScope, ThreadInNewTab: threadInNewTab, + HideAttachments: hideAttachments, MaskNSFW: maskNSFW, AutoRefreshNotifications: arn, FluorideMode: fluorideMode, diff --git a/templates/settings.tmpl b/templates/settings.tmpl index 2773deb..d0710c3 100644 --- a/templates/settings.tmpl +++ b/templates/settings.tmpl @@ -21,6 +21,10 @@ +
+ + +
diff --git a/templates/status.tmpl b/templates/status.tmpl index ade9d25..6433b9c 100644 --- a/templates/status.tmpl +++ b/templates/status.tmpl @@ -75,31 +75,48 @@ {{end}}
{{range .MediaAttachments}} + {{if eq .Type "image"}} + {{if $.Ctx.HideAttachments}} + [image] + {{else}} status-image {{if (and $.Ctx.MaskNSFW $s.Sensitive)}}
{{end}}
+ {{end}} + {{else if eq .Type "audio"}} + {{if $.Ctx.HideAttachments}} + [audio] + {{else}} + {{end}} + {{else if eq .Type "video"}} + {{if $.Ctx.HideAttachments}} + [video] + {{else}}
{{if (and $.Ctx.MaskNSFW $s.Sensitive)}}
{{end}}
+ {{end}} + {{else}} - attachment + [attachment] {{end}} + {{end}}
{{if .Poll}} -- cgit v1.2.3