Cleanup subscription spam
This commit is contained in:
parent
989cbe991e
commit
e61d25664b
@ -3,12 +3,6 @@ import { System } from "..";
|
|||||||
import { Subscriptions } from "../nostr/Subscriptions";
|
import { Subscriptions } from "../nostr/Subscriptions";
|
||||||
|
|
||||||
function notesReducer(state, ev) {
|
function notesReducer(state, ev) {
|
||||||
if (ev.reset === true) {
|
|
||||||
return {
|
|
||||||
notes: []
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
if (state.notes.some(a => a.id === ev.id)) {
|
if (state.notes.some(a => a.id === ev.id)) {
|
||||||
return state;
|
return state;
|
||||||
}
|
}
|
||||||
@ -37,7 +31,6 @@ export default function useSubscription(sub, opt) {
|
|||||||
|
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
if (sub) {
|
if (sub) {
|
||||||
dispatch({ reset: true });
|
|
||||||
sub.OnEvent = (e) => {
|
sub.OnEvent = (e) => {
|
||||||
dispatch(e);
|
dispatch(e);
|
||||||
};
|
};
|
||||||
|
@ -4,6 +4,7 @@ import { Subscriptions } from "../nostr/Subscriptions";
|
|||||||
import useSubscription from "./Subscription";
|
import useSubscription from "./Subscription";
|
||||||
|
|
||||||
export default function useTimelineFeed(pubKeys, global = false) {
|
export default function useTimelineFeed(pubKeys, global = false) {
|
||||||
|
const subTab = global ? "global" : "follows";
|
||||||
const sub = useMemo(() => {
|
const sub = useMemo(() => {
|
||||||
if (!Array.isArray(pubKeys)) {
|
if (!Array.isArray(pubKeys)) {
|
||||||
pubKeys = [pubKeys];
|
pubKeys = [pubKeys];
|
||||||
@ -14,7 +15,7 @@ export default function useTimelineFeed(pubKeys, global = false) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
let sub = new Subscriptions();
|
let sub = new Subscriptions();
|
||||||
sub.Id = `timeline:${sub.Id}`;
|
sub.Id = `timeline:${subTab}`;
|
||||||
sub.Authors = new Set(global ? [] : pubKeys);
|
sub.Authors = new Set(global ? [] : pubKeys);
|
||||||
sub.Kinds.add(EventKind.TextNote);
|
sub.Kinds.add(EventKind.TextNote);
|
||||||
sub.Limit = 20;
|
sub.Limit = 20;
|
||||||
@ -25,11 +26,10 @@ export default function useTimelineFeed(pubKeys, global = false) {
|
|||||||
const main = useSubscription(sub, { leaveOpen: true });
|
const main = useSubscription(sub, { leaveOpen: true });
|
||||||
|
|
||||||
const subNext = useMemo(() => {
|
const subNext = useMemo(() => {
|
||||||
return null; // spamming subscriptions
|
return null; // TODO: spam
|
||||||
|
|
||||||
if (main.notes.length > 0) {
|
if (main.notes.length > 0) {
|
||||||
let sub = new Subscriptions();
|
let sub = new Subscriptions();
|
||||||
sub.Id = `timeline-related:${sub.Id}`;
|
sub.Id = `timeline-related:${subTab}`;
|
||||||
sub.Kinds.add(EventKind.Reaction);
|
sub.Kinds.add(EventKind.Reaction);
|
||||||
sub.Kinds.add(EventKind.Deletion);
|
sub.Kinds.add(EventKind.Deletion);
|
||||||
sub.ETags = new Set(main.notes.map(a => a.id));
|
sub.ETags = new Set(main.notes.map(a => a.id));
|
||||||
|
@ -92,7 +92,19 @@ const LoginSlice = createSlice({
|
|||||||
state.relays = Object.fromEntries(filtered);
|
state.relays = Object.fromEntries(filtered);
|
||||||
},
|
},
|
||||||
setFollows: (state, action) => {
|
setFollows: (state, action) => {
|
||||||
state.follows = action.payload;
|
let existing = new Set(state.follows);
|
||||||
|
let update = Array.isArray(action.payload) ? action.payload : [action.payload];
|
||||||
|
|
||||||
|
let changes = false;
|
||||||
|
for (let pk of update) {
|
||||||
|
if (!existing.has(pk)) {
|
||||||
|
existing.add(pk);
|
||||||
|
changes = true;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if (changes) {
|
||||||
|
state.follows = Array.from(existing);
|
||||||
|
}
|
||||||
},
|
},
|
||||||
addNotifications: (state, action) => {
|
addNotifications: (state, action) => {
|
||||||
let n = action.payload;
|
let n = action.payload;
|
||||||
@ -100,14 +112,18 @@ const LoginSlice = createSlice({
|
|||||||
n = [n];
|
n = [n];
|
||||||
}
|
}
|
||||||
|
|
||||||
|
let didChange = false;
|
||||||
for (let x of n) {
|
for (let x of n) {
|
||||||
if (!state.notifications.some(a => a.id === x.id)) {
|
if (!state.notifications.some(a => a.id === x.id)) {
|
||||||
state.notifications.push(x);
|
state.notifications.push(x);
|
||||||
|
didChange = true;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
state.notifications = [
|
if (didChange) {
|
||||||
...state.notifications
|
state.notifications = [
|
||||||
];
|
...state.notifications
|
||||||
|
];
|
||||||
|
}
|
||||||
},
|
},
|
||||||
logout: (state) => {
|
logout: (state) => {
|
||||||
window.localStorage.removeItem(PrivateKeyItem);
|
window.localStorage.removeItem(PrivateKeyItem);
|
||||||
|
Loading…
Reference in New Issue
Block a user