Fix wrong filtered counts due to grouped boosts

This commit is contained in:
Lim Chee Aun 2024-03-20 09:44:27 +08:00
parent 552ad249e5
commit da909e4084

View file

@ -431,7 +431,7 @@ function Catchup() {
// Deduplicate boosts // Deduplicate boosts
const boostedPosts = {}; const boostedPosts = {};
filteredPosts = filteredPosts.filter((post) => { filteredPosts.forEach((post) => {
if (post.reblog) { if (post.reblog) {
if (boostedPosts[post.reblog.id]) { if (boostedPosts[post.reblog.id]) {
if (boostedPosts[post.reblog.id].__BOOSTERS) { if (boostedPosts[post.reblog.id].__BOOSTERS) {
@ -439,12 +439,11 @@ function Catchup() {
} else { } else {
boostedPosts[post.reblog.id].__BOOSTERS = new Set([post.account]); boostedPosts[post.reblog.id].__BOOSTERS = new Set([post.account]);
} }
return false; post.__HIDDEN = true;
} else { } else {
boostedPosts[post.reblog.id] = post; boostedPosts[post.reblog.id] = post;
} }
} }
return true;
}); });
if (selectedAuthor && authorCountsMap.has(selectedAuthor)) { if (selectedAuthor && authorCountsMap.has(selectedAuthor)) {
@ -479,39 +478,41 @@ function Catchup() {
authorCountsList.forEach((authorID, index) => { authorCountsList.forEach((authorID, index) => {
authorIndices[authorID] = index; authorIndices[authorID] = index;
}); });
return filteredPosts.sort((a, b) => { return filteredPosts
if (groupBy === 'account') { .filter((post) => !post.__HIDDEN)
const aAccountID = a.account.id; .sort((a, b) => {
const bAccountID = b.account.id; if (groupBy === 'account') {
const aIndex = authorIndices[aAccountID]; const aAccountID = a.account.id;
const bIndex = authorIndices[bAccountID]; const bAccountID = b.account.id;
const order = aIndex - bIndex; const aIndex = authorIndices[aAccountID];
if (order !== 0) { const bIndex = authorIndices[bAccountID];
return order; const order = aIndex - bIndex;
if (order !== 0) {
return order;
}
} }
} if (sortBy !== 'createdAt') {
if (sortBy !== 'createdAt') { a = a.reblog || a;
a = a.reblog || a; b = b.reblog || b;
b = b.reblog || b; if (sortBy !== 'density' && a[sortBy] === b[sortBy]) {
if (sortBy !== 'density' && a[sortBy] === b[sortBy]) { return a.createdAt > b.createdAt ? 1 : -1;
return a.createdAt > b.createdAt ? 1 : -1; }
}
if (sortBy === 'density') {
const aDensity = postDensity(a);
const bDensity = postDensity(b);
if (sortOrder === 'asc') {
return aDensity > bDensity ? 1 : -1;
} else {
return bDensity > aDensity ? 1 : -1;
}
} }
}
if (sortBy === 'density') {
const aDensity = postDensity(a);
const bDensity = postDensity(b);
if (sortOrder === 'asc') { if (sortOrder === 'asc') {
return aDensity > bDensity ? 1 : -1; return a[sortBy] > b[sortBy] ? 1 : -1;
} else { } else {
return bDensity > aDensity ? 1 : -1; return b[sortBy] > a[sortBy] ? 1 : -1;
} }
} });
if (sortOrder === 'asc') {
return a[sortBy] > b[sortBy] ? 1 : -1;
} else {
return b[sortBy] > a[sortBy] ? 1 : -1;
}
});
}, [filteredPosts, sortBy, sortOrder, groupBy, authorCountsList]); }, [filteredPosts, sortBy, sortOrder, groupBy, authorCountsList]);
const prevGroup = useRef(null); const prevGroup = useRef(null);