aboutsummaryrefslogtreecommitdiffstats
path: root/routers/web/repo/middlewares.go
diff options
context:
space:
mode:
authorwxiaoguang <wxiaoguang@gmail.com>2024-02-08 09:50:48 +0800
committerGitHub <noreply@github.com>2024-02-08 01:50:48 +0000
commita4859dcfea0cf1c7818f3cb2dcbb6b83902cc9d5 (patch)
tree0de3f0eea888d67b87a68e8397e74148329945d2 /routers/web/repo/middlewares.go
parent5c0fc9087211f01375f208d679a1e6de0685320c (diff)
downloadgitea-a4859dcfea0cf1c7818f3cb2dcbb6b83902cc9d5.tar.gz
gitea-a4859dcfea0cf1c7818f3cb2dcbb6b83902cc9d5.zip
Improve user experience for outdated comments (#29050)
Try to improve #28949 1. Make `ctx.Data["ShowOutdatedComments"] = true` by default: it brings consistent user experience, and sometimes the "outdated (source changed)" comments are still valuable. 2. Show a friendly message if the comment won't show, then the end users won't fell that "the comment disappears" (it is the special case when `ShowOutdatedComments = false`)
Diffstat (limited to 'routers/web/repo/middlewares.go')
-rw-r--r--routers/web/repo/middlewares.go18
1 files changed, 5 insertions, 13 deletions
diff --git a/routers/web/repo/middlewares.go b/routers/web/repo/middlewares.go
index ee49649654..d70a53030e 100644
--- a/routers/web/repo/middlewares.go
+++ b/routers/web/repo/middlewares.go
@@ -98,23 +98,15 @@ func SetWhitespaceBehavior(ctx *context.Context) {
// 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
+ showOutdatedCommentsValue = "true"
if ctx.IsSigned {
- showOutdatedCommentsValue, _ = user_model.GetUserSetting(ctx, ctx.Doer.ID, user_model.SettingsKeyShowOutdatedComments, "false")
- } else {
- // not logged in user -> use the default value
- showOutdatedCommentsValue = "false"
+ showOutdatedCommentsValue, _ = user_model.GetUserSetting(ctx, ctx.Doer.ID, user_model.SettingsKeyShowOutdatedComments, showOutdatedCommentsValue)
}
- } else {
+ } else if ctx.IsSigned {
// valid value -> update user setting if user is logged in
- if ctx.IsSigned {
- _ = user_model.SetUserSetting(ctx, ctx.Doer.ID, user_model.SettingsKeyShowOutdatedComments, showOutdatedCommentsValue)
- }
+ _ = user_model.SetUserSetting(ctx, ctx.Doer.ID, user_model.SettingsKeyShowOutdatedComments, showOutdatedCommentsValue)
}
-
- showOutdatedComments, _ := strconv.ParseBool(showOutdatedCommentsValue)
- ctx.Data["ShowOutdatedComments"] = showOutdatedComments
+ ctx.Data["ShowOutdatedComments"], _ = strconv.ParseBool(showOutdatedCommentsValue)
}