Fix boost dedupe bug, it was too powerful

This commit is contained in:
Lim Chee Aun 2023-04-09 11:36:18 +08:00
parent efb9864d73
commit f9217ac16f

View file

@ -1,4 +1,4 @@
import { getStatus } from './states'; import store from './store';
export function groupBoosts(values) { export function groupBoosts(values) {
let newValues = []; let newValues = [];
@ -50,24 +50,32 @@ export function groupBoosts(values) {
} }
export function dedupeBoosts(items, instance) { export function dedupeBoosts(items, instance) {
return items.filter((item) => { const boostedStatusIDs = store.account.get('boostedStatusIDs') || {};
const filteredItems = items.filter((item) => {
if (!item.reblog) return true; if (!item.reblog) return true;
const s = getStatus(item.reblog.id, instance); const statusKey = `${instance}-${item.reblog.id}`;
if (s) { const boosterID = boostedStatusIDs[statusKey];
if (boosterID && boosterID !== item.id) {
console.warn( console.warn(
`🚫 Duplicate boost by ${item.account.displayName}`, `🚫 Duplicate boost by ${item.account.displayName}`,
item, item,
s, item.reblog,
); );
return false; return false;
} } else {
const s2 = getStatus(item.id, instance); boostedStatusIDs[statusKey] = item.id;
if (s2) {
console.warn('🚫 Re-boosted boost', item);
return false;
} }
return true; return true;
}); });
// Limit to 50
const keys = Object.keys(boostedStatusIDs);
if (keys.length > 50) {
keys.slice(0, keys.length - 50).forEach((key) => {
delete boostedStatusIDs[key];
});
}
store.account.set('boostedStatusIDs', boostedStatusIDs);
return filteredItems;
} }
export function groupContext(items) { export function groupContext(items) {