From 688d2e0baa02a33ca180aea890cba8f50f49e9e9 Mon Sep 17 00:00:00 2001 From: Noah Petherbridge Date: Thu, 28 Nov 2024 11:21:06 -0800 Subject: [PATCH] Blur Explicit GIFs + Forum Improvements * Fix a bug where explicit GIF videos weren't blurring when the user wanted them to be blurred. * Make some improvements to the forums: * Polls will now remember the Expires setting while you are previewing and revising your original post. * Add 14 day and 30 day Expire options for polls. * Add disclaimer warnings above the Photo Attachment field when the current forum or thread isn't marked for Explicit content. --- pkg/config/enum.go | 44 ++++++++++++++++++++++++++ pkg/controller/forum/new_post.go | 28 ++++++++++++----- pkg/controller/forum/thread.go | 28 +++++++++++------ pkg/templates/template_funcs.go | 11 ++++--- web/templates/forum/new_post.html | 51 +++++++++++++++++++++++++------ web/templates/forum/thread.html | 26 ++++++++++++++-- web/templates/photo/gallery.html | 14 ++++----- 7 files changed, 160 insertions(+), 42 deletions(-) diff --git a/pkg/config/enum.go b/pkg/config/enum.go index 44d0445..10e0031 100644 --- a/pkg/config/enum.go +++ b/pkg/config/enum.go @@ -165,6 +165,50 @@ var ( "Anything Goes", } + // Forum Poll expiration options. + PollExpires = []Option{ + { + Label: "Never", + Value: "0", + }, + { + Label: "1 Day", + Value: "1", + }, + { + Label: "2 Days", + Value: "2", + }, + { + Label: "3 Days", + Value: "3", + }, + { + Label: "4 Days", + Value: "4", + }, + { + Label: "5 Days", + Value: "5", + }, + { + Label: "6 Days", + Value: "6", + }, + { + Label: "7 Days", + Value: "7", + }, + { + Label: "2 Weeks", + Value: "14", + }, + { + Label: "1 Month (30 days)", + Value: "30", + }, + } + // Keywords that appear in a DM that make it likely spam. DirectMessageSpamKeywords = []*regexp.Regexp{ regexp.MustCompile(`\b(telegram|whats\s*app|signal|kik|session)\b`), diff --git a/pkg/controller/forum/new_post.go b/pkg/controller/forum/new_post.go index f3dca70..a30247f 100644 --- a/pkg/controller/forum/new_post.go +++ b/pkg/controller/forum/new_post.go @@ -47,6 +47,10 @@ func NewPost() http.HandlerFunc { // well (pinned, explicit, noreply) isOriginalComment bool + // If neither the forum nor thread are explicit, show a hint to the user not to + // share an explicit photo in their reply. + explicitPhotoAllowed bool + // Polls pollOptions = []string{} pollExpires = 3 @@ -87,6 +91,11 @@ func NewPost() http.HandlerFunc { } } + // Would an explicit photo attachment be allowed? + if forum.Explicit || (thread != nil && thread.Explicit) { + explicitPhotoAllowed = true + } + // If the current user can moderate the forum thread, e.g. edit or delete posts. // Admins can edit always, user owners of forums can only delete. var canModerate = currentUser.HasAdminScope(config.ScopeForumModerator) || @@ -493,13 +502,14 @@ func NewPost() http.HandlerFunc { } var vars = map[string]interface{}{ - "Forum": forum, - "Thread": thread, - "Intent": intent, - "PostTitle": title, - "EditCommentID": editCommentID, - "EditThreadSettings": isOriginalComment, - "Message": message, + "Forum": forum, + "Thread": thread, + "Intent": intent, + "PostTitle": title, + "EditCommentID": editCommentID, + "EditThreadSettings": isOriginalComment, + "ExplicitPhotoAllowed": explicitPhotoAllowed, + "Message": message, // Thread settings (for editing the original comment esp.) "IsPinned": isPinned, @@ -507,7 +517,9 @@ func NewPost() http.HandlerFunc { "IsNoReply": isNoReply, // Polls - "PollOptions": pollOptions, + "PollOptions": pollOptions, + "PollExpires": pollExpires, + "PollExpiresOptions": config.PollExpires, // Attached photo. "CommentPhoto": commentPhoto, diff --git a/pkg/controller/forum/thread.go b/pkg/controller/forum/thread.go index 79f19b0..7222fd1 100644 --- a/pkg/controller/forum/thread.go +++ b/pkg/controller/forum/thread.go @@ -20,6 +20,10 @@ func Thread() http.HandlerFunc { idStr = r.PathValue("id") forum *models.Forum thread *models.Thread + + // If neither the forum nor thread are explicit, show a hint to the user not to + // share an explicit photo in their reply. + explicitPhotoAllowed bool ) if idStr == "" { @@ -61,6 +65,11 @@ func Thread() http.HandlerFunc { // e.g. can we delete threads and posts, not edit them) var canModerate = forum.CanBeModeratedBy(currentUser) + // Would an explicit photo attachment be allowed? + if forum.Explicit || thread.Explicit { + explicitPhotoAllowed = true + } + // Ping the view count on this thread. if err := thread.View(currentUser.ID); err != nil { log.Error("Couldn't ping view count on thread %d: %s", thread.ID, err) @@ -105,15 +114,16 @@ func Thread() http.HandlerFunc { }() var vars = map[string]interface{}{ - "Forum": forum, - "Thread": thread, - "Comments": comments, - "LikeMap": commentLikeMap, - "PhotoMap": photos, - "Pager": pager, - "CanModerate": canModerate, - "IsSubscribed": isSubscribed, - "IsForumSubscribed": models.IsForumSubscribed(currentUser, forum), + "Forum": forum, + "Thread": thread, + "Comments": comments, + "LikeMap": commentLikeMap, + "PhotoMap": photos, + "Pager": pager, + "CanModerate": canModerate, + "IsSubscribed": isSubscribed, + "IsForumSubscribed": models.IsForumSubscribed(currentUser, forum), + "ExplicitPhotoAllowed": explicitPhotoAllowed, } if err := tmpl.Execute(w, r, vars); err != nil { http.Error(w, err.Error(), http.StatusInternalServerError) diff --git a/pkg/templates/template_funcs.go b/pkg/templates/template_funcs.go index 80dd9d4..544c14b 100644 --- a/pkg/templates/template_funcs.go +++ b/pkg/templates/template_funcs.go @@ -38,10 +38,13 @@ func TemplateFuncs(r *http.Request) template.FuncMap { "ToMarkdown": ToMarkdown, "ToJSON": ToJSON, "ToHTML": ToHTML, - "PhotoURL": PhotoURL(r), - "VisibleAvatarURL": photo.VisibleAvatarURL, - "Now": time.Now, - "RunTime": RunTime, + "ToString": func(v interface{}) string { + return fmt.Sprintf("%v", v) + }, + "PhotoURL": PhotoURL(r), + "VisibleAvatarURL": photo.VisibleAvatarURL, + "Now": time.Now, + "RunTime": RunTime, "PrettyTitle": func() template.HTML { return template.HTML(fmt.Sprintf( `non` + diff --git a/web/templates/forum/new_post.html b/web/templates/forum/new_post.html index 6f8db42..b508b5e 100644 --- a/web/templates/forum/new_post.html +++ b/web/templates/forum/new_post.html @@ -28,6 +28,8 @@ + {{$Root := .}} +
@@ -83,7 +85,7 @@ {{if and (not .EditCommentID) (not .Thread)}}
- +
@@ -134,14 +136,9 @@
@@ -173,6 +170,33 @@
+ + + {{if not .ExplicitPhotoAllowed}} +

