Add option to hide attachments
authorr <r@freesoftwareextremist.com>
Sat, 25 Apr 2020 09:35:18 +0000 (09:35 +0000)
committerr <r@freesoftwareextremist.com>
Sat, 25 Apr 2020 09:35:18 +0000 (09:35 +0000)
model/settings.go
renderer/model.go
service/service.go
service/transport.go
templates/settings.tmpl
templates/status.tmpl

index b1463c7848719459d206c17493c9601e082bca5d..fa69672ac2e0fef5b5e75452f9aa727153dc4a50 100644 (file)
@@ -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,
index 96907b390d51d264528acda40e758b57440e9da7..85c73b85aa6bbd032863c46c56444e105b10b6ec 100644 (file)
@@ -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 {
index 02c55cbe800f9beb04e227d60aeadd9c07f4b2cd..d6ff192d04eb389b9f78413d53391e405d12a1d9 100644 (file)
@@ -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,
        }
 }
 
index f52cca00a3f58499cbf8d1e4c8fb607d9f8c7244..840f4cca36b736ac76c1772f304465da57992d56 100644 (file)
@@ -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,
index 2773deb0938e93ad65a59adece7f43ac0f61bc2d..d0710c3b0f4df321044a7336b25f887366c75920 100644 (file)
                <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>
        </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">
                <input id="mask-nsfw" name="mask_nsfw" type="checkbox" value="true" {{if .Settings.MaskNSFW}}checked{{end}}>
                <label for="mask-nsfw"> Mask NSFW attachments </label>
index ade9d25726cfec07be929b7022c17f94ecb8962a..6433b9c70fba51b057aeaa983479690df111ca3a 100644 (file)
                        {{end}}
                        <div class="status-media-container">
                                {{range .MediaAttachments}}
+
                                {{if eq .Type "image"}}
+                               {{if $.Ctx.HideAttachments}}
+                               <a href="{{.URL}}" target="_blank"> [image] </a>
+                               {{else}}
                                <a class="img-link" href="{{.URL}}" target="_blank">
                                        <img class="status-image" src="{{.URL}}" alt="status-image" />
                                        {{if (and $.Ctx.MaskNSFW $s.Sensitive)}}
                                        <div class="status-nsfw-overlay"></div>
                                        {{end}}
                                </a>
+                               {{end}}
+
                                {{else if eq .Type "audio"}}
+                               {{if $.Ctx.HideAttachments}}
+                               <a href="{{.URL}}" target="_blank"> [audio] </a>
+                               {{else}}
                                <audio class="status-audio" controls preload="none">
                                        <source src="{{.URL}}">
-                                       <p> Your browser doesn't support HTML5 audio </p>
+                                       <a href="{{.URL}}" target="_blank"> [audio] </a>
                                </audio>
+                               {{end}}
+
                                {{else if eq .Type "video"}}
+                               {{if $.Ctx.HideAttachments}}
+                               <a href="{{.URL}}" target="_blank"> [video] </a>
+                               {{else}}
                                <div class="status-video-container">
                                        <video class="status-video" controls preload="none">
                                                <source src="{{.URL}}">
-                                               <p> Your browser doesn't support HTML5 video </p>
+                                               <a href="{{.URL}}" target="_blank"> [video] </a>
                                        </video>
                                        {{if (and $.Ctx.MaskNSFW $s.Sensitive)}}
                                        <div class="status-nsfw-overlay"></div>
                                        {{end}}
                                </div>
+                               {{end}}
+
                                {{else}}
-                               <a href="{{.URL}}" target="_blank"> attachment </a>
+                               <a href="{{.URL}}" target="_blank"> [attachment] </a>
                                {{end}}
+
                                {{end}}
                        </div>
                        {{if .Poll}}