mirror of
https://github.com/ddnet/ddnet.git
synced 2024-11-10 01:58:19 +00:00
Merge pull request #7936 from Robyt3/Browser-Community-Tab-Max-Num-Fix
Fix and simplify check for maximum number of favorite communities
This commit is contained in:
commit
48a449d2f5
|
@ -1701,13 +1701,14 @@ void CFavoriteCommunityFilterList::Add(const char *pCommunityId)
|
|||
// the end of the list, to allow setting the entire list easier with binds.
|
||||
Remove(pCommunityId);
|
||||
|
||||
// Ensure maximum number of favorite communities, by removing least-recently
|
||||
// added communities from the beginning. One more than the maximum is removed
|
||||
// to make room for the new community.
|
||||
// Ensure maximum number of favorite communities, by removing the least-recently
|
||||
// added community from the beginning, when the maximum number of favorite
|
||||
// communities has been reached.
|
||||
constexpr size_t MaxFavoriteCommunities = 3;
|
||||
if(m_vEntries.size() >= MaxFavoriteCommunities)
|
||||
{
|
||||
m_vEntries.erase(m_vEntries.begin(), m_vEntries.begin() + (MaxFavoriteCommunities - 1));
|
||||
dbg_assert(m_vEntries.size() == MaxFavoriteCommunities, "Maximum number of communities can never be exceeded");
|
||||
m_vEntries.erase(m_vEntries.begin());
|
||||
}
|
||||
m_vEntries.emplace_back(pCommunityId);
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue