diff --git a/loader/src/ui/mods/sources/ModListSource.hpp b/loader/src/ui/mods/sources/ModListSource.hpp index dccb058e..49f2c849 100644 --- a/loader/src/ui/mods/sources/ModListSource.hpp +++ b/loader/src/ui/mods/sources/ModListSource.hpp @@ -166,6 +166,7 @@ public: server::ModsQuery const& getQuery() const; InvalidateQueryAfter getQueryMut(); bool isDefaultQuery() const override; + server::ModsQuery createDefaultQuery() const; ServerModListType getType() const; }; diff --git a/loader/src/ui/mods/sources/ServerModListSource.cpp b/loader/src/ui/mods/sources/ServerModListSource.cpp index 04991d7a..cc43e495 100644 --- a/loader/src/ui/mods/sources/ServerModListSource.cpp +++ b/loader/src/ui/mods/sources/ServerModListSource.cpp @@ -1,35 +1,7 @@ #include "ModListSource.hpp" void ServerModListSource::resetQuery() { - switch (m_type) { - case ServerModListType::Download: { - m_query = server::ModsQuery {}; - } break; - - case ServerModListType::Featured: { - m_query = server::ModsQuery { - .featured = true, - }; - } break; - - case ServerModListType::Trending: { - m_query = server::ModsQuery { - .sorting = server::ModsSort::RecentlyUpdated, - }; - } break; - - case ServerModListType::Recent: { - m_query = server::ModsQuery { - .sorting = server::ModsSort::RecentlyPublished, - }; - } break; - - case ServerModListType::Modtober24: { - m_query = server::ModsQuery { - .tags = { "modtober24" }, - }; - } break; - } + m_query = this->createDefaultQuery(); } ServerModListSource::ProviderTask ServerModListSource::fetchPage(size_t page, size_t pageSize, bool forceUpdate) { @@ -62,7 +34,7 @@ ServerModListSource::ServerModListSource(ServerModListType type) ServerModListSource* ServerModListSource::get(ServerModListType type) { switch (type) { - default: + default: [[fallthrough]]; case ServerModListType::Download: { static auto inst = new ServerModListSource(ServerModListType::Download); return inst; @@ -115,9 +87,29 @@ InvalidateQueryAfter ServerModListSource::getQueryMut() { return InvalidateQueryAfter(m_query, this); } bool ServerModListSource::isDefaultQuery() const { - return !m_query.query.has_value() && - m_query.tags.empty() && - !m_query.developer.has_value(); + return m_query == this->createDefaultQuery(); +} + +server::ModsQuery ServerModListSource::createDefaultQuery() const { + switch (m_type) { + case ServerModListType::Download: return server::ModsQuery {}; + + case ServerModListType::Featured: return server::ModsQuery { + .featured = true, + }; + + case ServerModListType::Trending: return server::ModsQuery { + .sorting = server::ModsSort::RecentlyUpdated, + }; + + case ServerModListType::Recent: return server::ModsQuery { + .sorting = server::ModsSort::RecentlyPublished, + }; + + case ServerModListType::Modtober24: return server::ModsQuery { + .tags = { "modtober24" }, + }; + } } ServerModListType ServerModListSource::getType() const {