Add option to hide attachments

This commit is contained in:
r 2020-04-25 09:35:18 +00:00
parent 1e750f89b1
commit f380371654
6 changed files with 43 additions and 16 deletions

View File

@ -4,6 +4,7 @@ type Settings struct {
DefaultVisibility string `json:"default_visibility"` DefaultVisibility string `json:"default_visibility"`
CopyScope bool `json:"copy_scope"` CopyScope bool `json:"copy_scope"`
ThreadInNewTab bool `json:"thread_in_new_tab"` ThreadInNewTab bool `json:"thread_in_new_tab"`
HideAttachments bool `json:"hide_attachments"`
MaskNSFW bool `json:"mask_nfsw"` MaskNSFW bool `json:"mask_nfsw"`
AutoRefreshNotifications bool `json:"auto_refresh_notifications"` AutoRefreshNotifications bool `json:"auto_refresh_notifications"`
FluorideMode bool `json:"fluoride_mode"` FluorideMode bool `json:"fluoride_mode"`
@ -15,6 +16,7 @@ func NewSettings() *Settings {
DefaultVisibility: "public", DefaultVisibility: "public",
CopyScope: true, CopyScope: true,
ThreadInNewTab: false, ThreadInNewTab: false,
HideAttachments: false,
MaskNSFW: true, MaskNSFW: true,
AutoRefreshNotifications: false, AutoRefreshNotifications: false,
FluorideMode: false, FluorideMode: false,

View File

@ -6,12 +6,13 @@ import (
) )
type Context struct { type Context struct {
MaskNSFW bool HideAttachments bool
FluorideMode bool MaskNSFW bool
ThreadInNewTab bool FluorideMode bool
DarkMode bool ThreadInNewTab bool
CSRFToken string DarkMode bool
UserID string CSRFToken string
UserID string
} }
type NavData struct { type NavData struct {

View File

@ -107,12 +107,13 @@ func getRendererContext(c *model.Client) *renderer.Context {
settings = *model.NewSettings() settings = *model.NewSettings()
} }
return &renderer.Context{ return &renderer.Context{
MaskNSFW: settings.MaskNSFW, HideAttachments: settings.HideAttachments,
ThreadInNewTab: settings.ThreadInNewTab, MaskNSFW: settings.MaskNSFW,
FluorideMode: settings.FluorideMode, ThreadInNewTab: settings.ThreadInNewTab,
DarkMode: settings.DarkMode, FluorideMode: settings.FluorideMode,
CSRFToken: session.CSRFToken, DarkMode: settings.DarkMode,
UserID: session.UserID, CSRFToken: session.CSRFToken,
UserID: session.UserID,
} }
} }

View File

