From 3ea786f3e8a0f587cd47ec865a37be95d68b303a Mon Sep 17 00:00:00 2001 From: "shakespeare.diy" Date: Tue, 17 Feb 2026 02:51:03 -0600 Subject: [PATCH] Default to follows tab when logged in, filter out future-dated posts - Feed.tsx: initialize activeTab to 'follows' when user is logged in, 'global' otherwise - useFeed.ts: filter out events with created_at > now in both follows and global feeds, including embedded repost content and fetched originals Co-authored-by: shakespeare.diy --- src/components/Feed.tsx | 2 +- src/hooks/useFeed.ts | 9 +++++++-- 2 files changed, 8 insertions(+), 3 deletions(-) diff --git a/src/components/Feed.tsx b/src/components/Feed.tsx index cad13ecc..c9c3329a 100644 --- a/src/components/Feed.tsx +++ b/src/components/Feed.tsx @@ -12,7 +12,7 @@ import type { FeedItem } from '@/hooks/useFeed'; export function Feed() { const { user } = useCurrentUser(); - const [activeTab, setActiveTab] = useState<'follows' | 'global'>('global'); + const [activeTab, setActiveTab] = useState<'follows' | 'global'>(user ? 'follows' : 'global'); const [loginDialogOpen, setLoginDialogOpen] = useState(false); const [signupDialogOpen, setSignupDialogOpen] = useState(false); const { data: feedItems, isLoading } = useFeed(activeTab); diff --git a/src/hooks/useFeed.ts b/src/hooks/useFeed.ts index 193d969a..b6641aea 100644 --- a/src/hooks/useFeed.ts +++ b/src/hooks/useFeed.ts @@ -63,6 +63,7 @@ export function useFeed(tab: 'follows' | 'global') { queryKey: ['feed', tab, user?.pubkey ?? '', followList?.length ?? 0], queryFn: async ({ signal }) => { const querySignal = AbortSignal.any([signal, AbortSignal.timeout(8000)]); + const now = Math.floor(Date.now() / 1000); if (tab === 'follows' && user && followList && followList.length > 0) { // Follows feed — posts and reposts from people you follow @@ -77,12 +78,15 @@ export function useFeed(tab: 'follows' | 'global') { const repostMap = new Map(); // eventId -> repost event for (const ev of events) { + // Skip future-dated events + if (ev.created_at > now) continue; + if (ev.kind === 1) { items.push({ event: ev, sortTimestamp: ev.created_at }); } else if (ev.kind === 6) { // Try to get the reposted event from the content first const embedded = parseRepostContent(ev); - if (embedded && embedded.kind === 1) { + if (embedded && embedded.kind === 1 && embedded.created_at <= now) { items.push({ event: embedded, repostedBy: ev.pubkey, sortTimestamp: ev.created_at }); } else { // Need to fetch the original event @@ -104,7 +108,7 @@ export function useFeed(tab: 'follows' | 'global') { ); for (const original of originals) { const repost = repostMap.get(original.id); - if (repost && original.kind === 1) { + if (repost && original.kind === 1 && original.created_at <= now) { items.push({ event: original, repostedBy: repost.pubkey, sortTimestamp: repost.created_at }); } } @@ -133,6 +137,7 @@ export function useFeed(tab: 'follows' | 'global') { { signal: querySignal }, ); return events + .filter((ev) => ev.created_at <= now) .sort((a, b) => b.created_at - a.created_at) .map((ev) => ({ event: ev, sortTimestamp: ev.created_at })); }