aboutsummaryrefslogtreecommitdiffstats
path: root/routers/web/repo/middlewares.go
diff options
context:
space:
mode:
Diffstat (limited to 'routers/web/repo/middlewares.go')
-rw-r--r--routers/web/repo/middlewares.go25
1 files changed, 25 insertions, 0 deletions
diff --git a/routers/web/repo/middlewares.go b/routers/web/repo/middlewares.go
index 5c38b31154..216550ca99 100644
--- a/routers/web/repo/middlewares.go
+++ b/routers/web/repo/middlewares.go
@@ -5,6 +5,7 @@ package repo
import (
"fmt"
+ "strconv"
system_model "code.gitea.io/gitea/models/system"
user_model "code.gitea.io/gitea/models/user"
@@ -88,3 +89,27 @@ func SetWhitespaceBehavior(ctx *context.Context) {
ctx.Data["WhitespaceBehavior"] = whitespaceBehavior
}
}
+
+// SetShowOutdatedComments set the show outdated comments option as context variable
+func SetShowOutdatedComments(ctx *context.Context) {
+ showOutdatedCommentsValue := ctx.FormString("show-outdated")
+ // var showOutdatedCommentsValue string
+
+ if showOutdatedCommentsValue != "true" && showOutdatedCommentsValue != "false" {
+ // invalid or no value for this form string -> use default or stored user setting
+ if ctx.IsSigned {
+ showOutdatedCommentsValue, _ = user_model.GetUserSetting(ctx.Doer.ID, user_model.SettingsKeyShowOutdatedComments, "false")
+ } else {
+ // not logged in user -> use the default value
+ showOutdatedCommentsValue = "false"
+ }
+ } else {
+ // valid value -> update user setting if user is logged in
+ if ctx.IsSigned {
+ _ = user_model.SetUserSetting(ctx.Doer.ID, user_model.SettingsKeyShowOutdatedComments, showOutdatedCommentsValue)
+ }
+ }
+
+ showOutdatedComments, _ := strconv.ParseBool(showOutdatedCommentsValue)
+ ctx.Data["ShowOutdatedComments"] = showOutdatedComments
+}