+ + {{if not .Thread}} + + + Explicit Photo Notice: + + + The forum you are posting to isn't marked as Explicit. If you are going to share + an Explicit photo, please also mark this thread + as Explicit using the checkbox below! + {{else}} + + + No Explicit Photos: + + + This {{if not .Thread}}forum{{else}}thread{{end}} is not marked to accept Explicit + photos being shared. If you are going to upload a nude picture, please make sure + it is not an Explicit photo. Thanks! + {{end}} +

+ {{end}} +
+ {{if not .Forum.Explicit}} +

+ The forum you are posting this in is not marked as Explicit, however the occasional + Explicit thread is allowed as long as it is correctly tagged. Please + check this box if the text or attached photos on this thread will be sexual in nature! +

+ {{end}}
{{end}} @@ -376,7 +407,7 @@ {value: ""}, {value: ""}, ], - expires: 3, // days + expires: parseInt({{.PollExpires}}), // days answersLimit: 100, } }, diff --git a/web/templates/forum/thread.html b/web/templates/forum/thread.html index 087e15b..f21c87c 100644 --- a/web/templates/forum/thread.html +++ b/web/templates/forum/thread.html @@ -264,9 +264,14 @@ {{else}} {{if HasSuffix .Filename ".mp4"}} - +
+ +
{{else}}
@@ -485,6 +490,21 @@
+ + + {{if not .ExplicitPhotoAllowed}} +

+ + + No Explicit Photos: + + + This {{if not .Thread}}forum{{else}}thread{{end}} is not marked to accept Explicit + photos being shared. If you are going to upload a nude picture, please make sure + it is not an Explicit photo. Thanks! +

+ {{end}} +