From 6882722b6528e911af5fdefcfeee2d552c312b13 Mon Sep 17 00:00:00 2001 From: "Dustin J. Mitchell" Date: Sun, 24 Nov 2024 16:44:34 -0500 Subject: [PATCH] Only nag to read news when there's news to read --- src/commands/CmdCustom.cpp | 7 +++---- src/commands/CmdNews.cpp | 25 +++++++++++++++++++++++++ src/commands/CmdNews.h | 2 ++ 3 files changed, 30 insertions(+), 4 deletions(-) diff --git a/src/commands/CmdCustom.cpp b/src/commands/CmdCustom.cpp index 5cf528662..911ac719d 100644 --- a/src/commands/CmdCustom.cpp +++ b/src/commands/CmdCustom.cpp @@ -28,6 +28,7 @@ // cmake.h include header must come first #include +#include #include #include #include @@ -222,11 +223,9 @@ int CmdCustom::execute(std::string& output) { } // Inform user about the new release highlights if not presented yet - Version news_version(Context::getContext().config.get("news.version")); - Version current_version = Version::Current(); - auto should_nag = news_version != current_version && Context::getContext().verbose("news"); - if (should_nag) { + if (CmdNews::should_nag()) { std::ostringstream notice; + Version current_version = Version::Current(); notice << "Recently upgraded to " << current_version << ". " "Please run 'task news' to read highlights about the new release."; diff --git a/src/commands/CmdNews.cpp b/src/commands/CmdNews.cpp index f88da6812..8ef979882 100644 --- a/src/commands/CmdNews.cpp +++ b/src/commands/CmdNews.cpp @@ -615,3 +615,28 @@ int CmdNews::execute(std::string& output) { return 0; } + +bool CmdNews::should_nag() { + if (!Context::getContext().verbose("news")) { + return false; + } + + Version news_version(Context::getContext().config.get("news.version")); + if (!news_version.is_valid()) news_version = Version("2.6.0"); + + Version current_version = Version::Current(); + + if (news_version == current_version) { + return true; + } + + // Check if there are actually any interesting news items to show. + std::vector items = NewsItem::all(); + for (auto& item : items) { + if (item._version > news_version) { + return true; + } + } + + return false; +} diff --git a/src/commands/CmdNews.h b/src/commands/CmdNews.h index 554f12bdd..78055356f 100644 --- a/src/commands/CmdNews.h +++ b/src/commands/CmdNews.h @@ -63,6 +63,8 @@ class CmdNews : public Command { public: CmdNews(); int execute(std::string&); + + static bool should_nag(); }; #endif