Move "FP included" logic to SearchSavesRequest

This commit is contained in:
Tamás Bálint Misius
2025-08-14 23:02:34 +02:00
parent 66b40b6442
commit ac0e075eef
4 changed files with 24 additions and 18 deletions

View File

@@ -83,6 +83,7 @@ namespace http
SearchSavesRequest::SearchSavesRequest(int start, int count, ByteString query, Period period, Sort sort, Category category) : APIRequest(Url(start, count, query, period, sort, category), authUse, false) SearchSavesRequest::SearchSavesRequest(int start, int count, ByteString query, Period period, Sort sort, Category category) : APIRequest(Url(start, count, query, period, sort, category), authUse, false)
{ {
includesFp = category == categoryNone && period == http::allSaves && sort == http::sortByVotes && query == "";
} }
std::pair<int, std::vector<std::unique_ptr<SaveInfo>>> SearchSavesRequest::Finish() std::pair<int, std::vector<std::unique_ptr<SaveInfo>>> SearchSavesRequest::Finish()

View File

@@ -7,9 +7,16 @@ namespace http
{ {
class SearchSavesRequest : public APIRequest class SearchSavesRequest : public APIRequest
{ {
bool includesFp;
public: public:
SearchSavesRequest(int start, int count, ByteString query, Period period, Sort sort, Category category); SearchSavesRequest(int start, int count, ByteString query, Period period, Sort sort, Category category);
bool GetIncludesFp() const
{
return includesFp;
}
std::pair<int, std::vector<std::unique_ptr<SaveInfo>>> Finish(); std::pair<int, std::vector<std::unique_ptr<SaveInfo>>> Finish();
}; };
} }

View File

@@ -15,6 +15,7 @@ SearchModel::SearchModel():
currentSort(http::sortByVotes), currentSort(http::sortByVotes),
currentPage(1), currentPage(1),
resultCount(0), resultCount(0),
includesFp(false),
showOwn(false), showOwn(false),
showFavourite(false), showFavourite(false),
showTags(true) showTags(true)
@@ -37,6 +38,7 @@ void SearchModel::BeginSearchSaves(int start, int count, String query, http::Per
resultCount = 0; resultCount = 0;
searchSaves = std::make_unique<http::SearchSavesRequest>(start, count, query.ToUtf8(), period, sort, category); searchSaves = std::make_unique<http::SearchSavesRequest>(start, count, query.ToUtf8(), period, sort, category);
searchSaves->Start(); searchSaves->Start();
includesFp = searchSaves->GetIncludesFp();
} }
std::vector<std::unique_ptr<SaveInfo>> SearchModel::EndSearchSaves() std::vector<std::unique_ptr<SaveInfo>> SearchModel::EndSearchSaves()
@@ -96,10 +98,18 @@ bool SearchModel::UpdateSaveList(int pageNumber, String query)
//resultCount = 0; //resultCount = 0;
currentPage = pageNumber; currentPage = pageNumber;
if(pageNumber == 1 && !showOwn && !showFavourite && currentPeriod == http::allSaves && currentSort == http::sortByVotes && query == "") auto category = http::categoryNone;
SetShowTags(true); if (showFavourite)
else {
SetShowTags(false); category = http::categoryFavourites;
}
if (showOwn && Client::Ref().GetAuthUser().UserID)
{
category = http::categoryMyOwn;
}
BeginSearchSaves((currentPage-1)*20, 20, lastQuery, currentPeriod, currentSort, category);
SetShowTags(includesFp && pageNumber == 1);
notifySaveListChanged(); notifySaveListChanged();
notifyTagListChanged(); notifyTagListChanged();
@@ -112,16 +122,6 @@ bool SearchModel::UpdateSaveList(int pageNumber, String query)
BeginGetTags(0, 24, ""); BeginGetTags(0, 24, "");
} }
auto category = http::categoryNone;
if (showFavourite)
{
category = http::categoryFavourites;
}
if (showOwn && Client::Ref().GetAuthUser().UserID)
{
category = http::categoryMyOwn;
}
BeginSearchSaves((currentPage-1)*20, 20, lastQuery, currentPeriod, currentSort, category);
return true; return true;
} }
return false; return false;
@@ -307,8 +307,5 @@ void SearchModel::notifySelectedChanged()
int SearchModel::GetPageCount() int SearchModel::GetPageCount()
{ {
if (!showOwn && !showFavourite && currentPeriod == http::allSaves && currentSort == http::sortByVotes && lastQuery == "") return std::max(1, (int)(ceil(resultCount/20.0f)) + (includesFp ? 1 : 0)); //add one for front page (front page saves are repeated twice)
return std::max(1, (int)(ceil(resultCount/20.0f))+1); //add one for front page (front page saves are repeated twice)
else
return std::max(1, (int)(ceil(resultCount/20.0f)));
} }

View File

@@ -36,6 +36,7 @@ private:
std::vector<std::pair<ByteString, int> > tagList; std::vector<std::pair<ByteString, int> > tagList;
int currentPage; int currentPage;
int resultCount; int resultCount;
bool includesFp;
bool showOwn; bool showOwn;
bool showFavourite; bool showFavourite;
bool showTags; bool showTags;