@ -615,6 +615,7 @@ func NewHandler(s Service, staticDir string) http.Handler {
visibility := req.FormValue("visibility") visibility := req.FormValue("visibility")
copyScope := req.FormValue("copy_scope") == "true" copyScope := req.FormValue("copy_scope") == "true"
threadInNewTab := req.FormValue("thread_in_new_tab") == "true" threadInNewTab := req.FormValue("thread_in_new_tab") == "true"
hideAttachments := req.FormValue("hide_attachments") == "true"
maskNSFW := req.FormValue("mask_nsfw") == "true" maskNSFW := req.FormValue("mask_nsfw") == "true"
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"
@ -624,6 +625,7 @@ func NewHandler(s Service, staticDir string) http.Handler {
DefaultVisibility: visibility, DefaultVisibility: visibility,
CopyScope: copyScope, CopyScope: copyScope,
ThreadInNewTab: threadInNewTab, ThreadInNewTab: threadInNewTab,
HideAttachments: hideAttachments,
MaskNSFW: maskNSFW, MaskNSFW: maskNSFW,
AutoRefreshNotifications: arn, AutoRefreshNotifications: arn,
FluorideMode: fluorideMode, FluorideMode: fluorideMode,

View File

@ -21,6 +21,10 @@
<input id="thread-tab" name="thread_in_new_tab" type="checkbox" value="true" {{if .Settings.ThreadInNewTab}}checked{{end}}> <input id="thread-tab" name="thread_in_new_tab" type="checkbox" value="true" {{if .Settings.ThreadInNewTab}}checked{{end}}>
<label for="thread-tab"> Open threads in new tab from timeline </label> <label for="thread-tab"> Open threads in new tab from timeline </label>
</div> </div>
<div class="settings-form-field">
<input id="hide-attachments" name="hide_attachments" type="checkbox" value="true" {{if .Settings.HideAttachments}}checked{{end}}>
<label for="hide-attachments"> Hide attachments </label>
</div>
<div class="settings-form-field"> <div class="settings-form-field">
<input id="mask-nsfw" name="mask_nsfw" type="checkbox" value="true" {{if .Settings.MaskNSFW}}checked{{end}}> <input id="mask-nsfw" name="mask_nsfw" type="checkbox" value="true" {{if .Settings.MaskNSFW}}checked{{end}}>
<label for="mask-nsfw"> Mask NSFW attachments </label> <label for="mask-nsfw"> Mask NSFW attachments </label>

View File

@ -75,31 +75,48 @@
{{end}} {{end}}
<div class="status-media-container"> <div class="status-media-container">
{{range .MediaAttachments}} {{range .MediaAttachments}}
{{if eq .Type "image"}} {{if eq .Type "image"}}
{{if $.Ctx.HideAttachments}}
<a href="{{.URL}}" target="_blank"> [image] </a>
{{else}}
<a class="img-link" href="{{.URL}}" target="_blank"> <a class="img-link" href="{{.URL}}" target="_blank">
<img class="status-image" src="{{.URL}}" alt="status-image" /> <img class="status-image" src="{{.URL}}" alt="status-image" />
{{if (and $.Ctx.MaskNSFW $s.Sensitive)}} {{if (and $.Ctx.MaskNSFW $s.Sensitive)}}
<div class="status-nsfw-overlay"></div> <div class="status-nsfw-overlay"></div>
{{end}} {{end}}
</a> </a>
{{end}}
{{else if eq .Type "audio"}} {{else if eq .Type "audio"}}
{{if $.Ctx.HideAttachments}}
<a href="{{.URL}}" target="_blank"> [audio] </a>
{{else}}
<audio class="status-audio" controls preload="none"> <audio class="status-audio" controls preload="none">
<source src="{{.URL}}"> <source src="{{.URL}}">
<p> Your browser doesn't support HTML5 audio </p> <a href="{{.URL}}" target="_blank"> [audio] </a>
</audio> </audio>
{{end}}
{{else if eq .Type "video"}} {{else if eq .Type "video"}}
{{if $.Ctx.HideAttachments}}
<a href="{{.URL}}" target="_blank"> [video] </a>
{{else}}
<div class="status-video-container"> <div class="status-video-container">
<video class="status-video" controls preload="none"> <video class="status-video" controls preload="none">
<source src="{{.URL}}"> <source src="{{.URL}}">
<p> Your browser doesn't support HTML5 video </p> <a href="{{.URL}}" target="_blank"> [video] </a>
</video> </video>
{{if (and $.Ctx.MaskNSFW $s.Sensitive)}} {{if (and $.Ctx.MaskNSFW $s.Sensitive)}}
<div class="status-nsfw-overlay"></div> <div class="status-nsfw-overlay"></div>
{{end}} {{end}}
</div> </div>
{{else}}
<a href="{{.URL}}" target="_blank"> attachment </a>
{{end}} {{end}}
{{else}}
<a href="{{.URL}}" target="_blank"> [attachment] </a>
{{end}}
{{end}} {{end}}
</div> </div>
{{if .Poll}} {{if .Poll}}