From 5a7d6f89975959e0a1a63f1ac68d5bb41f01ab2c Mon Sep 17 00:00:00 2001 From: jvoisin Date: Tue, 27 Feb 2024 17:19:38 +0100 Subject: [PATCH] Make use of printer.Print when possible --- internal/template/functions.go | 8 ++++---- internal/template/functions_test.go | 8 ++++---- internal/ui/category_refresh.go | 4 ++-- internal/ui/feed_refresh.go | 2 +- internal/ui/integration_pocket.go | 6 +++--- internal/ui/integration_update.go | 6 +++--- internal/ui/oauth2_callback.go | 6 +++--- internal/ui/oauth2_unlink.go | 4 ++-- 8 files changed, 22 insertions(+), 22 deletions(-) diff --git a/internal/template/functions.go b/internal/template/functions.go index 2db98420..08720dff 100644 --- a/internal/template/functions.go +++ b/internal/template/functions.go @@ -180,13 +180,13 @@ func durationImpl(t time.Time, now time.Time) string { func elapsedTime(printer *locale.Printer, tz string, t time.Time) string { if t.IsZero() { - return printer.Printf("time_elapsed.not_yet") + return printer.Print("time_elapsed.not_yet") } now := timezone.Now(tz) t = timezone.Convert(tz, t) if now.Before(t) { - return printer.Printf("time_elapsed.not_yet") + return printer.Print("time_elapsed.not_yet") } diff := now.Sub(t) @@ -196,7 +196,7 @@ func elapsedTime(printer *locale.Printer, tz string, t time.Time) string { d := int(s / 86400) switch { case s < 60: - return printer.Printf("time_elapsed.now") + return printer.Print("time_elapsed.now") case s < 3600: minutes := int(diff.Minutes()) return printer.Plural("time_elapsed.minutes", minutes, minutes) @@ -204,7 +204,7 @@ func elapsedTime(printer *locale.Printer, tz string, t time.Time) string { hours := int(diff.Hours()) return printer.Plural("time_elapsed.hours", hours, hours) case d == 1: - return printer.Printf("time_elapsed.yesterday") + return printer.Print("time_elapsed.yesterday") case d < 21: return printer.Plural("time_elapsed.days", d, d) case d < 31: diff --git a/internal/template/functions_test.go b/internal/template/functions_test.go index 35dbf6de..360d65ae 100644 --- a/internal/template/functions_test.go +++ b/internal/template/functions_test.go @@ -127,14 +127,14 @@ func TestElapsedTime(t *testing.T) { in time.Time out string }{ - {time.Time{}, printer.Printf("time_elapsed.not_yet")}, - {time.Now().Add(time.Hour), printer.Printf("time_elapsed.not_yet")}, - {time.Now(), printer.Printf("time_elapsed.now")}, + {time.Time{}, printer.Print("time_elapsed.not_yet")}, + {time.Now().Add(time.Hour), printer.Print("time_elapsed.not_yet")}, + {time.Now(), printer.Print("time_elapsed.now")}, {time.Now().Add(-time.Minute), printer.Plural("time_elapsed.minutes", 1, 1)}, {time.Now().Add(-time.Minute * 40), printer.Plural("time_elapsed.minutes", 40, 40)}, {time.Now().Add(-time.Hour), printer.Plural("time_elapsed.hours", 1, 1)}, {time.Now().Add(-time.Hour * 3), printer.Plural("time_elapsed.hours", 3, 3)}, - {time.Now().Add(-time.Hour * 32), printer.Printf("time_elapsed.yesterday")}, + {time.Now().Add(-time.Hour * 32), printer.Print("time_elapsed.yesterday")}, {time.Now().Add(-time.Hour * 24 * 3), printer.Plural("time_elapsed.days", 3, 3)}, {time.Now().Add(-time.Hour * 24 * 14), printer.Plural("time_elapsed.days", 14, 14)}, {time.Now().Add(-time.Hour * 24 * 15), printer.Plural("time_elapsed.days", 15, 15)}, diff --git a/internal/ui/category_refresh.go b/internal/ui/category_refresh.go index adbf015a..e3eed10e 100644 --- a/internal/ui/category_refresh.go +++ b/internal/ui/category_refresh.go @@ -33,7 +33,7 @@ func (h *handler) refreshCategory(w http.ResponseWriter, r *http.Request) int64 // Avoid accidental and excessive refreshes. if time.Now().UTC().Unix()-request.LastForceRefresh(r) < 1800 { - sess.NewFlashErrorMessage(printer.Printf("alert.too_many_feeds_refresh")) + sess.NewFlashErrorMessage(printer.Print("alert.too_many_feeds_refresh")) } else { // We allow the end-user to force refresh all its feeds in this category // without taking into consideration the number of errors. @@ -58,7 +58,7 @@ func (h *handler) refreshCategory(w http.ResponseWriter, r *http.Request) int64 go h.pool.Push(jobs) sess.SetLastForceRefresh() - sess.NewFlashMessage(printer.Printf("alert.background_feed_refresh")) + sess.NewFlashMessage(printer.Print("alert.background_feed_refresh")) } return categoryID diff --git a/internal/ui/feed_refresh.go b/internal/ui/feed_refresh.go index b1147073..ec609156 100644 --- a/internal/ui/feed_refresh.go +++ b/internal/ui/feed_refresh.go @@ -63,7 +63,7 @@ func (h *handler) refreshAllFeeds(w http.ResponseWriter, r *http.Request) { go h.pool.Push(jobs) sess.SetLastForceRefresh() - sess.NewFlashMessage(printer.Printf("alert.background_feed_refresh")) + sess.NewFlashMessage(printer.Print("alert.background_feed_refresh")) } html.Redirect(w, r, route.Path(h.router, "feeds")) diff --git a/internal/ui/integration_pocket.go b/internal/ui/integration_pocket.go index 7da6b072..13e17295 100644 --- a/internal/ui/integration_pocket.go +++ b/internal/ui/integration_pocket.go @@ -39,7 +39,7 @@ func (h *handler) pocketAuthorize(w http.ResponseWriter, r *http.Request) { slog.Any("user_id", user.ID), slog.Any("error", err), ) - sess.NewFlashErrorMessage(printer.Printf("error.pocket_request_token")) + sess.NewFlashErrorMessage(printer.Print("error.pocket_request_token")) html.Redirect(w, r, route.Path(h.router, "integrations")) return } @@ -71,7 +71,7 @@ func (h *handler) pocketCallback(w http.ResponseWriter, r *http.Request) { slog.Any("user_id", user.ID), slog.Any("error", err), ) - sess.NewFlashErrorMessage(printer.Printf("error.pocket_access_token")) + sess.NewFlashErrorMessage(printer.Print("error.pocket_access_token")) html.Redirect(w, r, route.Path(h.router, "integrations")) return } @@ -85,6 +85,6 @@ func (h *handler) pocketCallback(w http.ResponseWriter, r *http.Request) { return } - sess.NewFlashMessage(printer.Printf("alert.pocket_linked")) + sess.NewFlashMessage(printer.Print("alert.pocket_linked")) html.Redirect(w, r, route.Path(h.router, "integrations")) } diff --git a/internal/ui/integration_update.go b/internal/ui/integration_update.go index b8bfed44..c54ec625 100644 --- a/internal/ui/integration_update.go +++ b/internal/ui/integration_update.go @@ -36,7 +36,7 @@ func (h *handler) updateIntegration(w http.ResponseWriter, r *http.Request) { integrationForm.Merge(integration) if integration.FeverUsername != "" && h.store.HasDuplicateFeverUsername(user.ID, integration.FeverUsername) { - sess.NewFlashErrorMessage(printer.Printf("error.duplicate_fever_username")) + sess.NewFlashErrorMessage(printer.Print("error.duplicate_fever_username")) html.Redirect(w, r, route.Path(h.router, "integrations")) return } @@ -50,7 +50,7 @@ func (h *handler) updateIntegration(w http.ResponseWriter, r *http.Request) { } if integration.GoogleReaderUsername != "" && h.store.HasDuplicateGoogleReaderUsername(user.ID, integration.GoogleReaderUsername) { - sess.NewFlashErrorMessage(printer.Printf("error.duplicate_googlereader_username")) + sess.NewFlashErrorMessage(printer.Print("error.duplicate_googlereader_username")) html.Redirect(w, r, route.Path(h.router, "integrations")) return } @@ -85,6 +85,6 @@ func (h *handler) updateIntegration(w http.ResponseWriter, r *http.Request) { return } - sess.NewFlashMessage(printer.Printf("alert.prefs_saved")) + sess.NewFlashMessage(printer.Print("alert.prefs_saved")) html.Redirect(w, r, route.Path(h.router, "integrations")) } diff --git a/internal/ui/oauth2_callback.go b/internal/ui/oauth2_callback.go index cf223da8..09c03b80 100644 --- a/internal/ui/oauth2_callback.go +++ b/internal/ui/oauth2_callback.go @@ -81,7 +81,7 @@ func (h *handler) oauth2Callback(w http.ResponseWriter, r *http.Request) { slog.String("oauth2_provider", provider), slog.String("oauth2_profile_id", profile.ID), ) - sess.NewFlashErrorMessage(printer.Printf("error.duplicate_linked_account")) + sess.NewFlashErrorMessage(printer.Print("error.duplicate_linked_account")) html.Redirect(w, r, route.Path(h.router, "settings")) return } @@ -92,7 +92,7 @@ func (h *handler) oauth2Callback(w http.ResponseWriter, r *http.Request) { return } - sess.NewFlashMessage(printer.Printf("alert.account_linked")) + sess.NewFlashMessage(printer.Print("alert.account_linked")) html.Redirect(w, r, route.Path(h.router, "settings")) return } @@ -110,7 +110,7 @@ func (h *handler) oauth2Callback(w http.ResponseWriter, r *http.Request) { } if h.store.UserExists(profile.Username) { - html.BadRequest(w, r, errors.New(printer.Printf("error.user_already_exists"))) + html.BadRequest(w, r, errors.New(printer.Print("error.user_already_exists"))) return } diff --git a/internal/ui/oauth2_unlink.go b/internal/ui/oauth2_unlink.go index 8a698a3e..83b1fcfa 100644 --- a/internal/ui/oauth2_unlink.go +++ b/internal/ui/oauth2_unlink.go @@ -47,7 +47,7 @@ func (h *handler) oauth2Unlink(w http.ResponseWriter, r *http.Request) { } if !hasPassword { - sess.NewFlashErrorMessage(printer.Printf("error.unlink_account_without_password")) + sess.NewFlashErrorMessage(printer.Print("error.unlink_account_without_password")) html.Redirect(w, r, route.Path(h.router, "settings")) return } @@ -58,6 +58,6 @@ func (h *handler) oauth2Unlink(w http.ResponseWriter, r *http.Request) { return } - sess.NewFlashMessage(printer.Printf("alert.account_unlinked")) + sess.NewFlashMessage(printer.Print("alert.account_unlinked")) html.Redirect(w, r, route.Path(h.router, "settings")) }